0
|
1 |
#include <stdio.h>
|
5
|
2 |
#include <sys/stat.h>
|
0
|
3 |
|
|
4 |
#include "dictre.h"
|
|
5 |
|
|
6 |
extern int nwords;
|
|
7 |
extern int ndefs;
|
|
8 |
|
|
9 |
int main(int argn, char **argv)
|
|
10 |
{
|
|
11 |
char tmpname[500];
|
|
12 |
FILE *i, *d;
|
5
|
13 |
int remove_tmp_data = 0;
|
0
|
14 |
|
5
|
15 |
if (argn < 3)
|
0
|
16 |
{
|
|
17 |
fprintf(stderr, "usage: %s <dict_basename> "
|
5
|
18 |
"<dict_basename_out> [filter]\n",
|
0
|
19 |
argv[0]);
|
|
20 |
return 1;
|
|
21 |
}
|
|
22 |
strcpy(tmpname, argv[1]);
|
|
23 |
strcat(tmpname, ".index");
|
|
24 |
i = fopen(tmpname, "r");
|
|
25 |
if(i == NULL)
|
|
26 |
{
|
|
27 |
fprintf(stderr, "File: %s ", tmpname);
|
|
28 |
perror("- cannot open file.");
|
|
29 |
exit(-1);
|
|
30 |
}
|
|
31 |
|
|
32 |
strcpy(tmpname, argv[1]);
|
|
33 |
strcat(tmpname, ".dict");
|
|
34 |
d = fopen(tmpname, "r");
|
|
35 |
if(d == NULL)
|
|
36 |
{
|
5
|
37 |
struct stat st;
|
|
38 |
int res;
|
|
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;
|
0
|
60 |
}
|
|
61 |
|
5
|
62 |
init_load();
|
|
63 |
init_repeated();
|
|
64 |
/* Always line buffered on stdout, for 'ts' */
|
|
65 |
setlinebuf(stdout);
|
0
|
66 |
|
|
67 |
load_dictionary(i, d);
|
|
68 |
|
|
69 |
fclose(i);
|
|
70 |
fclose(d);
|
|
71 |
|
5
|
72 |
if (remove_tmp_data)
|
|
73 |
unlink("/tmp/tmp.dict");
|
|
74 |
|
0
|
75 |
sort_words();
|
|
76 |
|
|
77 |
if (0)
|
|
78 |
print_words();
|
|
79 |
|
5
|
80 |
if (argn >= 4)
|
|
81 |
filter_all(argv[3]);
|
0
|
82 |
|
|
83 |
write_dictionary(argv[2]);
|
|
84 |
|
|
85 |
return 0;
|
|
86 |
}
|