Lines Matching refs:dict

168 hnj_get_state (HyphenDict *dict, HashTab *hashtab, const char *string)
177 hnj_hash_insert (hashtab, string, dict->num_states);
178 /* predicate is true if dict->num_states is a power of two */
179 if (!(dict->num_states & (dict->num_states - 1)))
181 dict->states = hnj_realloc (dict->states,
182 (dict->num_states << 1) *
185 dict->states[dict->num_states].match = NULL;
186 dict->states[dict->num_states].repl = NULL;
187 dict->states[dict->num_states].fallback_state = -1;
188 dict->states[dict->num_states].num_trans = 0;
189 dict->states[dict->num_states].trans = NULL;
190 return dict->num_states++;
196 hnj_add_trans (HyphenDict *dict, int state1, int state2, char ch)
200 num_trans = dict->states[state1].num_trans;
203 dict->states[state1].trans = hnj_malloc (sizeof(HyphenTrans));
207 dict->states[state1].trans = hnj_realloc (dict->states[state1].trans,
211 dict->states[state1].trans[num_trans].ch = ch;
212 dict->states[state1].trans[num_trans].new_state = state2;
213 dict->states[state1].num_trans++;
272 HyphenDict *dict = hnj_hyphen_load_from_buffer(addr, sb.st_size);
276 return dict;
282 HyphenDict *dict[2];
308 dict[k] = hnj_malloc (sizeof(HyphenDict));
309 dict[k]->num_states = 1;
310 dict[k]->states = hnj_malloc (sizeof(HyphenState));
311 dict[k]->states[0].match = NULL;
312 dict[k]->states[0].repl = NULL;
313 dict[k]->states[0].fallback_state = -1;
314 dict[k]->states[0].num_trans = 0;
315 dict[k]->states[0].trans = NULL;
316 dict[k]->nextlevel = NULL;
317 dict[k]->lhmin = 0;
318 dict[k]->rhmin = 0;
319 dict[k]->clhmin = 0;
320 dict[k]->crhmin = 0;
324 for (i=0;i<MAX_NAME;i++) dict[k]->cset[i]= 0;
325 get_line(dict[k]->cset, sizeof(dict[k]->cset), dict_contents,
328 if ((dict[k]->cset[i] == '\r') || (dict[k]->cset[i] == '\n'))
329 dict[k]->cset[i] = 0;
330 dict[k]->utf8 = (strcmp(dict[k]->cset, "UTF-8") == 0);
332 strcpy(dict[k]->cset, dict[0]->cset);
333 dict[k]->utf8 = dict[0]->utf8;
345 dict[k]->lhmin = atoi(buf + 13);
348 dict[k]->rhmin = atoi(buf + 14);
351 dict[k]->clhmin = atoi(buf + 21);
354 dict[k]->crhmin = atoi(buf + 22);
400 if (dict[k]->utf8) {
424 state_num = hnj_get_state (dict[k], hashtab, word);
425 dict[k]->states[state_num].match = hnj_strdup (pattern + i);
426 dict[k]->states[state_num].repl = repl;
427 dict[k]->states[state_num].replindex = replindex;
429 dict[k]->states[state_num].replcut = strlen(word);
431 dict[k]->states[state_num].replcut = replcut;
441 state_num = hnj_get_state (dict[k], hashtab, word);
442 hnj_add_trans (dict[k], state_num, last_state, ch);
477 dict[k]->states[e->val].fallback_state = state_num;
484 dict[k]->states[e->val].fallback_state);
485 for (j = 0; j < dict[k]->states[e->val].num_trans; j++)
486 printf (" %c->%d\n", dict[k]->states[e->val].trans[j].ch,
487 dict[k]->states[e->val].trans[j].new_state);
496 if (k == 2) dict[0]->nextlevel = dict[1];
497 return dict[0];
500 void hnj_hyphen_free (HyphenDict *dict)
505 for (state_num = 0; state_num < dict->num_states; state_num++)
507 hstate = &dict->states[state_num];
515 if (dict->nextlevel) hnj_hyphen_free(dict->nextlevel);
517 hnj_free (dict->states);
519 hnj_free (dict);
524 int hnj_hyphen_hyphenate (HyphenDict *dict,
582 hstate = &dict->states[state];
601 match = dict->states[state].match;
603 if (match && !dict->states[state].repl)
706 int hnj_hyphen_hyph_(HyphenDict *dict, const char *word, int word_size,
782 hstate = &dict->states[state];
801 match = dict->states[state].match;
802 repl = dict->states[state].repl;
803 replindex = dict->states[state].replindex;
804 replcut = dict->states[state].replcut;
897 if (dict->nextlevel) {
933 hnj_hyphen_hyph_(dict, prep_word + begin + 1, i - begin + 1 + hyph,
966 hnj_hyphen_hyph_(dict->nextlevel, word, word_size,
968 if (!lend) hnj_hyphen_lhmin(dict->utf8, word, word_size, hyphens,
970 if (!rend) hnj_hyphen_rhmin(dict->utf8, word, word_size, hyphens,
1045 int hnj_hyphen_hyphenate2 (HyphenDict *dict,
1049 hnj_hyphen_hyph_(dict, word, word_size, hyphens, rep, pos, cut,
1050 dict->clhmin, dict->crhmin, 1, 1);
1051 hnj_hyphen_lhmin(dict->utf8, word, word_size,
1052 hyphens, rep, pos, cut, (dict->lhmin > 0 ? dict->lhmin : 2));
1053 hnj_hyphen_rhmin(dict->utf8, word, word_size,
1054 hyphens, rep, pos, cut, (dict->rhmin > 0 ? dict->rhmin : 2));
1056 if (dict->utf8) return hnj_hyphen_norm(word, word_size, hyphens, rep, pos, cut);
1061 int hnj_hyphen_hyphenate3 (HyphenDict *dict,
1066 lhmin = (lhmin > 0 ? lhmin : dict->lhmin);
1067 rhmin = (rhmin > 0 ? rhmin : dict->rhmin);
1068 hnj_hyphen_hyph_(dict, word, word_size, hyphens, rep, pos, cut,
1070 hnj_hyphen_lhmin(dict->utf8, word, word_size, hyphens,
1072 hnj_hyphen_rhmin(dict->utf8, word, word_size, hyphens,
1075 if (dict->utf8) return hnj_hyphen_norm(word, word_size, hyphens, rep, pos, cut);