67 |
67 |
68 void load_dictionary(FILE *index, FILE *fdefs) |
68 void load_dictionary(FILE *index, FILE *fdefs) |
69 { |
69 { |
70 struct Word w; |
70 struct Word w; |
71 int last_offset = 0; |
71 int last_offset = 0; |
|
72 int def_avoided = 0; |
72 |
73 |
73 do { |
74 do { |
74 int offset, length; |
75 int offset, length; |
75 char *defstr; |
76 char *defstr; |
76 w.w = get_word(index); |
77 w.w = get_word(index); |
77 if (w.w == 0) |
78 if (w.w == 0) |
78 break; |
79 break; |
|
80 /*printf("Word: %s\n", w.w);*/ |
79 offset = get_int(index); |
81 offset = get_int(index); |
80 length = get_int(index); |
82 length = get_int(index); |
81 if (offset > last_offset) |
83 if (offset > last_offset) |
82 { |
84 { |
83 w.def = -1; |
85 w.def = -1; |
84 last_offset = offset; |
86 last_offset = offset; |
85 } |
87 } |
86 else |
88 else |
87 w.def = search_def(offset, length); |
89 w.def = search_def(offset, length); |
88 if (w.def == -1) |
90 if (w.def == -1) |
89 { |
91 { |
|
92 /* New definition */ |
|
93 int newindex, repindex; |
90 defstr = get_def(fdefs, offset, length); |
94 defstr = get_def(fdefs, offset, length); |
91 w.def = new_def(defstr, offset, length); |
95 newindex = new_def(defstr, offset, length); |
|
96 |
|
97 /* Store it in the hash for repeated defs */ |
|
98 repindex = def_repeated(&defs[newindex]); |
|
99 if (repindex != -1) |
|
100 { |
|
101 def_avoided += 1; |
|
102 printf("Repeated def avoided %i (word %s)\n", def_avoided, w.w); |
|
103 remove_def(newindex); |
|
104 newindex = repindex; |
|
105 } else |
|
106 new_hashdef(&defs[newindex], newindex); |
|
107 |
|
108 /* Store the final index */ |
|
109 w.def = newindex; |
92 } |
110 } |
93 /* sizeof -1 instead of strlen() */ |
111 /* sizeof -1 instead of strlen() */ |
94 if (strncmp(w.w, "00database", sizeof("00database") - 1) == 0) |
112 if (strncmp(w.w, "00database", sizeof("00database") - 1) == 0) |
95 new_dont_touch(w.def); |
113 new_dont_touch(w.def); |
96 new_word(&w); |
114 new_word(&w); |