viric@0: #include viric@5: #include viric@0: viric@0: #include "dictre.h" viric@0: viric@0: extern int nwords; viric@0: extern int ndefs; viric@0: viric@0: int main(int argn, char **argv) viric@0: { viric@0: char tmpname[500]; viric@0: FILE *i, *d; viric@5: int remove_tmp_data = 0; viric@0: viric@5: if (argn < 3) viric@0: { viric@0: fprintf(stderr, "usage: %s " viric@5: " [filter]\n", viric@0: argv[0]); viric@0: return 1; viric@0: } viric@0: strcpy(tmpname, argv[1]); viric@0: strcat(tmpname, ".index"); viric@0: i = fopen(tmpname, "r"); viric@0: if(i == NULL) viric@0: { viric@0: fprintf(stderr, "File: %s ", tmpname); viric@0: perror("- cannot open file."); viric@0: exit(-1); viric@0: } viric@0: viric@0: strcpy(tmpname, argv[1]); viric@0: strcat(tmpname, ".dict"); viric@0: d = fopen(tmpname, "r"); viric@0: if(d == NULL) viric@0: { viric@5: struct stat st; viric@5: int res; viric@5: char tmp[500]; viric@5: strcat(tmpname, ".dz"); viric@5: res = stat(tmpname, &st); viric@5: if (res == -1) viric@5: { viric@5: fprintf(stderr, "File: %s ", tmpname); viric@5: perror("- cannot open file."); viric@5: exit(-1); viric@5: } viric@5: sprintf(tmp, "gzip -cd %s > /tmp/tmp.dict", viric@5: tmpname); viric@5: printf("Gunzipping...\n"); viric@5: res = system(tmp); viric@5: d = fopen("/tmp/tmp.dict", "r"); viric@5: if(d == NULL || res != 0) viric@5: { viric@5: fprintf(stderr, "Error gunzipping file: %s ", tmpname); viric@5: perror("- something happened to /tmp/tmp.dict."); viric@5: exit(-1); viric@5: } viric@5: remove_tmp_data = 1; viric@0: } viric@0: viric@5: init_load(); viric@5: init_repeated(); viric@5: /* Always line buffered on stdout, for 'ts' */ viric@5: setlinebuf(stdout); viric@0: viric@0: load_dictionary(i, d); viric@0: viric@0: fclose(i); viric@0: fclose(d); viric@0: viric@5: if (remove_tmp_data) viric@5: unlink("/tmp/tmp.dict"); viric@5: viric@0: sort_words(); viric@0: viric@0: if (0) viric@0: print_words(); viric@0: viric@5: if (argn >= 4) viric@5: filter_all(argv[3]); viric@0: viric@0: write_dictionary(argv[2]); viric@0: viric@0: return 0; viric@0: }