0
|
1 /*
|
|
2 * $Id: do_dic_no.c,v 1.5 2003/05/11 18:41:49 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 /*
|
|
33 * Do Dic operation by DicNo
|
|
34 */
|
|
35
|
|
36 #include <stdio.h>
|
|
37
|
|
38 #include "demcom.h"
|
|
39 #include "commonhd.h"
|
|
40 #include "de_header.h"
|
|
41 #include "kaiseki.h"
|
|
42 #include "jdata.h"
|
|
43 #include "hinsi_file.h"
|
|
44
|
|
45 static void return_jbiki (struct jdata *jd);
|
|
46 static void return_jbiki1 (struct jdata *jd);
|
|
47 static int count_jdata (struct jdata *p);
|
|
48 static int count_jdata_kanji (struct jdata *p);
|
|
49
|
|
50 void
|
|
51 dic_init ()
|
|
52 {
|
|
53 int i;
|
|
54 for (i = 0; i < MAX_DIC; i++)
|
|
55 {
|
|
56 dic_table[i].body = -1;
|
|
57 dic_table[i].hindo = -1;
|
|
58 }
|
|
59 }
|
|
60
|
|
61 /*
|
|
62 Dic. OPE by DicNo.
|
|
63 */
|
|
64
|
|
65 /* js_dic_info */
|
|
66 void
|
|
67 js_dic_info ()
|
|
68 {
|
|
69 int dic_no, envi;
|
|
70 envi = get4_cur (); /* env_id */
|
|
71 dic_no = get4_cur ();
|
|
72 if (!dic_in_envp (dic_no, envi))
|
|
73 {
|
|
74 wnn_errorno = WNN_DICT_NOT_IN_ENV;
|
|
75 error_ret ();
|
|
76 putc_purge ();
|
|
77 return;
|
|
78 }
|
|
79 put4_cur (0);
|
|
80 put_dic_info (dic_no);
|
|
81 putc_purge ();
|
|
82 }
|
|
83
|
|
84 void
|
|
85 put_dic_info (int dic_no)
|
|
86 {
|
|
87 int fid, hfid;
|
|
88 struct JT *jtl;
|
|
89
|
|
90 put4_cur (dic_no);
|
|
91 put4_cur (fid = dic_table[dic_no].body);
|
|
92 put4_cur (hfid = dic_table[dic_no].hindo);
|
|
93 put4_cur (dic_table[dic_no].rw);
|
|
94 put4_cur (dic_table[dic_no].hindo_rw);
|
|
95 put4_cur (dic_table[dic_no].enablef);
|
|
96 put4_cur (dic_table[dic_no].nice);
|
|
97 put4_cur (dic_table[dic_no].rev);
|
|
98 /* added H.T */
|
|
99 jtl = (struct JT *) files[fid].area;
|
|
100 putnws_cur (jtl->comment, jtl->maxcomment);
|
|
101 puts_cur (files[fid].name);
|
|
102 if (hfid >= 0)
|
|
103 puts_cur (files[hfid].name);
|
|
104 else
|
|
105 puts_cur ("");
|
|
106 puts_n_cur (files[fid].passwd, WNN_PASSWD_LEN);
|
|
107 if (hfid >= 0)
|
|
108 puts_n_cur (files[hfid].passwd, WNN_PASSWD_LEN);
|
|
109 else
|
|
110 puts_n_cur (jtl->hpasswd, WNN_PASSWD_LEN);
|
|
111 put4_cur (jtl->syurui);
|
|
112 put4_cur (jtl->gosuu);
|
|
113 put4_cur (files[fid].localf);
|
|
114 if (hfid >= 0)
|
|
115 put4_cur (files[hfid].localf);
|
|
116 else
|
|
117 put4_cur (-1);
|
|
118 }
|
|
119
|
|
120
|
|
121
|
|
122
|
|
123 /* js_word_add */
|
|
124 void
|
|
125 js_word_add ()
|
|
126 {
|
|
127 int dic_no, hinsi, envi, hindo, ret;
|
|
128 w_char yomi[LENGTHYOMI], kanji[LENGTHKANJI], comment[LENGTHKANJI];
|
|
129 envi = get4_cur (); /* env_id */
|
|
130 dic_no = get4_cur ();
|
|
131 getws_cur (yomi, LENGTHYOMI);
|
|
132 getws_cur (kanji, LENGTHKANJI);
|
|
133 getws_cur (comment, LENGTHKANJI);
|
|
134 hinsi = get4_cur ();
|
|
135 hindo = get4_cur ();
|
|
136 ret = word_add (envi, dic_no, yomi, kanji, hinsi, hindo, comment);
|
|
137 if (ret == -1)
|
|
138 {
|
|
139 error_ret ();
|
|
140 }
|
|
141 else
|
|
142 {
|
|
143 put4_cur (ret);
|
|
144 }
|
|
145 putc_purge ();
|
|
146 }
|
|
147
|
|
148 /* js_word_delete */
|
|
149 void
|
|
150 js_word_delete ()
|
|
151 {
|
|
152 int dic_no, dic_entry, envi, ret;
|
|
153 envi = get4_cur (); /* env_id */
|
|
154 dic_no = get4_cur ();
|
|
155 dic_entry = get4_cur ();
|
|
156 ret = word_delete (envi, dic_no, dic_entry);
|
|
157 if (ret == -1)
|
|
158 {
|
|
159 error_ret ();
|
|
160 }
|
|
161 else
|
|
162 {
|
|
163 put4_cur (ret);
|
|
164 }
|
|
165 putc_purge ();
|
|
166 }
|
|
167
|
|
168 void
|
|
169 js_word_search_by_env ()
|
|
170 {
|
|
171 w_char yomi[LENGTHYOMI];
|
|
172 w_char ryomi[LENGTHYOMI];
|
|
173 int n;
|
|
174
|
|
175 c_env = env[get4_cur ()];
|
|
176 getws_cur (yomi, LENGTHYOMI);
|
|
177 #ifdef CONVERT_from_TOP
|
|
178 Strcpy (ryomi, yomi);
|
|
179 #else
|
|
180 Sreverse (ryomi, yomi);
|
|
181 #endif /* CONVERT_from_TOP */
|
|
182 init_jmt ();
|
|
183
|
|
184 n = jishobiki (ryomi, jmt_ptr);
|
|
185 if (n != Strlen (yomi))
|
|
186 { /* Want to return Error if n < 0 */
|
|
187 return_jbiki (NULL);
|
|
188 }
|
|
189 else
|
|
190 {
|
|
191 return_jbiki (jmt_ptr[n - 1]);
|
|
192 }
|
|
193 if (n > 0)
|
|
194 jmt_ptr += n;
|
|
195 putc_purge ();
|
|
196 }
|
|
197
|
|
198
|
|
199 void
|
|
200 js_word_search ()
|
|
201 {
|
|
202 w_char yomi[LENGTHYOMI];
|
|
203 w_char ryomi[LENGTHYOMI];
|
|
204 int dic_no;
|
|
205 int n;
|
|
206
|
|
207 get4_cur (); /* env_id */
|
|
208 dic_no = get4_cur ();
|
|
209 getws_cur (yomi, LENGTHYOMI);
|
|
210 #ifdef CONVERT_from_TOP
|
|
211 Strcpy (ryomi, yomi);
|
|
212 #else
|
|
213 Sreverse (ryomi, yomi);
|
|
214 #endif /* CONVERT_from_TOP */
|
|
215 init_jmt ();
|
|
216
|
|
217 n = word_search (dic_no, ryomi, jmt_ptr);
|
|
218 if (n != Strlen (yomi))
|
|
219 { /* Want to return Error if n < 0 */
|
|
220 return_jbiki (NULL);
|
|
221 }
|
|
222 else
|
|
223 {
|
|
224 return_jbiki (jmt_ptr[n - 1]);
|
|
225 }
|
|
226 if (n > 0)
|
|
227 jmt_ptr += n;
|
|
228 putc_purge ();
|
|
229 }
|
|
230
|
|
231
|
|
232 void
|
|
233 js_word_comment_set ()
|
|
234 {
|
|
235 int dic_no, envi, entry;
|
|
236 int ret;
|
|
237 w_char comment[LENGTHKANJI];
|
|
238
|
|
239 envi = get4_cur (); /* env_id */
|
|
240 dic_no = get4_cur ();
|
|
241 entry = get4_cur ();
|
|
242 getws_cur (comment, LENGTHKANJI);
|
|
243
|
|
244 ret = word_comment_set (envi, dic_no, entry, comment);
|
|
245 if (ret == -1)
|
|
246 {
|
|
247 error_ret ();
|
|
248 }
|
|
249 else
|
|
250 {
|
|
251 put4_cur (0);
|
|
252 }
|
|
253 putc_purge ();
|
|
254 }
|
|
255
|
|
256 void
|
|
257 js_word_info ()
|
|
258 {
|
|
259 int dic_no, entry;
|
|
260 struct jdata jdata;
|
|
261 w_char yomi[LENGTHYOMI + 1];
|
|
262 w_char ryomi[LENGTHYOMI + 1];
|
|
263
|
|
264 get4_cur (); /* env_id */
|
|
265 dic_no = get4_cur ();
|
|
266 entry = get4_cur ();
|
|
267 if (inspect (dic_no, entry, yomi, &jdata) == -1)
|
|
268 {
|
|
269 error_ret ();
|
|
270 putc_purge ();
|
|
271 }
|
|
272 else
|
|
273 {
|
|
274 put4_cur (0);
|
|
275 #ifdef CONVERT_from_TOP
|
|
276 Strcpy (ryomi, yomi);
|
|
277 #else
|
|
278 Sreverse (ryomi, yomi);
|
|
279 #endif /* CONVERT_from_TOP */
|
|
280 putws_cur (ryomi);
|
|
281 return_jbiki (&jdata);
|
|
282 putc_purge ();
|
|
283 }
|
|
284 }
|
|
285
|
|
286
|
|
287 static void
|
|
288 return_jbiki (struct jdata *jd)
|
|
289 {
|
|
290 put4_cur (count_jdata (jd));
|
|
291 put4_cur (count_jdata_kanji (jd));
|
|
292 return_jbiki1 (jd);
|
|
293 }
|
|
294
|
|
295 static void
|
|
296 return_jbiki1 (struct jdata *jd)
|
|
297 {
|
|
298 int t;
|
|
299 w_char kouho[LENGTHKANJI];
|
|
300 w_char comment[LENGTHKANJI];
|
|
301 struct jdata *p;
|
|
302
|
|
303 for (p = jd; p; p = p->jptr)
|
|
304 {
|
|
305 for (t = 0; t < p->kosuu; t++)
|
|
306 {
|
|
307 put4_cur (p->jishono);
|
|
308 put4_cur (p->serial + t);
|
|
309
|
|
310 put4_cur (*(p->hinsi + t));
|
|
311
|
|
312 put4_cur (motoni2 (*(p->hindo + t) & 0x7f));
|
|
313 put4_cur (*(p->hindo + t) >> 7);
|
|
314
|
|
315 /* internal hindo */
|
|
316 if (p->hindo_in)
|
|
317 {
|
|
318 put4_cur (motoni2 (*(p->hindo_in + t) & 0x7f));
|
|
319 put4_cur (*(p->hindo_in + t) >> 7);
|
|
320 }
|
|
321 else
|
|
322 {
|
|
323 put4_cur (-1);
|
|
324 put4_cur (-1);
|
|
325 }
|
|
326 }
|
|
327 }
|
|
328 put4_cur (-1);
|
|
329 for (p = jd; p; p = p->jptr)
|
|
330 {
|
|
331 for (t = 0; t < p->kosuu; t++)
|
|
332 {
|
|
333 get_knj_com (p, t, kouho, comment);
|
|
334 /* get_knj(p, t, kouho); H.T. Return Also Comment */
|
|
335 putws_cur (kouho); /* kanji */
|
|
336 putws_cur (comment); /* comment */
|
|
337 }
|
|
338 }
|
|
339 }
|
|
340
|
|
341 static int
|
|
342 count_jdata (struct jdata *p)
|
|
343 {
|
|
344 int sum;
|
|
345
|
|
346 for (sum = 0; p; p = p->jptr)
|
|
347 {
|
|
348 sum += p->kosuu;
|
|
349 }
|
|
350 return sum;
|
|
351 }
|
|
352
|
|
353 static int
|
|
354 count_jdata_kanji (struct jdata *p)
|
|
355 {
|
|
356 int sum, t;
|
|
357 w_char kouho[LENGTHKANJI];
|
|
358 w_char comment[LENGTHKANJI];
|
|
359
|
|
360 for (sum = 0; p; p = p->jptr)
|
|
361 {
|
|
362 for (t = 0; t < p->kosuu; t++)
|
|
363 {
|
|
364 get_knj_com (p, t, kouho, comment);
|
|
365 sum += Strlen (kouho); /* kanji */
|
|
366 sum += Strlen (comment); /* comment */
|
|
367 }
|
|
368 }
|
|
369 return sum;
|
|
370 }
|
|
371
|
|
372 void
|
|
373 js_hinsi_name ()
|
|
374 {
|
|
375 w_char *c;
|
|
376 int no;
|
|
377
|
|
378 no = get4_cur ();
|
|
379 if ((c = wnn_hinsi_name (no)) == NULL)
|
|
380 {
|
|
381 error_ret ();
|
|
382 putc_purge ();
|
|
383 return;
|
|
384 }
|
|
385 put4_cur (Strlen (c));
|
|
386 putws_cur (c);
|
|
387 putc_purge ();
|
|
388 }
|
|
389
|
|
390 void
|
|
391 js_hinsi_number ()
|
|
392 {
|
|
393 w_char name[WNN_HINSI_NAME_LEN];
|
|
394 int no;
|
|
395
|
|
396 getws_cur (name, WNN_HINSI_NAME_LEN);
|
|
397
|
|
398 if ((no = wnn_hinsi_number (name)) == -1)
|
|
399 {
|
|
400 error_ret ();
|
|
401 putc_purge ();
|
|
402 return;
|
|
403 }
|
|
404 put4_cur (no);
|
|
405 putc_purge ();
|
|
406 }
|
|
407
|
|
408
|
|
409 void
|
|
410 js_hinsi_list ()
|
|
411 {
|
|
412 w_char name[WNN_HINSI_NAME_LEN];
|
|
413 w_char *c, *c1;
|
|
414 int envi, dic_no, no;
|
|
415 int l, l1, k;
|
|
416 int fid = 0, mmynode;
|
|
417 struct wnn_hinsi_node *mynode;
|
|
418 struct JT *jtl;
|
|
419
|
|
420 envi = get4_cur ();
|
|
421 dic_no = get4_cur ();
|
|
422 getws_cur (name, WNN_HINSI_NAME_LEN);
|
|
423
|
|
424 if (dic_no == -1)
|
|
425 {
|
|
426 /* fid = env[envi]->fzk_fid; */
|
|
427 fid = 0;
|
|
428 mynode = NULL;
|
|
429 mmynode = 0;
|
|
430 }
|
|
431 else
|
|
432 {
|
|
433 #ifdef nodef /* fid ha toumen tukawanai */
|
|
434 if (!dic_in_envp (dic_no, envi))
|
|
435 {
|
|
436 wnn_errorno = WNN_DICT_NOT_IN_ENV;
|
|
437 error_ret ();
|
|
438 putc_purge ();
|
|
439 return;
|
|
440 }
|
|
441 #endif
|
|
442 if (dic_no >= MAX_DIC || dic_no < 0)
|
|
443 {
|
|
444 wnn_errorno = WNN_DICT_NOT_IN_ENV;
|
|
445 error_ret ();
|
|
446 putc_purge ();
|
|
447 return;
|
|
448 }
|
|
449
|
|
450 fid = dic_table[dic_no].body;
|
|
451 if (fid == -1)
|
|
452 {
|
|
453 wnn_errorno = WNN_DICT_NOT_IN_ENV;
|
|
454 error_ret ();
|
|
455 putc_purge ();
|
|
456 return;
|
|
457 }
|
|
458 jtl = (struct JT *) (files[fid].area);
|
|
459 mynode = jtl->node;
|
|
460 mmynode = jtl->maxnode;
|
|
461 if (mmynode == 0)
|
|
462 mynode = NULL;
|
|
463 }
|
|
464
|
|
465 if ((no = wnn_hinsi_list (name, &c, mynode, mmynode)) == -1)
|
|
466 {
|
|
467 error_ret ();
|
|
468 putc_purge ();
|
|
469 return;
|
|
470 }
|
|
471 put4_cur (no);
|
|
472 for (l = 0, c1 = c, k = 0; k < no; k++)
|
|
473 {
|
|
474 /* l += (l1 = Strlen(c1));
|
|
475 c1 += l1 + 1; H.T.*/
|
|
476 l += (l1 = Strlen (c1) + 1);
|
|
477 c1 += l1;
|
|
478 }
|
|
479 put4_cur (l);
|
|
480 for (k = 0, c1 = c; k < no; k++)
|
|
481 {
|
|
482 putws_cur (c1);
|
|
483 c1 += Strlen (c1) + 1;
|
|
484 }
|
|
485 putc_purge ();
|
|
486 }
|
|
487
|
|
488 void
|
|
489 js_hinsi_dicts ()
|
|
490 {
|
|
491 int envi;
|
|
492 w_char *name;
|
|
493 register int k;
|
|
494 int cnt;
|
|
495 struct JT *jtl;
|
|
496 int ret[MAX_DIC];
|
|
497 int no;
|
|
498 int mmynode;
|
|
499 struct wnn_hinsi_node *mynode;
|
|
500 int max;
|
|
501 register int dno;
|
|
502
|
|
503 envi = get4_cur ();
|
|
504 no = get4_cur ();
|
|
505 if (no != -1)
|
|
506 { /* H.T. n == -1 to return all dicts */
|
|
507 if ((name = wnn_hinsi_name (no)) == NULL)
|
|
508 {
|
|
509 error_ret ();
|
|
510 putc_purge ();
|
|
511 return;
|
|
512 }
|
|
513 }
|
|
514 cnt = 0;
|
|
515 max = env[envi]->jishomax;
|
|
516 for (k = 0; k < max; k++)
|
|
517 {
|
|
518 if ((dno = (env[envi]->jisho)[k]) == -1)
|
|
519 continue;
|
|
520 if (dic_table[dno].body == -1)
|
|
521 continue;
|
|
522 if (dic_table[dno].rw == WNN_DIC_RDONLY)
|
|
523 continue; /* H.T. */
|
|
524 if (no == -1)
|
|
525 {
|
|
526 ret[cnt++] = dno;
|
|
527 }
|
|
528 else
|
|
529 {
|
|
530 jtl = (struct JT *) (files[dic_table[dno].body].area);
|
|
531 mynode = jtl->node;
|
|
532 mmynode = jtl->maxnode;
|
|
533 if (mmynode == 0)
|
|
534 mynode = NULL;
|
|
535 if (wnn_has_hinsi (mynode, mmynode, name))
|
|
536 ret[cnt++] = dno;
|
|
537 }
|
|
538 }
|
|
539 put4_cur (cnt);
|
|
540 for (k = 0; k < cnt; k++)
|
|
541 {
|
|
542 put4_cur (ret[k]);
|
|
543 }
|
|
544 putc_purge ();
|
|
545 }
|
|
546
|
|
547 void
|
|
548 js_hinsi_table_set ()
|
|
549 {
|
|
550 w_char table[HEAP_LEN];
|
|
551 int envi, dic_no, fid;
|
|
552 /*
|
|
553 struct wnn_hinsi_node *mynode;
|
|
554 */
|
|
555 struct JT *jtl;
|
|
556
|
|
557 envi = get4_cur ();
|
|
558 dic_no = get4_cur ();
|
|
559 getws_cur (table, HEAP_LEN);
|
|
560
|
|
561
|
|
562 if (!dic_in_envp (dic_no, envi))
|
|
563 {
|
|
564 wnn_errorno = WNN_DICT_NOT_IN_ENV;
|
|
565 error_ret ();
|
|
566 putc_purge ();
|
|
567 return;
|
|
568 }
|
|
569
|
|
570 if (dic_no >= MAX_DIC || dic_no < 0)
|
|
571 {
|
|
572 wnn_errorno = WNN_DICT_NOT_IN_ENV;
|
|
573 error_ret ();
|
|
574 putc_purge ();
|
|
575 return;
|
|
576 }
|
|
577
|
|
578 fid = dic_table[dic_no].body;
|
|
579 if (fid == -1)
|
|
580 {
|
|
581 wnn_errorno = WNN_DICT_NOT_IN_ENV;
|
|
582 error_ret ();
|
|
583 putc_purge ();
|
|
584 return;
|
|
585 }
|
|
586 jtl = (struct JT *) (files[fid].area);
|
|
587 if (hinsi_table_set (jtl, table) == -1)
|
|
588 {
|
|
589 error_ret ();
|
|
590 putc_purge ();
|
|
591 return;
|
|
592 }
|
|
593 put4_cur (0);
|
|
594 putc_purge ();
|
|
595 }
|