viric@0: #include viric@0: #include "dictre.h" viric@0: viric@0: extern struct Word words[]; viric@0: extern int nwords; viric@0: extern struct Def defs[]; viric@0: extern int ndefs; viric@0: viric@0: static int write_dictionary_data(FILE *fdefs) viric@0: { viric@0: int i; viric@0: viric@0: int offset = 0; viric@0: viric@0: for (i=0; i < ndefs; ++i) viric@0: { viric@0: fwrite(defs[i].d, defs[i].length, 1, fdefs); viric@0: defs[i].offset = offset; viric@0: offset += defs[i].length; viric@0: } viric@0: } viric@0: viric@0: static void write_dictionary_index(FILE *index) viric@0: { viric@0: int i; viric@0: viric@0: for (i=0; i < nwords; ++i) viric@0: { viric@0: char offset_str[50]; viric@0: char length_str[50]; viric@0: viric@0: num_to_ia5(offset_str, defs[words[i].def].offset); viric@0: num_to_ia5(length_str, defs[words[i].def].length); viric@0: fprintf(index, "%s\t%s\t%s\n", viric@0: words[i].w, offset_str, length_str); viric@0: } viric@0: } viric@0: viric@0: void write_dictionary(const char *name) viric@0: { viric@0: FILE *i, *d; viric@0: char tmpname[500]; viric@0: viric@0: strcpy(tmpname, name); viric@0: strcat(tmpname, ".dict"); viric@0: d = fopen(tmpname, "wb"); viric@0: write_dictionary_data(d); viric@0: fclose(d); viric@0: viric@0: strcpy(tmpname, name); viric@0: strcat(tmpname, ".index"); viric@0: i = fopen(tmpname, "wb"); viric@0: write_dictionary_index(i); viric@0: fclose(i); viric@0: }