0
|
1 /*
|
|
2 * $Id: jbiki.c,v 1.4 2003/06/07 02:22:23 hiroo Exp $
|
|
3 */
|
|
4
|
|
5 /*
|
|
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
|
|
7 * This file is part of FreeWnn.
|
|
8 *
|
|
9 * Copyright Kyoto University Research Institute for Mathematical Sciences
|
|
10 * 1987, 1988, 1989, 1990, 1991, 1992
|
|
11 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
|
|
12 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992
|
|
13 * Copyright FreeWnn Project 1999, 2000, 2003
|
|
14 *
|
|
15 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp>
|
|
16 *
|
|
17 * This program is free software; you can redistribute it and/or modify
|
|
18 * it under the terms of the GNU General Public License as published by
|
|
19 * the Free Software Foundation; either version 2 of the License, or
|
|
20 * (at your option) any later version.
|
|
21 *
|
|
22 * This program is distributed in the hope that it will be useful,
|
|
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
25 * GNU General Public License for more details.
|
|
26 *
|
|
27 * You should have received a copy of the GNU General Public License
|
|
28 * along with this program; if not, write to the Free Software
|
|
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
30 */
|
|
31
|
|
32 #ifdef HAVE_CONFIG_H
|
|
33 # include <config.h>
|
|
34 #endif
|
|
35
|
|
36 #include <stdio.h>
|
|
37
|
|
38 #include "commonhd.h"
|
|
39 #include "de_header.h"
|
|
40 #include "jdata.h"
|
|
41 #include "kaiseki.h"
|
|
42
|
|
43
|
|
44 #ifndef min
|
|
45 #define min(a, b) ((a > b)? b:a)
|
|
46 #define max(a, b) ((a < b)? b:a)
|
|
47 #endif
|
|
48
|
|
49 static int maxlevel;/** 読みの何文字目までマッチするエントリーがあったか */
|
|
50 static struct jdata **jmt;/** 候補を返す場所へのポインタ */
|
|
51 static int number;/** クライアントの辞書番号 */
|
|
52 static unsigned short *hinsistart;
|
|
53 static UCHAR *hindostart;
|
|
54 static UCHAR *hindo2start;
|
|
55
|
|
56 #ifdef CONVERT_with_SiSheng
|
|
57 static unsigned short *sishengstart;
|
|
58 static unsigned int sisheng_int;
|
|
59 static w_char pan_yomi[256];
|
|
60 static char pan_tmp[256];
|
|
61 #endif /* CONVERT_with_SiSheng */
|
|
62
|
|
63 static int ud_biki (struct JT *, w_char *);
|
|
64 static int sd_biki ();
|
|
65 static int sd_biki_one ();
|
|
66 static int sdbinary ();
|
|
67
|
|
68 int
|
|
69 jishobiki (w_char *yomi, /* 読みの先頭へのポインタ */
|
|
70 struct jdata **jmtx) /* 結果を返す領域の先頭 */
|
|
71 {
|
|
72 struct JT *jtp;
|
|
73 int k;
|
|
74 #ifdef CONVERT_with_SiSheng /* TMP */
|
|
75 char sisheng_si[LENGTHBUNSETSU];
|
|
76 w_char yomi_tmp[LENGTHBUNSETSU];
|
|
77 get_sisheng (yomi, sisheng_si, yomi_tmp);
|
|
78 sisheng_int = 0;
|
|
79 sscanf (sisheng_si, "%d", &sisheng_int);
|
|
80 #endif /* CONVERT_with_SiSheng */
|
|
81
|
|
82 maxlevel = 0;
|
|
83 jmt = jmtx;
|
|
84
|
|
85 for (k = 0; k < c_env->jishomax; k++)
|
|
86 {
|
|
87 number = c_env->jisho[k];
|
|
88 if (dic_table[c_env->jisho[k]].enablef)
|
|
89 {
|
|
90 jtp = (struct JT *) (files[dic_table[c_env->jisho[k]].body].area);
|
|
91 hindo2start = (dic_table[c_env->jisho[k]].hindo != -1) ? jtp->hindo : NULL;
|
|
92 hindostart = (dic_table[c_env->jisho[k]].hindo != -1) ? ((struct HJT *) (files[dic_table[c_env->jisho[k]].hindo].area))->hindo : jtp->hindo;
|
|
93 #ifdef CONVERT_with_SiSheng
|
|
94 if (jtp->syurui == CWNN_REV_DICT)
|
|
95 sishengstart = jtp->sisheng;
|
|
96 else
|
|
97 sishengstart = 0;
|
|
98 #endif /* CONVERT_with_SiSheng */
|
|
99 hinsistart = jtp->hinsi;
|
|
100 if (jtp->syurui == WNN_UD_DICT)
|
|
101 {
|
|
102 #ifdef CONVERT_with_SiSheng
|
|
103 if (ud_biki (jtp, yomi_tmp) == -1)
|
|
104 #else
|
|
105 if (ud_biki (jtp, yomi) == -1)
|
|
106 #endif /* CONVERT_with_SiSheng */
|
|
107 {
|
|
108 goto err;
|
|
109 }
|
|
110 }
|
|
111 #ifdef CONVERT_with_SiSheng
|
|
112 else if ((jtp->syurui & 0x00ff) == WNN_REV_DICT)
|
|
113 {
|
|
114 if (rd_biki (jtp, yomi_tmp, dic_table[c_env->jisho[k]].rev) == -1)
|
|
115 #else
|
|
116 else if (jtp->syurui == WNN_REV_DICT)
|
|
117 {
|
|
118 if (rd_biki (jtp, yomi, dic_table[c_env->jisho[k]].rev) == -1)
|
|
119 #endif /* CONVERT_with_SiSheng */
|
|
120 {
|
|
121 goto err;
|
|
122 }
|
|
123 }
|
|
124 else
|
|
125 {
|
|
126 #ifdef CONVERT_with_SiSheng
|
|
127 if (sd_biki (jtp, yomi_tmp) == -1)
|
|
128 #else
|
|
129 if (sd_biki (jtp, yomi) == -1)
|
|
130 #endif /* CONVERT_with_SiSheng */
|
|
131 {
|
|
132 goto err;
|
|
133 }
|
|
134 }
|
|
135 }
|
|
136 }
|
|
137 return (maxlevel);
|
|
138 err:
|
|
139 {
|
|
140 error1 ("No More Jishobiki Area\n");
|
|
141 for (k = 0; k < maxlevel; k++)
|
|
142 {
|
|
143 jmt[k] = NULL;
|
|
144 }
|
|
145 return (-1);
|
|
146 }
|
|
147 }
|
|
148
|
|
149
|
|
150
|
|
151 static int
|
|
152 ud_biki (struct JT *jtl, w_char *yomi)
|
|
153 {
|
|
154 struct jdata *jep;
|
|
155 register struct uind2 *p;
|
|
156 register int ind1;
|
|
157 register int len;
|
|
158
|
|
159 struct uind1 *tary;
|
|
160
|
|
161 tary = jtl->table;
|
|
162
|
|
163 for (ind1 = binary (tary, yomi, jtl->maxtable, jtl); ind1 >= 0; ind1 = tary[ind1].pter1)
|
|
164 {
|
|
165
|
|
166 for (p = ((struct uind2 *) ((tary[ind1].pter) + jtl->hontai));
|
|
167 ;
|
|
168 p = ((struct uind2 *) ((p->next) + jtl->hontai)))
|
|
169 {
|
|
170 len = p->yomi[0];
|
|
171 if (jmt + len > jmt_end)
|
|
172 return (-1);
|
|
173
|
|
174 /* set jmt */
|
|
175 if (*(jmt + len - 1))
|
|
176 {
|
|
177 for (jep = *(jmt + len - 1); jep->jptr != NULL; jep = jep->jptr);
|
|
178 jep->jptr = j_e_p;
|
|
179 }
|
|
180 else
|
|
181 {
|
|
182 *(jmt + len - 1) = j_e_p;
|
|
183 }
|
|
184
|
|
185 maxlevel = max (maxlevel, len);
|
|
186 if (j_e_p >= jmtw_end)
|
|
187 return (-1);
|
3
|
188 j_e_p->kanji1 = p->kanjipter; //xxx is this an offset? may result in failure --yaz
|
0
|
189 j_e_p->kanji2 = 0;
|
|
190 j_e_p->serial = p->serial;
|
|
191 j_e_p->kosuu = p->kosuu;
|
|
192 j_e_p->jishono = number;
|
|
193 j_e_p->jptr = NULL;
|
|
194 j_e_p->hinsi = hinsistart + p->serial;
|
|
195 j_e_p->hindo = hindostart + p->serial;
|
|
196 if (hindo2start)
|
|
197 j_e_p->hindo_in = hindo2start + p->serial;
|
|
198 else
|
|
199 j_e_p->hindo_in = NULL;
|
|
200 j_e_p->which = D_YOMI;
|
|
201 j_e_p += 1;
|
|
202 if (p->next == ENDPTR)
|
|
203 break;
|
|
204 }
|
|
205 }
|
|
206 return (maxlevel);
|
|
207 }
|
|
208
|
|
209 /*
|
|
210 * Find the element of user dict which matches longest with the yomi.
|
|
211 */
|
|
212
|
|
213 int
|
|
214 binary1 (tary, yomi, end, jtl)
|
|
215 register struct uind1 *tary;
|
|
216 register w_char *yomi;
|
|
217 register int end;
|
|
218 struct JT *jtl;
|
|
219 {
|
|
220 register int start = -1;
|
|
221 register int key;
|
|
222
|
|
223 for (; start + 1 < end;)
|
|
224 {
|
|
225 key = (start + end) / 2;
|
|
226 if (Strcmpud (&tary[key], yomi, jtl) > 0)
|
|
227 {
|
|
228 end = key;
|
|
229 }
|
|
230 else
|
|
231 {
|
|
232 start = key;
|
|
233 }
|
|
234 }
|
|
235 return (start);
|
|
236 }
|
|
237
|
|
238 int
|
|
239 binary (tary, yomi, end, jtl)
|
|
240 register struct uind1 *tary;
|
|
241 register w_char *yomi;
|
|
242 int end;
|
|
243 struct JT *jtl;
|
|
244 {
|
|
245 register int start;
|
|
246 register struct uind2 *hop;
|
|
247 register int len;
|
|
248
|
|
249 start = binary1 (tary, yomi, end, jtl);
|
|
250 for (; start >= 0; start = tary[start].pter1)
|
|
251 {
|
|
252 hop = ((struct uind2 *) ((tary[start].pter) + jtl->hontai));
|
|
253 len = hop->yomi[0];
|
|
254 if (Substrud (&tary[start], yomi, len, jtl))
|
|
255 {
|
|
256 return (start);
|
|
257 }
|
|
258 }
|
|
259 return (-1);
|
|
260 }
|
|
261
|
|
262 int
|
|
263 Strcmpud (ui1p, yomi, jtl)
|
|
264 struct uind1 *ui1p;
|
|
265 w_char *yomi;
|
|
266 struct JT *jtl;
|
|
267 {
|
|
268 unsigned int y1, y2;
|
|
269 int tmp;
|
|
270 int len;
|
|
271 struct uind2 *hop;
|
|
272
|
|
273 if (yomi[0] == 0)
|
|
274 return (ui1p->yomi1 > 0);
|
|
275 y1 = yomi[0] << 16 | yomi[1];
|
3
|
276 if ((tmp = (ui1p->yomi1 - y1)))
|
0
|
277 {
|
|
278 return ((ui1p->yomi1 > y1) ? 1 : -1);
|
|
279 }
|
|
280 if (yomi[1] == 0)
|
|
281 return (0);
|
|
282 if (yomi[2] == 0)
|
|
283 return (ui1p->yomi2 > 0);
|
|
284 y2 = yomi[2] << 16 | yomi[3];
|
3
|
285 if ((tmp = (ui1p->yomi2 - y2)))
|
0
|
286 {
|
|
287 return ((ui1p->yomi2 > y2) ? 1 : -1);
|
|
288 }
|
|
289 hop = ((struct uind2 *) ((ui1p->pter) + jtl->hontai));
|
|
290 if ((len = hop->yomi[0]) < 4)
|
|
291 return (0);
|
|
292 if ((tmp = Strncmp (hop->yomi + 1, yomi + 4, len - 4)) != 0)
|
|
293 {
|
|
294 return (tmp);
|
|
295 }
|
|
296 return (0 - yomi[len]);
|
|
297 }
|
|
298
|
|
299 int
|
|
300 Substrud (ui1p, yomi, len, jtl)
|
|
301 struct uind1 *ui1p;
|
|
302 w_char *yomi;
|
|
303 int len;
|
|
304 struct JT *jtl;
|
|
305 {
|
|
306 switch (len)
|
|
307 {
|
|
308 case 0:
|
|
309 return (1);
|
|
310 case 1:
|
|
311 return ((ui1p->yomi1 >> 16 == yomi[0]));
|
|
312 case 2:
|
|
313 return (ui1p->yomi1 == (yomi[0] << 16 | yomi[1]));
|
|
314 case 3:
|
|
315 return ((ui1p->yomi1 == (yomi[0] << 16 | yomi[1])) && ui1p->yomi2 >> 16 == yomi[2]);
|
|
316 case 4:
|
|
317 return ((ui1p->yomi1 == (yomi[0] << 16 | yomi[1])) && (ui1p->yomi2 == (yomi[2] << 16 | yomi[3])));
|
|
318 default:
|
|
319 return ((ui1p->yomi1 == (yomi[0] << 16 | yomi[1])) && (ui1p->yomi2 == (yomi[2] << 16 | yomi[3])) && !(Strncmp (((struct uind2 *) (ui1p->pter + jtl->hontai))->yomi + 1, yomi + 4, len - 4)));
|
|
320 }
|
|
321 }
|
|
322
|
|
323 int
|
|
324 Substrstud (yomi, ui1p, jtl)
|
|
325 w_char *yomi;
|
|
326 struct uind1 *ui1p;
|
|
327 struct JT *jtl;
|
|
328 {
|
|
329 int len = Strlen (yomi);
|
|
330
|
|
331 switch (len)
|
|
332 {
|
|
333 case 0:
|
|
334 return (1);
|
|
335 case 1:
|
|
336 return ((ui1p->yomi1 >> 16 == yomi[0]));
|
|
337 case 2:
|
|
338 return (ui1p->yomi1 == (yomi[0] << 16 | yomi[1]));
|
|
339 case 3:
|
|
340 return ((ui1p->yomi1 == (yomi[0] << 16 | yomi[1])) && ui1p->yomi2 >> 16 == yomi[2]);
|
|
341 case 4:
|
|
342 return ((ui1p->yomi1 == (yomi[0] << 16 | yomi[1])) && (ui1p->yomi2 == (yomi[2] << 16 | yomi[3])));
|
|
343 default:
|
|
344 if (len > (int) ((struct uind2 *) ((ui1p->pter) + jtl->hontai))->yomi[0])
|
|
345 return (0);
|
|
346 return ((ui1p->yomi1 == (yomi[0] << 16 | yomi[1])) && (ui1p->yomi2 == (yomi[2] << 16 | yomi[3])) && !(Strncmp (((struct uind2 *) ((ui1p->pter) + jtl->hontai))->yomi + 1, yomi + 4, len - 4)));
|
|
347 }
|
|
348 }
|
|
349
|
|
350 int
|
|
351 Substrudud (ui1d, ui1s, jtl)
|
|
352 register struct uind1 *ui1d, *ui1s;
|
|
353 register struct JT *jtl;
|
|
354 {
|
|
355 if (ui1d->yomi1 != ui1s->yomi1)
|
|
356 {
|
|
357 if ((ui1d->yomi1 == 0) || (((ui1d->yomi1 & 0xffff0000) == (ui1s->yomi1 & 0xffff0000)) && ((ui1d->yomi1 & 0x0000ffff) == 0)))
|
|
358 {
|
|
359 return (1);
|
|
360 }
|
|
361 else
|
|
362 return (0);
|
|
363 }
|
|
364 else if (ui1d->yomi2 != ui1d->yomi2)
|
|
365 {
|
|
366 if ((ui1d->yomi2 == 0) || (((ui1d->yomi2 & 0xffff0000) == (ui1s->yomi2 & 0xffff0000)) && ((ui1d->yomi2 & 0x0000ffff) == 0)))
|
|
367 {
|
|
368 return (1);
|
|
369 }
|
|
370 else
|
|
371 return (0);
|
|
372 }
|
|
373 else
|
|
374 {
|
|
375 return (!(Strncmp (
|
|
376 ((struct uind2 *) ((ui1d->pter) + jtl->hontai))->yomi + 1,
|
|
377 ((struct uind2 *) ((ui1s->pter) + jtl->hontai))->yomi + 1, ((struct uind2 *) ((ui1d->pter) + jtl->hontai))->yomi[0])));
|
|
378 }
|
|
379 }
|
|
380
|
|
381 /*
|
|
382 *
|
|
383 *
|
|
384 *sd_biki
|
|
385 *
|
|
386 *
|
|
387 */
|
|
388
|
|
389 UCHAR *hontaistart;
|
|
390
|
|
391 static int
|
|
392 sd_biki (jtl, yomi)
|
|
393 struct JT *jtl;
|
|
394 w_char *yomi;
|
|
395 {
|
|
396
|
|
397 hontaistart = jtl->hontai;
|
|
398 return (sd_biki_one (jtl->hontai, 0, yomi));
|
|
399 }
|
|
400
|
|
401 static int
|
|
402 sd_biki_one (hopter, level, yomi)
|
|
403 char *hopter;
|
|
404 w_char *yomi;
|
|
405 int level;
|
|
406 {
|
|
407
|
|
408 int tsize;
|
|
409 w_char *charst;
|
|
410 w_char *sumst;
|
|
411 int *ptrst;
|
|
412 int state;
|
|
413 struct jdata *jep;
|
|
414 int index;
|
|
415 int cnt;
|
|
416 int serial;
|
|
417
|
|
418 switch ((state = *(w_char *) hopter))
|
|
419 {
|
|
420 case ST_NORMAL:
|
|
421 case ST_NOPTER:
|
|
422 tsize = *(w_char *) (hopter + 2);
|
|
423 charst = (w_char *) (hopter + 12);
|
|
424 sumst = ((w_char *) charst + tsize + 2); /* + 2 keeps two zero words */
|
|
425 ptrst = (int *) ((w_char *) sumst + tsize);
|
|
426 if ((index = sdbinary (*yomi, charst, tsize)) < 0)
|
|
427 return (maxlevel);
|
|
428
|
|
429 if ((cnt = sumst[index] - sumst[index - 1]) > 0)
|
|
430 {
|
|
431 if (jmt + level >= jmt_end)
|
|
432 return (-1);
|
|
433
|
|
434 /* set jmt */
|
|
435 if (*(jmt + level))
|
|
436 {
|
|
437 for (jep = *(jmt + level); jep->jptr != NULL; jep = jep->jptr);
|
|
438 jep->jptr = j_e_p;
|
|
439 }
|
|
440 else
|
|
441 {
|
|
442 *(jmt + level) = j_e_p;
|
|
443 }
|
|
444
|
|
445 maxlevel = max (maxlevel, level + 1);
|
|
446 if (j_e_p >= jmtw_end)
|
|
447 return (-1);
|
3
|
448 j_e_p->kanji1 = *(int *) (hopter + 8); //xxx what's? --yaz
|
0
|
449 j_e_p->kanji2 = sumst[index - 1];
|
|
450 j_e_p->serial = serial = *(int *) (hopter + 4) + sumst[index - 1];
|
|
451 j_e_p->kosuu = cnt;
|
|
452 j_e_p->jishono = number;
|
|
453 j_e_p->jptr = NULL;
|
|
454 j_e_p->hinsi = hinsistart + serial;
|
|
455 j_e_p->hindo = hindostart + serial;
|
|
456 if (hindo2start)
|
|
457 j_e_p->hindo_in = hindo2start + serial;
|
|
458 else
|
|
459 j_e_p->hindo_in = NULL;
|
|
460 j_e_p->which = D_YOMI;
|
|
461 j_e_p += 1;
|
|
462 }
|
|
463 if (state == ST_NORMAL)
|
|
464 {
|
|
465 if (ptrst[index] != ENDPTR)
|
|
466 {
|
|
467 sd_biki_one (hontaistart + ptrst[index], level + 1, yomi + 1);
|
|
468 }
|
|
469 }
|
|
470 break;
|
|
471 case ST_NOENT:
|
|
472 tsize = *(w_char *) (hopter + 2);
|
|
473 charst = (w_char *) (hopter + 4);
|
|
474 ptrst = (int *) AL_INT ((w_char *) charst + tsize);
|
|
475 if ((index = sdbinary (*yomi, charst, tsize)) < 0)
|
|
476 return (maxlevel);
|
|
477 sd_biki_one (hontaistart + ptrst[index], level + 1, yomi + 1);
|
|
478 break;
|
|
479 case ST_SMALL:
|
|
480 if (*yomi != *(w_char *) (hopter + 2))
|
|
481 return (maxlevel);
|
|
482 sd_biki_one (hopter + 4, level + 1, yomi + 1);
|
|
483 break;
|
|
484
|
|
485 }
|
|
486 return (maxlevel);
|
|
487 }
|
|
488
|
|
489
|
|
490 static int
|
|
491 sdbinary (ch, chst, tsize)
|
|
492 register w_char ch;
|
|
493 register w_char *chst;
|
|
494 int tsize;
|
|
495 {
|
|
496 register w_char *chst1 = chst;
|
|
497 register w_char *chend = chst + tsize;
|
|
498 register w_char *key;
|
|
499
|
|
500 for (; chst < chend;)
|
|
501 {
|
|
502 key = chst + ((chend - chst) >> 1);
|
|
503 if (*key == ch)
|
|
504 return (key - chst1);
|
|
505 if (*key < ch)
|
|
506 chst = key + 1;
|
|
507 else
|
|
508 chend = key - 1;
|
|
509 }
|
|
510 if (*chst == ch)
|
|
511 return (chst - chst1);
|
|
512 return (-1);
|
|
513 }
|
|
514
|
|
515 int
|
|
516 word_search (dic_no, yomi, jmtx)
|
|
517 int dic_no;
|
|
518 w_char *yomi;
|
|
519 /** 読みの先頭へのポインタ */
|
|
520 struct jdata **jmtx;
|
|
521 /** 結果を返す領域の先頭 */
|
|
522 {
|
|
523
|
|
524 register struct JT *jtp;
|
|
525
|
|
526 maxlevel = 0;
|
|
527 jmt = jmtx;
|
|
528
|
|
529 if (dic_no >= MAX_DIC || dic_no < 0 || dic_table[dic_no].body == -1)
|
|
530 return (-1);
|
|
531 number = dic_no;
|
|
532 jtp = (struct JT *) (files[dic_table[dic_no].body].area);
|
|
533 hindo2start = (dic_table[dic_no].hindo != -1) ? jtp->hindo : NULL;
|
|
534 hindostart = (dic_table[dic_no].hindo != -1) ? ((struct HJT *) (files[dic_table[dic_no].hindo].area))->hindo : jtp->hindo;
|
|
535
|
|
536 hinsistart = jtp->hinsi;
|
|
537 if (jtp->syurui == WNN_UD_DICT)
|
|
538 {
|
|
539 if (ud_biki (jtp, yomi) == -1)
|
|
540 return (-1);
|
|
541 #if defined(CONVERT_by_STROKE) || defined(CONVERT_with_SiSheng)
|
|
542 }
|
|
543 else if ((jtp->syurui & 0x00ff) == WNN_REV_DICT)
|
|
544 {
|
|
545 #else
|
|
546 }
|
|
547 else if (jtp->syurui == WNN_REV_DICT)
|
|
548 {
|
|
549 #endif /* CONVERT_by_STROKE || CONVERT_with_SiSheng */
|
|
550 if (rd_biki (jtp, yomi, dic_table[dic_no].rev) == -1)
|
|
551 return (-1);
|
|
552 }
|
|
553 else
|
|
554 {
|
|
555 if (sd_biki (jtp, yomi) == -1)
|
|
556 return (-1);
|
|
557 }
|
|
558 return (maxlevel);
|
|
559 }
|
|
560
|
|
561
|
|
562
|
|
563 /**************************************
|
|
564 ****** Rev_Dic *********
|
|
565 **************************************/
|
|
566
|
|
567 int
|
|
568 rd_biki (jtl, yomi, which)
|
|
569 struct JT *jtl;
|
|
570 w_char *yomi;
|
|
571 register int which;
|
|
572 {
|
|
573 register struct rind2 *p;
|
|
574 register int ind, serial;
|
|
575 register int len;
|
|
576 register int prev;
|
|
577 register struct jdata **jepp;
|
|
578
|
|
579 struct rind1 *tary;
|
|
580 struct rind2 *ri2;
|
|
581 UCHAR *kanji;
|
|
582
|
|
583 tary = jtl->ri1[which];
|
|
584 ri2 = jtl->ri2;
|
|
585 kanji = jtl->kanji;
|
|
586
|
|
587 for (ind = rd_binary (tary, yomi, jtl->maxri1[which], ri2, kanji, which); ind >= 0; ind = tary[ind].pter1)
|
|
588 {
|
|
589 p = tary[ind].pter + ri2;
|
3
|
590 len = Get_kanji_len (p->kanjipter + kanji, which); // xxx regard p->kanjipter as an offset for now --yaz
|
0
|
591 if (jmt + len > jmt_end)
|
|
592 return (-1);
|
|
593 /* set jmt */
|
|
594 jepp = &(jmt[len - 1]);
|
|
595 for (; *jepp; jepp = &((*jepp)->jptr));
|
|
596 maxlevel = max (maxlevel, len);
|
|
597 prev = -2; /* prev + 1 is not a serial number */
|
|
598 for (;; p = p->next[which] + ri2)
|
|
599 {
|
|
600 serial = p - ri2;
|
|
601 if (serial == prev + 1)
|
|
602 {
|
|
603 (j_e_p - 1)->kosuu++;
|
|
604 }
|
|
605 else
|
|
606 {
|
|
607 *jepp = j_e_p;
|
|
608 if (j_e_p >= jmtw_end)
|
|
609 return (-1);
|
3
|
610 j_e_p->kanji1 = p->kanjipter; //xxx this may result in failure --yaz
|
0
|
611 j_e_p->kanji2 = 0;
|
|
612 j_e_p->serial = serial;
|
|
613 j_e_p->kosuu = 1;
|
|
614 j_e_p->jishono = number;
|
|
615 j_e_p->jptr = NULL;
|
|
616 j_e_p->hinsi = hinsistart + serial;
|
|
617 j_e_p->hindo = hindostart + serial;
|
|
618 #ifdef CONVERT_with_SiSheng
|
|
619 if (sishengstart)
|
|
620 {
|
|
621 j_e_p->sisheng = sishengstart + serial;
|
|
622 j_e_p->sisheng_int = sisheng_int;
|
|
623 }
|
|
624 #endif /* CONVERT_with_SiSheng */
|
|
625 if (hindo2start)
|
|
626 j_e_p->hindo_in = hindo2start + serial;
|
|
627 else
|
|
628 j_e_p->hindo_in = NULL;
|
|
629 j_e_p->which = which;
|
|
630 j_e_p += 1;
|
|
631 jepp = &((*jepp)->jptr);
|
|
632 }
|
|
633 prev = serial;
|
|
634 if (p->next[which] == RD_ENDPTR)
|
|
635 break;
|
|
636 }
|
|
637 }
|
|
638 return (maxlevel);
|
|
639 }
|
|
640
|
|
641 /*
|
|
642 * Find the element of user dict which matches longest with the yomi.
|
|
643 */
|
|
644
|
|
645 int
|
|
646 rd_binary1 (tary, yomi, end, ri2, kanji, which)
|
|
647 register struct rind1 *tary;
|
|
648 register w_char *yomi;
|
|
649 register int end;
|
|
650 struct rind2 *ri2;
|
|
651 UCHAR *kanji;
|
|
652 int which;
|
|
653 {
|
|
654 register w_char *s1, *s2;
|
|
655 register int start = -1;
|
|
656 register int key;
|
|
657
|
|
658 for (; start + 1 < end;)
|
|
659 {
|
|
660 key = (start + end) / 2;
|
|
661 s1 = KANJI_str (ri2[tary[key].pter].kanjipter + kanji, which);
|
|
662 #ifdef CONVERT_with_SiSheng /* reform_dic */
|
|
663 s1 = biki_sisheng (s1, pan_tmp, pan_yomi);
|
|
664 #endif /* CONVERT_with_SiSheng */
|
|
665 s2 = yomi;
|
|
666 /* This is same as Strcmp(s1, s2) */
|
|
667 for (; *s1 != 0 && *s1 == *s2; s1++, s2++);
|
|
668 if (*s1 > *s2)
|
|
669 {
|
|
670 end = key;
|
|
671 }
|
|
672 else
|
|
673 {
|
|
674 start = key;
|
|
675 }
|
|
676 }
|
|
677 return (start);
|
|
678 }
|
|
679
|
|
680 /* returns the entry which matches longest with yomi.*/
|
|
681 int
|
|
682 rd_binary (tary, yomi, end, ri2, kanji, which)
|
|
683 register struct rind1 *tary;
|
|
684 register w_char *yomi;
|
|
685 register int end;
|
|
686 struct rind2 *ri2;
|
|
687 UCHAR *kanji;
|
|
688 int which;
|
|
689 {
|
|
690 register w_char *s1, *s2;
|
|
691 register int start;
|
|
692 /*
|
|
693 register int len;
|
|
694 */
|
|
695
|
|
696 start = rd_binary1 (tary, yomi, end, ri2, kanji, which);
|
|
697 for (; start != RD_ENDPTR; start = tary[start].pter1)
|
|
698 {
|
|
699 s1 = KANJI_str (ri2[tary[start].pter].kanjipter + kanji, which);
|
|
700 #ifdef CONVERT_with_SiSheng /* reform_dic */
|
|
701 s1 = biki_sisheng (s1, pan_tmp, pan_yomi);
|
|
702 #endif /* CONVERT_with_SiSheng */
|
|
703 s2 = yomi;
|
|
704 /* This is same as Substr(s1, s2) */
|
|
705 for (; *s1 != 0 && *s1 == *s2; s1++, s2++);
|
|
706 if (!*s1)
|
|
707 {
|
|
708 return (start);
|
|
709 }
|
|
710 }
|
|
711 return (-1);
|
|
712 }
|
|
713
|
|
714 /* returns the entry which matches accurately with yomi.*/
|
|
715
|
|
716 int
|
|
717 rd_binary_same (tary, yomi, end, ri2, kanji, which)
|
|
718 register struct rind1 *tary;
|
|
719 register w_char *yomi;
|
|
720 register int end;
|
|
721 struct rind2 *ri2;
|
|
722 UCHAR *kanji;
|
|
723 int which;
|
|
724 {
|
|
725 register int start;
|
|
726 /*
|
|
727 register int len;
|
|
728 */
|
|
729 w_char *tmp;
|
|
730
|
|
731 start = rd_binary1 (tary, yomi, end, ri2, kanji, which);
|
|
732 for (; start >= 0; start = tary[start].pter1)
|
|
733 {
|
|
734 tmp = KANJI_str (ri2[tary[start].pter].kanjipter + kanji, which);
|
|
735 #ifdef CONVERT_with_SiSheng /* reform_dic */
|
|
736 tmp = biki_sisheng (tmp, pan_tmp, pan_yomi);
|
|
737 #endif /* CONVERT_with_SiSheng */
|
|
738 if (!Strcmp (tmp, yomi))
|
|
739 {
|
|
740 return (start);
|
|
741 }
|
|
742 }
|
|
743 return (-1);
|
|
744 }
|
|
745
|
|
746
|
|
747 /*
|
|
748 * Gd_biki( Giji (Regular Dict) biki routine.
|
|
749 *
|
|
750 *
|
|
751 * GD Format
|
|
752 * [ - ] moji no syuugou.
|
|
753 * p* p no 0 kai ijou no kurikaesi(p = syuugou)
|
|
754 * []+ p no 1 kai ijou no kurikaesi(p = syuugou)
|
|
755 *
|
|
756 *
|
|
757 * ri2 is only used to point kanji
|
|
758 */
|
|
759 #define GD_SET_START '['
|
|
760 #define GD_SET_END ']'
|
|
761 #define GD_KURIKAESI0 '*'
|
|
762 #define GD_KURIKAESI1 '+'
|
|
763 #define GD_ESCAPE '\\'
|
|
764 #define GD_FROMTO '-'
|