diff -r b2dfe3374454 -r c87681fff7d3 main.c --- a/main.c Sat Aug 11 16:12:27 2007 +0200 +++ b/main.c Mon Aug 13 16:27:41 2007 +0200 @@ -1,4 +1,5 @@ #include +#include #include "dictre.h" @@ -9,11 +10,12 @@ { char tmpname[500]; FILE *i, *d; + int remove_tmp_data = 0; - if (argn < 4) + if (argn < 3) { fprintf(stderr, "usage: %s " - " \n", + " [filter]\n", argv[0]); return 1; } @@ -32,24 +34,51 @@ d = fopen(tmpname, "r"); if(d == NULL) { - fprintf(stderr, "File: %s ", tmpname); - perror("- cannot open file."); - exit(-1); + struct stat st; + int res; + char tmp[500]; + strcat(tmpname, ".dz"); + res = stat(tmpname, &st); + if (res == -1) + { + fprintf(stderr, "File: %s ", tmpname); + perror("- cannot open file."); + exit(-1); + } + sprintf(tmp, "gzip -cd %s > /tmp/tmp.dict", + tmpname); + printf("Gunzipping...\n"); + res = system(tmp); + d = fopen("/tmp/tmp.dict", "r"); + if(d == NULL || res != 0) + { + fprintf(stderr, "Error gunzipping file: %s ", tmpname); + perror("- something happened to /tmp/tmp.dict."); + exit(-1); + } + remove_tmp_data = 1; } - load_init(); + init_load(); + init_repeated(); + /* Always line buffered on stdout, for 'ts' */ + setlinebuf(stdout); load_dictionary(i, d); fclose(i); fclose(d); + if (remove_tmp_data) + unlink("/tmp/tmp.dict"); + sort_words(); if (0) print_words(); - filter_all(argv[3]); + if (argn >= 4) + filter_all(argv[3]); write_dictionary(argv[2]);