viric@11: #include viric@11: #include viric@11: #include "dictre.h" viric@11: viric@11: static FILE *index, *dict; viric@11: static remove_tmp_file = 0; viric@11: viric@11: static new_word(const char *w, const char *defstr) viric@11: { viric@11: printf("'%s': '%s'\n", w, defstr); viric@11: } viric@11: viric@11: void zload_words(FILE *index, FILE *fdefs) viric@11: { viric@11: int last_offset = 0; viric@11: int def_avoided = 0; viric@11: int numword = 0;; viric@11: static int dispnwords = 0; viric@11: static int nwords = 0; viric@11: viric@11: do { viric@11: int offset, length; viric@11: char *defstr; viric@11: char *word; viric@11: word = get_word(index); viric@11: /*numword++; viric@11: printf("words: %i\n", numword);*/ viric@11: if (word == 0) viric@11: break; viric@11: /*printf("Word: %s\n", w.w);*/ viric@11: offset = get_int(index); viric@11: length = get_int(index); viric@11: defstr = get_def(fdefs, offset, length); viric@11: viric@11: /* sizeof -1 instead of strlen() */ viric@11: /* If the word is not 00database* ... */ viric@11: if (strncmp(word, "00database", sizeof("00database") - 1) != 0) viric@11: zprocess_def(word, defstr); viric@11: viric@11: /* stdout Display */ viric@11: dispnwords++; viric@11: nwords++; viric@11: if (dispnwords >= 1000) viric@11: { viric@11: dispnwords = 0; viric@11: fprintf(stderr, viric@11: "Loaded: %i Repeated definitions avoided: %i\n", nwords, viric@11: def_avoided); viric@11: } viric@11: viric@11: } while(1); viric@11: } viric@11: viric@11: static void close_files() viric@11: { viric@11: fclose(index); viric@11: fclose(dict); viric@11: viric@11: if (remove_tmp_file) viric@11: unlink("/tmp/tmp.dict"); viric@11: } viric@11: viric@11: static void open_files(int argn, char **argv) viric@11: { viric@11: char tmpname[500]; viric@11: if (argn < 2) viric@11: { viric@11: fprintf(stderr, "usage: %s \n", argv[0]); viric@11: exit(1); viric@11: } viric@11: strcpy(tmpname, argv[1]); viric@11: strcat(tmpname, ".index"); viric@11: index = fopen(tmpname, "r"); viric@11: if(index == NULL) viric@11: { viric@11: fprintf(stderr, "File: %s ", tmpname); viric@11: perror("- cannot open file."); viric@11: exit(-1); viric@11: } viric@11: viric@11: strcpy(tmpname, argv[1]); viric@11: strcat(tmpname, ".dict"); viric@11: dict = fopen(tmpname, "r"); viric@11: if(dict == NULL) viric@11: { viric@11: struct stat st; viric@11: int res; viric@11: char tmp[500]; viric@11: strcat(tmpname, ".dz"); viric@11: res = stat(tmpname, &st); viric@11: if (res == -1) viric@11: { viric@11: fprintf(stderr, "File: %s ", tmpname); viric@11: perror("- cannot open file."); viric@11: exit(-1); viric@11: } viric@11: sprintf(tmp, "gzip -cd %s > /tmp/tmp.dict", viric@11: tmpname); viric@11: printf("Gunzipping...\n"); viric@11: res = system(tmp); viric@11: dict = fopen("/tmp/tmp.dict", "r"); viric@11: if(dict == NULL || res != 0) viric@11: { viric@11: fprintf(stderr, "Error gunzipping file: %s ", tmpname); viric@11: perror("- something happened to /tmp/tmp.dict."); viric@11: exit(-1); viric@11: } viric@11: remove_tmp_file = 1; viric@11: } viric@11: } viric@11: viric@11: int main(int argn, char **argv) viric@11: { viric@11: open_files(argn, argv); viric@11: init_wordlist(); viric@11: zload_words(index, dict); viric@11: dump_wordlist(); viric@11: close_files(); viric@11: }