0
|
1 /*
|
|
2 * $Id: jishoop.c,v 1.6 2003/06/07 02:23:58 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 #if defined(HAVE_CONFIG_H)
|
|
33 #include <config.h>
|
|
34 #endif
|
|
35
|
|
36 #include <stdio.h>
|
|
37
|
|
38 #if defined(HAVE_SYS_TYPES_H)
|
|
39 #include <sys/types.h>
|
|
40 #endif
|
|
41
|
|
42 #include "commonhd.h"
|
|
43 #include "de_header.h"
|
|
44 #include "jdata.h"
|
|
45
|
|
46 static void make_space ();
|
|
47 static int word_add1 (), word_delete1 (), word_comment_set1 ();
|
|
48
|
|
49 #ifndef min
|
|
50 #define min(a, b) ((a > b)? b:a)
|
|
51 #define max(a, b) ((a < b)? b:a)
|
|
52 #endif
|
|
53
|
|
54 int
|
|
55 word_add (envi, dic_no, yomi, kanji, hinsi, hindo, comment)
|
|
56 int envi;
|
|
57 int dic_no;
|
|
58 w_char *yomi;
|
|
59 w_char *kanji, *comment;
|
|
60 int hinsi, hindo;
|
|
61 {
|
|
62 int fid, k;
|
|
63 struct JT *jtl;
|
|
64 struct HJT *hjtl;
|
|
65 int serial;
|
|
66
|
|
67 if (Strlen (yomi) >= LENGTHYOMI)
|
|
68 {
|
|
69 wnn_errorno = WNN_YOMI_LONG;
|
|
70 return (-1);
|
|
71 }
|
|
72 if (Strlen (kanji) + Strlen (comment) + Strlen (yomi) >= LENGTHKANJI)
|
|
73 {
|
|
74 wnn_errorno = WNN_KANJI_LONG;
|
|
75 return (-1);
|
|
76 }
|
|
77 if (Strlen (yomi) == 0)
|
|
78 {
|
|
79 wnn_errorno = WNN_NO_YOMI;
|
|
80 return (-1);
|
|
81 }
|
|
82 if (!dic_in_envp (dic_no, envi))
|
|
83 {
|
|
84 wnn_errorno = WNN_DICT_NOT_IN_ENV;
|
|
85 return (-1);
|
|
86 }
|
|
87 if (dic_table[dic_no].rw == WNN_DIC_RDONLY)
|
|
88 {
|
|
89 wnn_errorno = WNN_RDONLY;
|
|
90 return (-1);
|
|
91 }
|
|
92
|
|
93 jtl = (struct JT *) (files[dic_table[dic_no].body].area);
|
|
94
|
|
95 if (jtl->syurui == WNN_STATIC_DICT)
|
|
96 {
|
|
97 wnn_errorno = WNN_NOT_A_UD;
|
|
98 return (-1);
|
|
99 }
|
|
100
|
|
101 if (wnn_get_hinsi_name (hinsi) == NULL)
|
|
102 {
|
|
103 return (-1);
|
|
104 }
|
|
105 if (jtl->syurui == WNN_UD_DICT)
|
|
106 {
|
|
107 if ((serial = word_add1 (jtl, yomi, hinsi, kanji, comment)) == -1)
|
|
108 return (-1);
|
|
109 }
|
|
110 else
|
|
111 { /* jtl->syurui == WNN_REV_DICT || CWNN_REV_DICT */
|
|
112 if ((serial = rd_word_add1 (jtl, yomi, hinsi, kanji, comment)) == -1)
|
|
113 return (-1);
|
|
114 }
|
|
115 if (dic_table[dic_no].hindo != -1)
|
|
116 {
|
|
117 hjtl = (struct HJT *) (files[dic_table[dic_no].hindo].area);
|
|
118 if (serial >= hjtl->maxserial)
|
|
119 {
|
|
120 if (serial >= hjtl->bufsize_serial)
|
|
121 {
|
|
122 hindo_file_realloc (hjtl);
|
|
123 }
|
|
124 hjtl->maxserial = jtl->maxserial;
|
|
125 }
|
|
126 hjtl->hindo[serial] = asshuku (hindo) | 0x80;
|
|
127 hjtl->hdirty = 1;
|
|
128 }
|
|
129 else
|
|
130 {
|
|
131 jtl->hindo[serial] = asshuku (hindo) | 0x80;
|
|
132 jtl->hdirty = 1;
|
|
133 }
|
|
134 /* Since other hindo file may be used with this dictionary,
|
|
135 update the size of such hindo file */
|
|
136 fid = dic_table[dic_no].body;
|
|
137 for (k = 0; k < MAX_DIC; k++)
|
|
138 {
|
|
139 if (dic_table[k].body == fid && dic_table[k].hindo != -1)
|
|
140 {
|
|
141 hjtl = (struct HJT *) (files[dic_table[k].hindo].area);
|
|
142 if (serial >= hjtl->maxserial)
|
|
143 {
|
|
144 if (serial >= hjtl->bufsize_serial)
|
|
145 {
|
|
146 hindo_file_realloc (hjtl);
|
|
147 }
|
|
148 hjtl->maxserial = jtl->maxserial;
|
|
149 hjtl->hindo[serial] = 0;
|
|
150 hjtl->hdirty = 1;
|
|
151 }
|
|
152 }
|
|
153 }
|
|
154
|
|
155 jtl->dirty = 1;
|
|
156 return (0);
|
|
157 }
|
|
158
|
|
159
|
|
160 int
|
|
161 word_comment_set (envi, dic_no, serial, comment)
|
|
162 int envi;
|
|
163 int dic_no;
|
|
164 int serial;
|
|
165 w_char *comment;
|
|
166 {
|
|
167 w_char yomi[LENGTHYOMI];
|
|
168 struct JT *jtl;
|
|
169
|
|
170 if (!dic_in_envp (dic_no, envi))
|
|
171 {
|
|
172 wnn_errorno = WNN_DICT_NOT_IN_ENV;
|
|
173 return (-1);
|
|
174 }
|
|
175
|
|
176 if (dic_table[dic_no].rw == WNN_DIC_RDONLY)
|
|
177 {
|
|
178 wnn_errorno = WNN_RDONLY;
|
|
179 return (-1);
|
|
180 }
|
|
181
|
|
182 jtl = (struct JT *) (files[dic_table[dic_no].body].area);
|
|
183
|
|
184 if (jtl->syurui == WNN_STATIC_DICT)
|
|
185 {
|
|
186 wnn_errorno = WNN_NOT_A_UD;
|
|
187 return (-1);
|
|
188 }
|
|
189
|
|
190 if (serial >= jtl->maxserial || serial < 0)
|
|
191 {
|
|
192 wnn_errorno = WNN_WORD_NO_EXIST;
|
|
193 return (-1);
|
|
194 }
|
|
195 get_yomi_from_serial (dic_no, serial, yomi);
|
|
196 jtl->dirty = 1;
|
|
197 return (word_comment_set1 ((struct JT *) (files[dic_table[dic_no].body].area), yomi, serial, comment));
|
|
198 }
|
|
199
|
|
200
|
|
201 int
|
|
202 word_delete (envi, dic_no, serial)
|
|
203 int envi;
|
|
204 int dic_no;
|
|
205 int serial;
|
|
206 {
|
|
207 w_char yomi[LENGTHYOMI];
|
|
208 struct JT *jtl;
|
|
209 struct HJT *hjtl;
|
|
210 int x, fid, k;
|
|
211
|
|
212 if (!dic_in_envp (dic_no, envi))
|
|
213 {
|
|
214 wnn_errorno = WNN_DICT_NOT_IN_ENV;
|
|
215 return (-1);
|
|
216 }
|
|
217
|
|
218 if (dic_table[dic_no].rw == WNN_DIC_RDONLY)
|
|
219 {
|
|
220 wnn_errorno = WNN_RDONLY;
|
|
221 return (-1);
|
|
222 }
|
|
223
|
|
224 jtl = (struct JT *) (files[dic_table[dic_no].body].area);
|
|
225 if (dic_table[dic_no].hindo != -1)
|
|
226 {
|
|
227 hjtl = (struct HJT *) (files[dic_table[dic_no].hindo].area);
|
|
228 }
|
|
229 else
|
|
230 hjtl = NULL;
|
|
231
|
|
232 if (jtl->syurui == WNN_STATIC_DICT)
|
|
233 {
|
|
234 wnn_errorno = WNN_NOT_A_UD;
|
|
235 return (-1);
|
|
236 }
|
|
237
|
|
238 if ((serial >= jtl->maxserial) || (serial < 0))
|
|
239 {
|
|
240 wnn_errorno = WNN_WORD_NO_EXIST;
|
|
241 return (-1);
|
|
242 }
|
|
243 if (get_yomi_from_serial (dic_no, serial, yomi) == -1)
|
|
244 {
|
|
245 wnn_errorno = WNN_WORD_NO_EXIST;
|
|
246 return (-1);
|
|
247 }
|
|
248 jtl->dirty = 1;
|
|
249 if (jtl->syurui == WNN_UD_DICT)
|
|
250 {
|
|
251 x = word_delete1 (jtl, hjtl, yomi, serial);
|
|
252 #if defined(CONVERT_by_STROKE) || defined(CONVERT_with_SiSheng)
|
|
253 }
|
|
254 else if ((jtl->syurui & 0xff) == WNN_REV_DICT)
|
|
255 {
|
|
256 #else
|
|
257 }
|
|
258 else if (jtl->syurui == WNN_REV_DICT)
|
|
259 {
|
|
260 #endif /* CONVERT_by_STROKE || CONVERT_with_SiSheng */
|
|
261 x = rd_word_delete1 (jtl, hjtl, serial);
|
|
262 }
|
|
263 else
|
|
264 {
|
|
265 wnn_errorno = WNN_NOT_A_UD;
|
|
266 x = -1;
|
|
267 }
|
|
268 if (x == -1)
|
|
269 return (-1);
|
|
270 /* Since other hindo file may be used with this dictionary,
|
|
271 update the size of such hindo file */
|
|
272 fid = dic_table[dic_no].body;
|
|
273 for (k = 0; k < MAX_DIC; k++)
|
|
274 {
|
|
275 if (dic_table[k].body == fid && dic_table[k].hindo != -1)
|
|
276 {
|
|
277 hjtl = (struct HJT *) (files[dic_table[k].hindo].area);
|
|
278 if (jtl->maxserial != hjtl->maxserial)
|
|
279 {
|
|
280 hjtl->maxserial = jtl->maxserial;
|
|
281 hjtl->hdirty = 1;
|
|
282 }
|
|
283 }
|
|
284 }
|
|
285 return (0);
|
|
286 }
|
|
287
|
|
288
|
|
289 static int
|
|
290 word_add1 (jtl, pyomi, hinsi, kanji, comment)
|
|
291 struct JT *jtl;
|
|
292 int hinsi;
|
|
293 w_char *kanji, *comment;
|
|
294 w_char *pyomi;
|
|
295 {
|
|
296 register struct uind1 *tary;
|
|
297 register struct uind2 *hopter, *hopter1;
|
|
298 register int key, key0, keye;
|
|
299 register struct uind2 *hop;
|
|
300 int len = Strlen (pyomi);
|
|
301 int serial = jtl->maxserial;
|
|
302 w_char yomi[LENGTHYOMI];
|
|
303
|
|
304 Sreverse (yomi, pyomi);
|
|
305
|
|
306 if ((jtl->bufsize_hontai <= jtl->maxhontai + sizeof (struct uind2) + Strlen (yomi))
|
1
|
307 && (!ud_realloc_hontai (jtl)))
|
0
|
308 {
|
|
309 return (-1);
|
|
310 }
|
|
311 if ((jtl->bufsize_kanji <= jtl->maxkanji + (Strlen (kanji) + Strlen (comment) + Strlen (yomi) + 3) * sizeof (w_char) + 1)
|
1
|
312 && (!ud_realloc_kanji (jtl)))
|
0
|
313 {
|
|
314 return (-1);
|
|
315 }
|
|
316 if (jtl->bufsize_serial <= jtl->maxserial + 4
|
1
|
317 && !ud_realloc_serial (jtl))
|
0
|
318 {
|
|
319 return (-1);
|
|
320 }
|
|
321 if (jtl->bufsize_table <= jtl->maxtable + sizeof (struct uind1)
|
1
|
322 && !ud_realloc_table (jtl))
|
0
|
323 {
|
|
324 return (-1);
|
|
325 }
|
|
326
|
|
327 tary = jtl->table;
|
|
328 hopter = (struct uind2 *) (jtl->hontai + jtl->maxhontai);
|
|
329
|
|
330 key = binary1 (tary, yomi, jtl->maxtable, jtl);
|
|
331 if (key < 0 || Strcmpud (&tary[key], yomi, jtl))
|
|
332 { /* No entry with same yomi */
|
|
333 key += 1;
|
|
334 for (key0 = key - 1; key0 >= 0; key0 = tary[key0].pter1)
|
|
335 {
|
1
|
336 hop = (struct uind2 *) (jtl->hontai + tary[key0].pter);
|
0
|
337 if (Substrud (&tary[key0], yomi, hop->yomi[0], jtl))
|
|
338 {
|
|
339 break;
|
|
340 }
|
|
341 }
|
|
342 make_space (tary, key, jtl);
|
|
343 for (keye = key + 1; keye < jtl->maxtable && Substrstud (yomi, &tary[keye], jtl); keye++)
|
|
344 {
|
|
345 if (tary[keye].pter1 == key0)
|
|
346 tary[keye].pter1 = key;
|
|
347 }
|
|
348 tary[key].pter1 = key0;
|
|
349 tary[key].yomi2 = 0;
|
|
350 tary[key].yomi1 = yomi[0] << 16;
|
|
351 if (yomi[1])
|
|
352 {
|
|
353 tary[key].yomi1 |= yomi[1];
|
|
354 if (yomi[2])
|
|
355 {
|
|
356 tary[key].yomi2 = yomi[2] << 16;
|
|
357 if (yomi[3])
|
|
358 {
|
|
359 tary[key].yomi2 |= yomi[3];
|
|
360 }
|
|
361 }
|
|
362 }
|
|
363 tary[key].pter = 0;
|
|
364 }
|
|
365 else
|
|
366 {
|
|
367 hopter1 = (struct uind2 *) (tary[key].pter + (char *) (jtl->hontai));
|
|
368 while (1)
|
|
369 {
|
|
370 w_char kanji1[LENGTHKANJI];
|
|
371 w_char comment1[LENGTHKANJI];
|
|
372 if (jtl->hinsi[hopter1->serial] == hinsi)
|
|
373 {
|
|
374 Get_kanji (hopter1->kanjipter + jtl->kanji, yomi, Strlen (yomi), kanji1, NULL, comment);
|
|
375 if (Strcmp (kanji, kanji1) == 0)
|
|
376 {
|
|
377 /* Same hinsi, same kanji, same yomi */
|
|
378 if (Strcmp (comment, comment1) != 0)
|
|
379 {
|
|
380 /* set_comment */
|
|
381 hopter1->kanjipter = jtl->maxkanji;
|
|
382 kanjiadd (jtl, kanji, yomi, comment);
|
|
383 }
|
|
384 return (hopter1->serial);
|
|
385 }
|
|
386 }
|
|
387 if (hopter1->next == 0)
|
|
388 break;
|
1
|
389 hopter1 = (struct uind2 *) (hopter1->next + (char *) (jtl->hontai));
|
0
|
390 }
|
|
391 }
|
|
392 hopter->next = tary[key].pter;
|
|
393 hopter->serial = jtl->maxserial++;
|
|
394 jtl->gosuu++;
|
|
395 hopter->kanjipter = jtl->maxkanji;
|
|
396 hopter->kosuu = 1;
|
|
397 hopter->yomi[0] = len;
|
|
398 Strncpy (hopter->yomi + 1, yomi + 4, len - 4);
|
|
399 tary[key].pter = (char *) hopter - (char *) (jtl->hontai);
|
|
400 jtl->maxhontai = (char *) (AL_INT (&(hopter->yomi[0]) + 1 + max ((len - 4), 0))) - (char *) (jtl->hontai);
|
|
401 jtl->hinsi[serial] = hinsi;
|
|
402 jtl->hindo[serial] = 0; /* Hindo is set later on upper module */
|
|
403 kanjiadd (jtl, kanji, yomi, comment);
|
|
404
|
|
405 return (serial);
|
|
406 }
|
|
407
|
|
408 void
|
|
409 kanjiadd (jtl, kanji, yomi, comment)
|
|
410 struct JT *jtl;
|
|
411 w_char *kanji, *comment, *yomi;
|
|
412 {
|
|
413 register UCHAR *dest = jtl->kanji + jtl->maxkanji;
|
1
|
414 long len;
|
0
|
415
|
|
416 #if defined(CONVERT_by_STROKE) || defined(CONVERT_with_SiSheng)
|
|
417 if ((jtl->syurui & 0xff) != WNN_REV_DICT)
|
|
418 {
|
|
419 #else
|
|
420 if (jtl->syurui != WNN_REV_DICT)
|
|
421 {
|
|
422 #endif /* CONVERT_by_STROKE || CONVERT_with_SiSheng */
|
|
423 yomi = NULL;
|
|
424 }
|
1
|
425 len = (long) kanjiaddr (dest, kanji, yomi, comment);
|
0
|
426 jtl->maxkanji += len;
|
|
427 }
|
|
428
|
|
429 static void
|
|
430 make_space (tary, key, jtl)
|
|
431 register struct JT *jtl;
|
|
432 register struct uind1 *tary;
|
|
433 register int key;
|
|
434 {
|
|
435 register struct uind1 *p, *p1, *pend;
|
|
436 int end = jtl->maxtable;
|
|
437
|
|
438 pend = tary + key;
|
|
439 for (p = tary + end - 1, p1 = tary + end; p >= pend; p--, p1--)
|
|
440 {
|
|
441 *p1 = *p; /* struct no dainyuu! */
|
|
442 if (p1->pter1 >= key)
|
|
443 p1->pter1++;
|
|
444 }
|
|
445 jtl->maxtable++;
|
|
446 }
|
|
447
|
|
448 static void
|
|
449 remove_space (tary, key, jtl, newkey)
|
|
450 register struct JT *jtl;
|
|
451 register struct uind1 *tary;
|
|
452 register int key, newkey;
|
|
453 {
|
|
454 register struct uind1 *p, *p1, *pend;
|
|
455 register int end = jtl->maxtable;
|
|
456
|
|
457 pend = tary + end;
|
|
458 for (p = tary + key + 1, p1 = tary + key; p < pend; p++, p1++)
|
|
459 {
|
|
460 *p1 = *p;
|
|
461 if (p1->pter1 > key)
|
|
462 p1->pter1--;
|
|
463 else if (p1->pter1 == key)
|
|
464 p1->pter1 = newkey;
|
|
465 }
|
|
466 jtl->maxtable--;
|
|
467 }
|
|
468
|
|
469 int
|
|
470 dic_in_envp (dic_no, envi)
|
|
471 int dic_no;
|
|
472 int envi;
|
|
473 {
|
|
474 register int k;
|
|
475
|
|
476 for (k = 0; k < env[envi]->jishomax; k++)
|
|
477 {
|
|
478 if (env[envi]->jisho[k] == dic_no)
|
|
479 {
|
|
480 return (1);
|
|
481 }
|
|
482 }
|
|
483 return (0);
|
|
484 }
|
|
485
|
|
486 static int
|
|
487 word_delete1 (jtl, hjtl, yomi, serial)
|
|
488 struct JT *jtl;
|
|
489 struct HJT *hjtl;
|
|
490 w_char *yomi;
|
|
491 int serial;
|
|
492 {
|
|
493 int k;
|
|
494 register struct uind2 *hopter;
|
|
495 register struct uind2 *p;
|
|
496 register struct uind1 *tary;
|
|
497 register int ind1;
|
|
498 int *next_pter;
|
|
499 UCHAR *c;
|
|
500 int tmp;
|
|
501
|
|
502 tary = jtl->table;
|
|
503
|
|
504 ind1 = binary (tary, yomi, jtl->maxtable, jtl);
|
|
505 if (ind1 == -1)
|
|
506 {
|
|
507 wnn_errorno = WNN_WORD_NO_EXIST;
|
|
508 return (-1);
|
|
509 }
|
|
510
|
|
511 for (next_pter = &(tary[ind1].pter), p = ((struct uind2 *) ((tary[ind1].pter) + jtl->hontai));; next_pter = &p->next, p = ((struct uind2 *) ((p->next) + jtl->hontai)))
|
|
512 {
|
|
513
|
|
514 if ((int) p->serial <= (int) serial && (int) p->serial + (int) p->kosuu > (int) serial)
|
|
515 goto found_it;
|
|
516 if (p->next == ENDPTR)
|
|
517 break;
|
|
518 }
|
|
519 wnn_errorno = WNN_WORD_NO_EXIST;
|
|
520 return (-1);
|
|
521
|
|
522 found_it:
|
|
523 if (p->kosuu == 1)
|
|
524 {
|
|
525 *next_pter = p->next;
|
1
|
526 if (tary[ind1].pter == 0)
|
0
|
527 remove_space (tary, ind1, jtl, tary[ind1].pter1);
|
|
528 if (p->serial == jtl->maxserial - 1)
|
|
529 {
|
|
530 jtl->maxserial--;
|
|
531 if (hjtl)
|
|
532 hjtl->maxserial--;
|
|
533 }
|
|
534 if ((int) p->kanjipter + (int) *(p->kanjipter + jtl->kanji) >= (int) jtl->maxkanji)
|
|
535 {
|
|
536 jtl->maxkanji = p->kanjipter;
|
|
537 }
|
|
538 if (jtl->maxhontai + (char *) (jtl->hontai) == (char *) (AL_INT (&(p->yomi[0]) + 1 + max (((int) p->yomi[0] - 4), 0))))
|
|
539 {
|
|
540 jtl->maxhontai = (char *) p - (char *) (jtl->hontai);
|
|
541 }
|
|
542 }
|
|
543 else if (p->serial == serial)
|
|
544 {
|
|
545 p->kosuu -= 1;
|
|
546 p->serial += 1;
|
|
547 p->kanjipter += *(p->kanjipter + jtl->kanji);
|
|
548 }
|
|
549 else if (p->serial + p->kosuu - 1 == serial)
|
|
550 {
|
|
551 p->kosuu -= 1;
|
|
552 }
|
|
553 else
|
|
554 { /* devide left space into 2 */
|
|
555
|
|
556 if (jtl->bufsize_hontai <= jtl->maxhontai + sizeof (struct uind2) + Strlen (yomi))
|
|
557 {
|
|
558 tmp = (char *) p - (char *) jtl->hontai;
|
1
|
559 if (ud_realloc_hontai (jtl) == 0)
|
0
|
560 {
|
|
561 return (-1);
|
|
562 }
|
|
563 error1 ("Realloc in Word_delete for serial %d\n", serial);
|
|
564 p = (struct uind2 *) (tmp + jtl->hontai);
|
|
565
|
|
566 }
|
|
567 hopter = (struct uind2 *) (jtl->hontai + jtl->maxhontai);
|
|
568 hopter->next = p->next;
|
|
569 hopter->serial = serial + 1;
|
|
570
|
|
571 for (k = 0, c = p->kanjipter + jtl->kanji; k < serial - p->serial + 1; k++)
|
|
572 {
|
|
573 c += *c;
|
|
574 }
|
|
575 hopter->kanjipter = c - jtl->kanji;
|
|
576
|
|
577 hopter->kosuu = p->kosuu - (serial - p->serial) - 1;
|
|
578 hopter->yomi[0] = p->yomi[0];
|
|
579 Strncpy (hopter->yomi + 1, p->yomi + 1, max (((int) p->yomi[0] - 4), 0));
|
|
580 p->next = (char *) hopter - (char *) (jtl->hontai);
|
|
581 jtl->maxhontai = (char *) (AL_INT (&(hopter->yomi[0]) + 1 + max (((int) p->yomi[0] - 4), 0))) - (char *) (jtl->hontai);
|
|
582
|
|
583 p->kosuu = serial - p->serial;
|
|
584 }
|
|
585 jtl->hinsi[serial] = SAKUJO_HINSI;
|
|
586 jtl->gosuu--;
|
|
587 return (0);
|
|
588 }
|
|
589
|
|
590
|
|
591 static int
|
|
592 word_comment_set1 (jtl, yomi, serial, comment)
|
|
593 struct JT *jtl;
|
|
594 w_char *yomi;
|
|
595 int serial;
|
|
596 w_char *comment;
|
|
597 {
|
|
598 int k;
|
|
599 register struct uind2 *p;
|
|
600 register struct uind1 *tary;
|
|
601 register int ind1;
|
|
602 UCHAR *kptr;
|
|
603 w_char yomi1[LENGTHYOMI], kanji[LENGTHKANJI], ocomment[LENGTHKANJI];
|
|
604
|
|
605 tary = jtl->table;
|
|
606
|
|
607 if (jtl->syurui == WNN_UD_DICT)
|
|
608 {
|
|
609 ind1 = binary (tary, yomi, jtl->maxtable, jtl);
|
|
610 if (ind1 == -1)
|
|
611 {
|
|
612 wnn_errorno = WNN_WORD_NO_EXIST;
|
|
613 return (-1);
|
|
614 }
|
|
615
|
|
616 for (p = ((struct uind2 *) ((tary[ind1].pter) + jtl->hontai));; p = ((struct uind2 *) ((p->next) + jtl->hontai)))
|
|
617 {
|
|
618
|
|
619 if ((int) p->serial <= (int) serial && (int) p->serial + (int) p->kosuu > (int) serial)
|
|
620 {
|
|
621 kptr = p->kanjipter + jtl->kanji;
|
|
622 for (k = serial - p->serial; k > 0; k--)
|
|
623 {
|
|
624 kptr += *kptr;
|
|
625 }
|
|
626 goto found_it;
|
|
627 }
|
|
628 if (p->next == ENDPTR)
|
|
629 break;
|
|
630 }
|
|
631 wnn_errorno = WNN_WORD_NO_EXIST;
|
|
632 return (-1);
|
|
633 }
|
|
634 else
|
|
635 {
|
|
636 kptr = jtl->kanji + (jtl->ri2)[serial].kanjipter;
|
|
637 }
|
|
638 found_it:
|
|
639 get_kanji_str (kptr, kanji, yomi1, ocomment);
|
|
640 if (Strlen (ocomment) > Strlen (comment))
|
|
641 {
|
|
642 w_char *com, *kan, *yom;
|
|
643 Get_kanji_str_r (kptr, &kan, &yom, &com);
|
|
644 Strcpy (com, comment);
|
|
645 }
|
|
646 else
|
|
647 {
|
|
648 if (jtl->bufsize_kanji <= jtl->maxkanji + (Strlen (kanji) + Strlen (comment) + Strlen (yomi1) + 4) * 2)
|
|
649 {
|
1
|
650 if (ud_realloc_kanji (jtl) == 0)
|
0
|
651 {
|
|
652 return (-1);
|
|
653 }
|
|
654 }
|
|
655 *(kptr + 1) = FORWARDED;
|
|
656 *(w_char *) (kptr + 2) = (jtl->maxkanji + jtl->kanji - kptr) >> 16;
|
|
657 *(w_char *) (kptr + 4) = (jtl->maxkanji + jtl->kanji - kptr) & 0xffff;
|
|
658
|
|
659 kanjiadd (jtl, kanji, yomi1, comment);
|
|
660 #if defined(CONVERT_by_STROKE) || defined(CONVERT_with_SiSheng)
|
|
661 if ((jtl->syurui & 0xff) == WNN_REV_DICT)
|
|
662 {
|
|
663 #else
|
|
664 if (jtl->syurui == WNN_REV_DICT)
|
|
665 {
|
|
666 #endif /* CONVERT_by_STROKE || CONVERT_with_SiSheng */
|
|
667 /* We need to spend one serial_no to ensure that the entry
|
|
668 before this and after this are not connected */
|
|
669 if (jtl->bufsize_serial <= jtl->maxserial + 4
|
1
|
670 && ud_realloc_serial (jtl) == 0)
|
0
|
671 {
|
|
672 return (-1);
|
|
673 }
|
|
674 jtl->hinsi[jtl->maxserial] = SAKUJO_HINSI;
|
|
675 jtl->ri2[jtl->maxserial].kanjipter = 0xffffffff;
|
|
676 jtl->ri2[jtl->maxserial].next[D_YOMI] = jtl->ri2[jtl->maxserial].next[D_KANJI] = RD_ENDPTR;
|
|
677 jtl->maxserial++;
|
|
678 jtl->maxri2++;
|
|
679 }
|
|
680 }
|
|
681 return (0);
|
|
682
|
|
683 #ifdef nodef
|
|
684 /* UCHAR *c, *c0; */
|
|
685 /* int kan, len; */
|
|
686 if (p->kosuu == 1)
|
|
687 {
|
|
688 Get_kanji (p->kanjipter + jtl->kanji, yomi, Strlen (yomi), kanji, NULL, NULL);
|
|
689 if ((jtl->bufsize_kanji <= jtl->maxkanji + (Strlen (kanji) + Strlen (comment)) * sizeof (w_char) + 4)
|
|
690 && (ud_realloc_kanji (jtl) == NULL))
|
|
691 {
|
|
692 return (-1);
|
|
693 }
|
|
694 if (p->kanjipter + *(p->kanjipter + jtl->kanji) >= jtl->maxkanji)
|
|
695 {
|
|
696 jtl->maxkanji = p->kanjipter;
|
|
697 }
|
|
698 p->kanjipter = jtl->maxkanji;
|
|
699 kanjiadd (jtl, kanji, yomi, comment);
|
|
700 }
|
|
701 else
|
|
702 {
|
|
703 /*nagasa wo hakatte realloc */
|
|
704 for (k = 0, c = p->kanjipter + jtl->kanji; k < p->kosuu; k++)
|
|
705 c += *c;
|
|
706 len = c - (p->kanjipter + jtl->kanji);
|
|
707 while (jtl->bufsize_kanji <= jtl->maxkanji + (Strlen (kanji) + Strlen (comment)) * sizeof (w_char) + 4 + len)
|
|
708 {
|
|
709 if (ud_realloc_kanji (jtl) == NULL)
|
|
710 {
|
|
711 return (-1);
|
|
712 }
|
|
713 }
|
|
714 if (p->kanjipter + len >= jtl->maxkanji)
|
|
715 {
|
|
716 jtl->maxkanji = p->kanjipter;
|
|
717 }
|
|
718 kan = jtl->maxkanji;
|
|
719
|
|
720 /*mae made no nagasa wo hakatte bcopy */
|
|
721 for (k = 0, c = p->kanjipter + jtl->kanji; k < serial - p->serial; k++)
|
|
722 {
|
|
723 c += *c;
|
|
724 }
|
|
725 len = c - (p->kanjipter + jtl->kanji);
|
|
726 bcopy (p->kanjipter + jtl->kanji, jtl->maxkanji + jtl->kanji, len);
|
|
727
|
|
728 jtl->maxkanji += len;
|
|
729 Get_kanji (c, yomi, Strlen (yomi), kanji, NULL, NULL);
|
|
730 kanjiadd (jtl, kanji, yomi, comment);
|
|
731 c += *c;
|
|
732
|
|
733 c0 = c;
|
|
734 for (k = serial + 1, c = p->kanjipter + jtl->kanji; k < p->kosuu + p->serial; k++)
|
|
735 {
|
|
736 c += *c;
|
|
737 }
|
|
738 len = c - c0;
|
|
739 bcopy (c0, jtl->maxkanji + jtl->kanji, len);
|
|
740 jtl->maxkanji += len;
|
|
741 p->kanjipter = kan;
|
|
742 }
|
|
743 return (0);
|
|
744 #endif
|
|
745 }
|
|
746
|
|
747
|
|
748 int
|
|
749 hindo_file_size_justify (wfp, whfp)
|
|
750 struct wnn_file *wfp, *whfp;
|
|
751 {
|
|
752 struct HJT *hjtp;
|
|
753 struct JT *jtp;
|
|
754 int k;
|
|
755
|
|
756 jtp = (struct JT *) (wfp->area);
|
|
757 hjtp = (struct HJT *) (whfp->area);
|
|
758
|
|
759 if (hjtp->maxserial != jtp->maxserial)
|
|
760 {
|
|
761 if (hjtp->maxserial < jtp->maxserial)
|
|
762 {
|
|
763 while (hjtp->bufsize_serial <= jtp->maxserial)
|
|
764 {
|
1
|
765 if (hindo_file_realloc (hjtp) == 0)
|
0
|
766 return (-1);
|
|
767 }
|
|
768 error1 ("Dic file size is bigger than that of Hindo file!");
|
|
769 for (k = hjtp->maxserial; k < jtp->maxserial; k++)
|
|
770 {
|
|
771 hjtp->hindo[k] = 0;
|
|
772 }
|
|
773 }
|
|
774 else
|
|
775 {
|
|
776 error1 ("Hindo file size is bigger than that of Dic file!");
|
|
777 }
|
|
778 hjtp->maxserial = jtp->maxserial;
|
|
779 hjtp->hdirty = 1;
|
|
780 }
|
|
781 return (0);
|
|
782 }
|