|
1 #include <stdio.h> |
|
2 #include <stdlib.h> |
|
3 #include "dictre.h" |
|
4 |
|
5 #define NELEM(x) (sizeof(x)/sizeof(x[0])) |
|
6 |
|
7 |
|
8 const char *dictionarynames[] = { "bokarjovrueo", "slovnyk_ru-en" }; |
|
9 static struct Dict dictionaries[5/*MAX DICT*/]; |
|
10 static int ndictionaries; |
|
11 |
|
12 static void init_dictionaries() |
|
13 { |
|
14 ndictionaries = 0; |
|
15 |
|
16 init_dictionary(&dictionaries[0], "bokarjovrueo"); |
|
17 dictionaries[0].trim_last_newlines = 1; |
|
18 ndictionaries++; |
|
19 |
|
20 init_dictionary(&dictionaries[1], "slovnyk_ru-en"); |
|
21 dictionaries[1].trim_first_line = 1; |
|
22 dictionaries[1].trim_last_newlines = 1; |
|
23 ndictionaries++; |
|
24 } |
|
25 |
|
26 static void close_dictionaries() |
|
27 { |
|
28 int i; |
|
29 for(i=0; i<ndictionaries; ++i) |
|
30 end_dictionary(&dictionaries[i]); |
|
31 |
|
32 ndictionaries=0; |
|
33 } |
|
34 |
|
35 void dump_word(const char *word) |
|
36 { |
|
37 int i; |
|
38 char def[MAXDEF]; |
|
39 int word_header_dumped = 0; |
|
40 |
|
41 if (strncmp(word, "00database", sizeof("00database"-1)) == 0) |
|
42 return; |
|
43 |
|
44 for (i=0; i < ndictionaries; ++i) |
|
45 { |
|
46 char *found; |
|
47 find_def(&dictionaries[i], word, def); |
|
48 if (def[0]) |
|
49 { |
|
50 if(!word_header_dumped) |
|
51 { |
|
52 printf(":%s:", word); |
|
53 word_header_dumped = 1; |
|
54 } |
|
55 printf("[%s]\n%s\n\n", dictionarynames[i], def); |
|
56 } |
|
57 } |
|
58 } |
|
59 |
|
60 void dump_words() |
|
61 { |
|
62 FILE *fwords; |
|
63 char word[MAXWORD]; |
|
64 |
|
65 fwords = fopen("words.txt", "r"); |
|
66 if (fwords == 0) |
|
67 { |
|
68 printf("Cannot open words.txt\n"); |
|
69 exit(-1); |
|
70 } |
|
71 |
|
72 do |
|
73 { |
|
74 char *res; |
|
75 res = fgets(word, MAXWORD, fwords); |
|
76 if (res == 0) |
|
77 break; |
|
78 word[strlen(word) - 1] = 0; /* Remove \n in the line */ |
|
79 dump_word(word); |
|
80 } while(1); |
|
81 } |
|
82 |
|
83 int main() |
|
84 { |
|
85 init_dictionaries(); |
|
86 |
|
87 dump_words(); |
|
88 |
|
89 close_dictionaries(); |
|
90 |
|
91 return 0; |
|
92 } |