1 #include <stdio.h> |
1 #include <stdio.h> |
|
2 #include <sys/stat.h> |
2 |
3 |
3 #include "dictre.h" |
4 #include "dictre.h" |
4 |
5 |
5 extern int nwords; |
6 extern int nwords; |
6 extern int ndefs; |
7 extern int ndefs; |
7 |
8 |
8 int main(int argn, char **argv) |
9 int main(int argn, char **argv) |
9 { |
10 { |
10 char tmpname[500]; |
11 char tmpname[500]; |
11 FILE *i, *d; |
12 FILE *i, *d; |
|
13 int remove_tmp_data = 0; |
12 |
14 |
13 if (argn < 4) |
15 if (argn < 3) |
14 { |
16 { |
15 fprintf(stderr, "usage: %s <dict_basename> " |
17 fprintf(stderr, "usage: %s <dict_basename> " |
16 "<dict_basename_out> <filter>\n", |
18 "<dict_basename_out> [filter]\n", |
17 argv[0]); |
19 argv[0]); |
18 return 1; |
20 return 1; |
19 } |
21 } |
20 strcpy(tmpname, argv[1]); |
22 strcpy(tmpname, argv[1]); |
21 strcat(tmpname, ".index"); |
23 strcat(tmpname, ".index"); |
30 strcpy(tmpname, argv[1]); |
32 strcpy(tmpname, argv[1]); |
31 strcat(tmpname, ".dict"); |
33 strcat(tmpname, ".dict"); |
32 d = fopen(tmpname, "r"); |
34 d = fopen(tmpname, "r"); |
33 if(d == NULL) |
35 if(d == NULL) |
34 { |
36 { |
35 fprintf(stderr, "File: %s ", tmpname); |
37 struct stat st; |
36 perror("- cannot open file."); |
38 int res; |
37 exit(-1); |
39 char tmp[500]; |
|
40 strcat(tmpname, ".dz"); |
|
41 res = stat(tmpname, &st); |
|
42 if (res == -1) |
|
43 { |
|
44 fprintf(stderr, "File: %s ", tmpname); |
|
45 perror("- cannot open file."); |
|
46 exit(-1); |
|
47 } |
|
48 sprintf(tmp, "gzip -cd %s > /tmp/tmp.dict", |
|
49 tmpname); |
|
50 printf("Gunzipping...\n"); |
|
51 res = system(tmp); |
|
52 d = fopen("/tmp/tmp.dict", "r"); |
|
53 if(d == NULL || res != 0) |
|
54 { |
|
55 fprintf(stderr, "Error gunzipping file: %s ", tmpname); |
|
56 perror("- something happened to /tmp/tmp.dict."); |
|
57 exit(-1); |
|
58 } |
|
59 remove_tmp_data = 1; |
38 } |
60 } |
39 |
61 |
40 load_init(); |
62 init_load(); |
|
63 init_repeated(); |
|
64 /* Always line buffered on stdout, for 'ts' */ |
|
65 setlinebuf(stdout); |
41 |
66 |
42 load_dictionary(i, d); |
67 load_dictionary(i, d); |
43 |
68 |
44 fclose(i); |
69 fclose(i); |
45 fclose(d); |
70 fclose(d); |
46 |
71 |
|
72 if (remove_tmp_data) |
|
73 unlink("/tmp/tmp.dict"); |
|
74 |
47 sort_words(); |
75 sort_words(); |
48 |
76 |
49 if (0) |
77 if (0) |
50 print_words(); |
78 print_words(); |
51 |
79 |
52 filter_all(argv[3]); |
80 if (argn >= 4) |
|
81 filter_all(argv[3]); |
53 |
82 |
54 write_dictionary(argv[2]); |
83 write_dictionary(argv[2]); |
55 |
84 |
56 return 0; |
85 return 0; |
57 } |
86 } |