1 /*
2 * $Id: jlv3.c,v 1.9 2002/07/14 04:26:57 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, 2002
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 Nihongo Henkan Library
34 */
35 /*
36 entry functions
37
38 jd_open jd_open_in jd_close
39 jd_begin jd_end
40 jd_next jd_reconv jd_tanconv
41 jd_udp jd_udchg jd_freqsv
42 jd_dicadd jd_dicdel jd_dicinfo
43 jd_wdel jd_wsch jd_wreg
44 jd_setevf jd_getevf
45 jd_dicstatus jd_whdel
46 jd_mkdir jd_access
47 jd_who jd_version
48
49 extern Variables
50 int wnn_errorno;
51 */
52
53 #ifdef HAVE_CONFIG_H
54 # include <config.h>
55 #endif
56
57 #include <stdio.h>
58 #include <ctype.h>
59 #if STDC_HEADERS
60 # include <stdlib.h>
61 # include <string.h>
62 #else
63 # if HAVE_MALLOC_H
64 # include <malloc.h>
65 # endif
66 # if HAVE_STRINGS_H
67 # include <strings.h>
68 # endif
69 #endif /* STDC_HEADERS */
70 #if HAVE_FCNTL_H
71 # include <fcntl.h>
72 #endif
73 #include <pwd.h>
74 #if HAVE_UNISTD_H
75 # include <unistd.h>
76 #endif
77 #include <sys/types.h>
78
79 #include "jllib.h"
80 #include "jlib.h"
81 #include "wnnerror.h"
82 #include "wnn_string.h"
83 #include "wnn_os.h"
84
85
86 /* These are used to convert w_char and char strings */
87 static w_char wchartmp[256];
88 static char chartmp[256];
89
90 static struct wnn_buf *buf;
91
92 /* "jd_server_dead_env" �ϡ��Ȥ�ɬ�פ�������ޤ���
93 �ߴ����Τ�������ˤ���ޤ���
94 V4 �Ǥϡ������С������Ǥ⡢�����ȥ��顼����ޤ���
95 */
96 jmp_buf jd_server_dead_env;
97 int jd_server_dead_env_flg = 0;
98
99 #define JD_WNN_DEAD \
100 { \
101 buf->env->js_id->js_dead_env_flg = 1; \
102 if (setjmp(buf->env->js_id->js_dead_env) == 666) { \
103 if (jlib_work_area) { \
104 free(jlib_work_area); \
105 jlib_work_area = NULL;} \
106 jl_close(buf); \
107 if (jd_server_dead_env_flg) \
108 longjmp(jd_server_dead_env,666); \
109 return -1; \
110 } \
111 }
112
113 /* j Lib. */
114 static char *jlib_work_area = NULL;
115
116 /* bun joho */
117 static struct bunjoho bun; /** ʸ���� **/
118
119 static int current_bun_no = -1; /* ��������äƤ���ʸ�� */
120 static int current_ud = -1; /* �����ȡ��桼������ */
121
122 static struct wnn_ret_buf ret_buf = { 0, NULL };
123
124 /* get login name form /etc/passwd file */
125 static char *
getlogname()126 getlogname ()
127 {
128 extern struct passwd *getpwuid ();
129 struct passwd *p;
130
131 if ((p = getpwuid (getuid ())) == NULL)
132 return (NULL);
133 return (p->pw_name);
134 }
135
136 /*
137 * Lib. Functions
138 */
139
140 /** jd_close **/
141 int
jd_close(void)142 jd_close (void)
143 {
144 if (jlib_work_area)
145 {
146 free (jlib_work_area);
147 jlib_work_area = NULL;
148 }
149 if (jl_dic_save_all (buf) < 0)
150 return (-1);
151 jl_close (buf);
152 return (0);
153 }
154
155 int jd_begin ();
156 static int henkan_rcv ();
157
158 /** jd_reconv **/
159 int
jd_reconv(bunsetsu_no,kbuf,kb_siz)160 jd_reconv (bunsetsu_no, kbuf, kb_siz)
161 int bunsetsu_no, kb_siz;
162 w_char *kbuf;
163 {
164 JD_WNN_DEAD if (bunsetsu_no == 0)
165 return jd_begin (kbuf, kb_siz);
166 if (jl_ren_conv (buf, &(bun.kana_buf)[((bun.klist)[bunsetsu_no]).s_ichi], bunsetsu_no, -1, WNN_USE_MAE) < 0)
167 return (-1);
168 return henkan_rcv (bunsetsu_no, kbuf, kb_siz);
169 }
170
171 /** jd_begin **/
172 int
jd_begin(kbuf,kb_siz)173 jd_begin (kbuf, kb_siz)
174 w_char *kbuf;
175 int kb_siz;
176 {
177 JD_WNN_DEAD current_bun_no = -1;
178 jl_kill (buf, 0, -1);
179 if (jl_ren_conv (buf, bun.kana_buf, 0, -1, WNN_NO_USE) < 0)
180 return (-1);
181
182 return (henkan_rcv (0, kbuf, kb_siz));
183 }
184
185 /** jd_tanconv **/
186 int
jd_tanconv(bunsetsu_no,moji_no,kbuf,kb_siz)187 jd_tanconv (bunsetsu_no, moji_no, kbuf, kb_siz)
188 int bunsetsu_no, moji_no, kb_siz;
189 w_char *kbuf;
190 {
191 JD_WNN_DEAD if (moji_no < 0)
192 return (-1);
193 if (jl_nobi_conv (buf, bunsetsu_no, moji_no, -1, WNN_USE_MAE, WNN_SHO) < 0)
194 return (-1);
195 return henkan_rcv (bunsetsu_no, kbuf, kb_siz);
196 }
197
198 /** �Ѵ���̤�������� **/
199 static int
henkan_rcv(bunsetsu_no,kbuf,kb_siz)200 henkan_rcv (bunsetsu_no, kbuf, kb_siz)
201 int bunsetsu_no; /** ʸ���ֹ� **/
202 w_char *kbuf; /** �����Хåե��� **/
203 int kb_siz; /** �����Хåե��������� **/
204 {
205
206 register w_char *b, *p;
207 register int i, bun_no;
208 register KOUHO_ENT *klp;
209 int kanji_len = 0;
210 int tmp;
211
212 bun_no = jl_bun_suu (buf);
213 if (jl_kanji_len (buf, bunsetsu_no, -1) >= kb_siz)
214 return -1;
215
216 if (bun_no >= bun.klist_size)
217 {
218 wnn_errorno = WNN_LONG_MOJIRETSU;
219 return -1;
220 }
221 for (i = bunsetsu_no, klp = &((bun.klist)[bunsetsu_no]), b = kbuf; i < bun_no; klp++, i++)
222 {
223 klp->s_ichi = jl_yomi_len (buf, 0, i);
224 klp->jl = jl_jiri_len (buf, i);
225 klp->fl = jl_fuzoku_len (buf, i);
226 klp->jishono = buf->bun[i]->dic_no;
227 klp->serial = buf->bun[i]->entry;
228 if (jl_kanji_len (buf, i, i + 1) + kanji_len >= kb_siz)
229 {
230 wnn_errorno = WNN_LONG_MOJIRETSU;
231 return (-1);
232 }
233 klp->k_data = b;
234 jl_get_kanji (buf, i, i + 1, b);
235 tmp = jl_jiri_kanji_len (buf, i);
236 b += tmp;
237 kanji_len += tmp + 1;
238 *b = 0;
239 b++;
240 klp->pl = 0;
241 for (p = klp->k_data; *p; p++)
242 {
243 klp->pl += (*p & 0x8000) ? 2 : 1;
244 }
245 klp->pl += (klp->fl * 2);
246 }
247 klp->s_ichi = -1;
248 return (bun_no - bunsetsu_no);
249 }
250
251 static int up_date_jikouho ();
252
253 /** jd_end **/
254
255 int
jd_end()256 jd_end ()
257 {
258 int ret;
259
260 JD_WNN_DEAD if (current_bun_no != -1)
261 {
262 up_date_jikouho ();
263 current_bun_no = -1;
264 }
265 ret = jl_update_hindo (buf, 0, -1);
266 jl_kill (buf, 0, -1);
267 return (ret);
268 }
269
270
271 /** jd_next **/
272 int
jd_next(bunsetsu_no,to_go)273 jd_next (bunsetsu_no, to_go)
274 int bunsetsu_no;
275 JIKOUHOJOHO *to_go;
276 {
277 register int no_of_kouho, i;
278 register w_char *b;
279 register JIKOUHO_ENT *jlp;
280
281 JD_WNN_DEAD if (current_bun_no != -1 && current_bun_no != bunsetsu_no)
282 up_date_jikouho ();
283 current_bun_no = bunsetsu_no;
284 if (jl_zenkouho (buf, bunsetsu_no, WNN_USE_MAE, WNN_UNIQ) < 0)
285 return (-1);
286 no_of_kouho = jl_zenkouho_suu (buf);
287
288 if (no_of_kouho >= to_go->jlist_size - 1)
289 {
290 wnn_errorno = WNN_JKTAREA_FULL;
291 return (-1);
292 }
293 for (i = 0, jlp = to_go->jlist, b = to_go->kanji_buf; i < no_of_kouho; jlp++, i++)
294 {
295
296 jlp->jl = jl_jiri_len (buf, bunsetsu_no);
297 jlp->jishono = buf->bun[bunsetsu_no]->dic_no;
298 jlp->serial = buf->bun[bunsetsu_no]->entry;
299 jlp->k_data = b;
300 if (jl_kanji_len (buf, bunsetsu_no, bunsetsu_no + 1) >= to_go->kanji_buf_size)
301 {
302 wnn_errorno = WNN_JKTAREA_FULL;
303 return (-1);
304 }
305 jl_get_kanji (buf, bunsetsu_no, bunsetsu_no + 1, b);
306 b += jl_jiri_kanji_len (buf, bunsetsu_no);
307 *b = 0;
308 b++;
309 if (jl_next (buf) < 0)
310 return (-1);
311 }
312 jlp->jl = -1;
313 return no_of_kouho;
314 }
315
316 static int
up_date_jikouho()317 up_date_jikouho ()
318 {
319 register int no_of_kouho, i;
320 int jishono, serial;
321
322 jishono = (bun.klist)[current_bun_no].jishono;
323 serial = (bun.klist)[current_bun_no].serial;
324
325 no_of_kouho = jl_zenkouho_suu (buf);
326
327 for (i = 0; i < no_of_kouho; i++)
328 {
329 if (jishono == buf->bun[current_bun_no]->dic_no && serial == buf->bun[current_bun_no]->entry)
330 return (0);
331 if (jl_next (buf) < 0)
332 return (-1);
333 }
334 wnn_errorno = WNN_WORD_NO_EXIST;
335 return (-1);
336 }
337
338 /* JD dictionary */
339
340 /** jd_dicadd **/
341 int
jd_dicadd(fn,fn1,prio,hrdonly)342 jd_dicadd (fn, fn1, prio, hrdonly)
343 char *fn, *fn1;
344 int prio, hrdonly;
345 {
346 int rdonly;
347 WNN_DIC_INFO ret;
348 int dic_no;
349
350 JD_WNN_DEAD if (fn1 == 0 || *fn1 == 0)
351 { /* UD */
352 rdonly = hrdonly;
353 }
354 else if ((hrdonly == WNN_DIC_RDONLY) &&
355 /* READ ONLY SD && hind file is none */
356 (js_access (jl_env (buf), fn, 4) != -1) && (js_access (jl_env (buf), fn1, 4) == -1))
357 {
358 if ((dic_no = jl_dic_add (buf, fn, fn1, WNN_DIC_ADD_NOR, prio, WNN_DIC_RDONLY, WNN_DIC_RW, NULL, NULL, WNN_CREATE, NULL)) < 0)
359 return (-1);
360 if (jl_dic_delete (buf, dic_no) < 0)
361 return (-1);
362 rdonly = WNN_DIC_RDONLY;
363 }
364 else
365 {
366 rdonly = WNN_DIC_RDONLY;
367 }
368 if ((dic_no = jl_dic_add (buf, fn, fn1, WNN_DIC_ADD_NOR, prio, rdonly, hrdonly, NULL, NULL, WNN_CREATE, NULL)) < 0)
369 /* pw_d pw_h err mes */
370 return (-1);
371 if (js_dic_info (jl_env (buf), dic_no, &ret) < 0)
372 return (-1);
373 if ((ret.type == WNN_UD_DICT || ret.type == WNN_REV_DICT) && ret.rw == WNN_DIC_RW)
374 current_ud = dic_no;
375 return (dic_no);
376 }
377
378 /** jd_dicdel **/
379 int
jd_dicdel(dict_no)380 jd_dicdel (dict_no)
381 int dict_no;
382 {
383 JD_WNN_DEAD return (jl_dic_delete (buf, dict_no));
384 }
385
386
387 /** jd_udchg **/
388 int
jd_udchg(dic_no)389 jd_udchg (dic_no)
390 int dic_no;
391 {
392 WNN_DIC_INFO ret;
393
394 JD_WNN_DEAD if (js_dic_info (jl_env (buf), dic_no, &ret) < 0)
395 return (-1);
396 if (ret.type != WNN_UD_DICT && ret.type != WNN_REV_DICT)
397 {
398 wnn_errorno = WNN_NOT_A_UD;
399 return (-1);
400 }
401 else if (ret.rw != WNN_DIC_RW || ret.enablef != 1)
402 {
403 wnn_errorno = WNN_RDONLY;
404 return (-1);
405 }
406 current_ud = dic_no;
407 return (0);
408 }
409
410 /** jd_udp **/
411 int
jd_udp(dic_no)412 jd_udp (dic_no)
413 int dic_no;
414 {
415 WNN_DIC_INFO ret;
416 int rdonly = 0;
417
418 JD_WNN_DEAD if (js_dic_info (jl_env (buf), dic_no, &ret) < 0)
419 return (-1);
420 if (ret.rw == WNN_DIC_RDONLY || ret.enablef == 0)
421 rdonly |= 0x4;
422 if (ret.type == WNN_UD_DICT || (ret.type == WNN_REV_DICT && ret.rw == WNN_DIC_RW))
423 {
424 rdonly = 1;
425 if (current_ud == dic_no)
426 rdonly |= 0x2;
427 }
428
429 return (rdonly);
430 }
431
432 /** jd_freqsv **/
433 int
jd_freqsv()434 jd_freqsv ()
435 {
436 JD_WNN_DEAD return (jl_dic_save_all (buf));
437 }
438
439 /* JD word */
440
441 /** jd_whdel **/
442 int
jd_whdel(ser_no,yomi,bunpou)443 jd_whdel (ser_no, yomi, bunpou)
444 int ser_no, bunpou;
445 w_char *yomi;
446 {
447 JD_WNN_DEAD return (jl_word_delete (buf, current_ud, ser_no));
448 }
449
450
451 /** jd_wdel **/
452 int
jd_wdel(ser_no,yomi)453 jd_wdel (ser_no, yomi)
454 int ser_no;
455 w_char *yomi;
456 {
457 JD_WNN_DEAD return (jl_word_delete (buf, current_ud, ser_no));
458 }
459
460 static int oldh_to_newh ();
461
462 /** jd_wreg **/
463 int
jd_wreg(kanji,yomi,bunpo)464 jd_wreg (kanji, yomi, bunpo)
465 w_char *kanji, *yomi;
466 int bunpo;
467 {
468 #ifdef NEW_HINSI
469 return (jl_word_add (buf, current_ud, yomi, kanji, NULL, bunpo, 0));
470 #else
471 int i;
472 int ret = 0;
473 int hinsi_suu;
474 unsigned short *hinsi;
475
476 JD_WNN_DEAD
477 /* hinsi No conversion */
478 hinsi_suu = oldh_to_newh (bunpo, &hinsi);
479 for (i = 0; i < hinsi_suu; i++, hinsi++)
480 {
481 if (jl_word_add (buf, current_ud, yomi, kanji, NULL, *hinsi, 0))
482 {
483 ret = -1;
484 }
485 }
486 return (ret);
487 #endif
488 }
489
490 static int newh_to_oldh ();
491
492 /** jd_wsch **/
493 int
jd_wsch(yomi,jbuf,jbuf_siz,kbuf,kbuf_siz)494 jd_wsch (yomi, jbuf, jbuf_siz, kbuf, kbuf_siz)
495 w_char *yomi, *kbuf;
496 JISHOJOHO *jbuf;
497 int jbuf_siz, kbuf_siz;
498 {
499 register int i, klen;
500 register w_char *b;
501
502 struct wnn_jdata *jdp;
503 int len;
504 int cnt;
505
506 JD_WNN_DEAD if ((cnt = jl_word_search_by_env (buf, yomi, &jdp)) < 0)
507 return (-1);
508
509 if (cnt >= jbuf_siz - 1)
510 {
511 wnn_errorno = WNN_JISHOTABLE_FULL;
512 return (-1);
513 }
514 for (klen = 0, i = cnt, b = kbuf; i > 0; jbuf++, jdp++, i--)
515 {
516 jbuf->hindo = jdp->hindo;
517 #ifdef NEW_HINSI
518 jbuf->bumpo = jdp->hinshi;
519 #else /* hinsi No conversion */
520 jbuf->bumpo = newh_to_oldh (jdp->hinshi);
521 #endif
522 jbuf->jisho = jdp->dic_no;
523 jbuf->serial = jdp->serial;
524 jbuf->k_data = b;
525 len = wnn_Strlen (jdp->kanji) + 1;
526 klen += len;
527 if (klen >= kbuf_siz)
528 {
529 wnn_errorno = WNN_JISHOTABLE_FULL;
530 return (-1);
531 }
532 wnn_Strcpy (b, jdp->kanji);
533 b += len;
534 }
535 jbuf->hindo = -1;
536 return cnt;
537 }
538
539
540 /* Parameter set/get */
541 /** jd_setenvf **/
542 int
jd_setevf(bunsetsu_su,par1,par2,par3,par4,par5)543 jd_setevf (bunsetsu_su, par1, par2, par3, par4, par5)
544 int bunsetsu_su, par1, par2, par3, par4, par5;
545 {
546 struct wnn_param para;
547 int ret;
548
549 JD_WNN_DEAD ret = jl_param_get (buf, ¶);
550 if (ret < 0)
551 return (ret);
552 para.n = bunsetsu_su;
553 para.p1 = par1;
554 para.p2 = par2;
555 para.p3 = par3;
556 para.p4 = par4;
557 para.p5 = par5;
558 return (jl_param_set (buf, ¶));
559 }
560
561
562 /** jd_getenvf **/
563 int
jd_getevf(bunsetsu_su,par1,par2,par3,par4,par5)564 jd_getevf (bunsetsu_su, par1, par2, par3, par4, par5)
565 int *bunsetsu_su, *par1, *par2, *par3, *par4, *par5;
566 {
567 struct wnn_param para;
568 int ret;
569
570 JD_WNN_DEAD ret = jl_param_get (buf, ¶);
571 *bunsetsu_su = para.n;
572 *par1 = para.p1; /* ��������� */
573 *par2 = para.p2; /* ��ʸ��Ĺ */
574 *par3 = para.p3; /* ��Ω��Ĺ */
575 *par4 = para.p4; /* ���Ȥä���ӥå� */
576 *par5 = para.p5; /* ���� */
577 if (ret < 0);
578 return (ret);
579 }
580
581
582 /** jd_dicinfo **/
583 int
jd_dicinfo(jbuf,jbuf_siz,fbuf,fbuf_siz)584 jd_dicinfo (jbuf, jbuf_siz, fbuf, fbuf_siz)
585 DICINFO *jbuf;
586 int jbuf_siz;
587 char *fbuf;
588 int fbuf_siz;
589 {
590 register int i, klen;
591 register char *b;
592
593 WNN_DIC_INFO *dic;
594 int cnt, len;
595
596 JD_WNN_DEAD if ((cnt = js_dic_list (jl_env (buf), &ret_buf)) < 0)
597 return (-1);
598
599 if (cnt >= jbuf_siz - 1)
600 {
601 wnn_errorno = WNN_JISHOTABLE_FULL;
602 return (-1);
603 }
604 dic = (WNN_DIC_INFO *) ret_buf.buf;
605 for (klen = i = 0, b = fbuf; i < cnt; jbuf++, dic++, i++)
606 {
607 jbuf->dic_no = dic->dic_no;
608 jbuf->ttl_hindo = 0; /* ??? */
609 /*
610 jbuf->dic_type = dic->type;
611 */
612 if (dic->type == WNN_STATIC_DICT || (dic->type == WNN_REV_DICT && dic->rw == WNN_DIC_RDONLY))
613 jbuf->dic_type = SYSTEM_DIC;
614 else if (dic->type == WNN_UD_DICT || (dic->type == WNN_REV_DICT && dic->rw == WNN_DIC_RW))
615 jbuf->dic_type = USER_DIC;
616 jbuf->udp = jbuf->dic_no == current_ud ? 1 : 0;
617 jbuf->dic_size = dic->gosuu;
618 jbuf->prio = dic->nice;
619 jbuf->rdonly = dic->rw | !dic->enablef;
620 jbuf->file_name = b;
621 len = strlen (dic->fname) + 1;
622 klen += len;
623 if (klen >= fbuf_siz)
624 {
625 wnn_errorno = WNN_JISHOTABLE_FULL;
626 return (-1);
627 }
628 strcpy (b, dic->fname);
629 b += len;
630 jbuf->h_file_name = b;
631 len = strlen (dic->hfname) + 1;
632 klen += len;
633 if (klen >= fbuf_siz)
634 {
635 wnn_errorno = WNN_JISHOTABLE_FULL;
636 return (-1);
637 }
638 strcpy (b, dic->hfname);
639 b += len;
640 }
641 jbuf->dic_no = -1;
642 return i;
643 }
644
645
646 /** jd_open_in **/
647 struct bunjoho *
jd_open_in(kana_len,klist_len,kanji_len,server,user,host)648 jd_open_in (kana_len, klist_len, kanji_len, server, user, host)
649 int kana_len, klist_len, kanji_len;
650 char *server, *user, *host;
651 {
652 register int kasz, klsz, kjsz;
653 int cnt, i;
654 WNN_FILE_INFO_STRUCT *files;
655
656 if (jlib_work_area != NULL)
657 free (jlib_work_area);
658 jlib_work_area = NULL;
659
660 if (user == NULL || *user == '\0')
661 { /* ENV name */
662 user = getlogname ();
663 }
664
665 if ((buf = jl_open (user, server, NULL, WNN_NO_CREATE, NULL, 0)) == NULL)
666 return (NULL);
667 else if (buf->env == NULL)
668 return (NULL);
669 kasz = (sizeof (w_char) * (kana_len + 1) + 7) & 0xfffffff8;
670 klsz = (sizeof (KOUHO_ENT) * (klist_len + 1) + 7) & 0xfffffff8;
671 kjsz = (sizeof (w_char) * kanji_len + 7) & 0xfffffff8;
672 if (!(jlib_work_area = malloc (kasz + klsz + kjsz)))
673 {
674 wnn_errorno = WNN_MALLOC_INITIALIZE;
675 return 0;
676 }
677 bun.klist = (KOUHO_ENT *) jlib_work_area;
678 bun.klist_size = klist_len;
679 bun.kana_buf = (w_char *) (jlib_work_area + klsz);
680 bun.kana_size = kana_len;
681 bun.kanji_buf = (w_char *) (jlib_work_area + klsz + kasz);
682 bun.kanji_buf_size = kanji_len;
683
684 /* Don't override fuzokugo file if already exists */
685 if (js_fuzokugo_get (jl_env (buf)) >= 0)
686 {
687 return &bun;
688 }
689
690 if ((cnt = js_file_list_all (buf->env->js_id, &ret_buf)) <= 0)
691 return (NULL);
692 for (i = 0, files = (WNN_FILE_INFO_STRUCT *) ret_buf.buf; i < cnt; i++)
693 {
694 if (files->type == WNN_FT_FUZOKUGO_FILE)
695 break;
696 files++;
697 }
698 if (i == cnt)
699 return (NULL);
700 if (jl_fuzokugo_set (buf, files->name) == -1)
701 {
702 return (NULL);
703 }
704 return &bun;
705 }
706
707 /** jd_open **/
708 struct bunjoho *
jd_open(kana_len,klist_len,kanji_len)709 jd_open (kana_len, klist_len, kanji_len)
710 int kana_len, klist_len, kanji_len;
711 {
712 return (struct bunjoho *) jd_open_in (kana_len, klist_len, kanji_len, NULL, getlogname (), NULL);
713 }
714
715
716 /** jd_dicstatus **/
717 int
jd_dicstatus(fn)718 jd_dicstatus (fn)
719 char *fn;
720 {
721 WNN_FILE_STAT s;
722
723 JD_WNN_DEAD if (js_file_stat (jl_env (buf), fn, &s) < 0)
724 return (-1);
725 if (s.type == WNN_STATIC_DICT)
726 return (SYSTEM_DIC);
727 else if (s.type == WNN_UD_DICT || s.type == WNN_REV_DICT)
728 return (USER_DIC);
729 else if (s.type == WNN_FILE_NOT_EXIST)
730 return (NO_EXIST);
731 else
732 return (NOT_A_JISHO);
733 }
734
735 /** jd_mkdir **/
736 int
jd_mkdir(dn)737 jd_mkdir (dn)
738 char *dn;
739 {
740 JD_WNN_DEAD return (js_mkdir (jl_env (buf), dn));
741 }
742
743 /** jd_access **/
744 int
jd_access(dn,amode)745 jd_access (dn, amode)
746 char *dn;
747 int amode;
748 {
749 JD_WNN_DEAD return (js_access (jl_env (buf), dn, amode));
750 }
751
752 /** jd_who **/
753 int
jd_who(u,str)754 jd_who (u, str)
755 JWHO u[];
756 char *str;
757 {
758 register int i;
759 register int cnt;
760 WNN_JWHO *jwho;
761
762 JD_WNN_DEAD if ((cnt = js_who (jl_env (buf)->js_id, &ret_buf)) < 0)
763 return (-1);
764 jwho = (WNN_JWHO *) ret_buf.buf;
765 for (i = 0; i < cnt; i++, jwho++)
766 {
767 u[i].sd = jwho[0].sd;
768 u[i].user_name = str;
769 strcpy (str, jwho->user_name);
770 str += strlen (u[i].user_name) + 1;
771 u[i].host_name = str;
772 strcpy (str, jwho->host_name);
773 str += strlen (u[i].host_name) + 1;
774 }
775 u[i].sd = -1;
776 return (0);
777 }
778
779 /** jd_version **/
780 int
jd_version(serv,libv)781 jd_version (serv, libv)
782 int *serv, *libv;
783 {
784 JD_WNN_DEAD return (js_version (jl_env (buf)->js_id, serv, libv));
785 }
786
787 #ifndef NEW_HINSI
788 #define KOMEI 0x20000000
789 #define MEISI 0x00040000
790 #define JOSUU 0x04000000
791 #define SETTO 0x01000000
792 #define SETUBI 0x02000000
793 #define KEIYOU 0x00010000
794 #define KEIDOU 0x00020000
795 #define OLD_HINSI_SZ 32
796
797 static char *new_name[] = {
798 "���Ը���", "����(�Ԥ�)", "���Ը���", "���Ը���",
799 "���Ը���", "�ʹԸ���", "�йԸ���", "�Ը���",
800 "��Ը���", "��Ը���", "����&̾��", "����",
801 "����(����)&̾��", "����(����)", "����(����)", "��(��)",
802 "���ƻ�", "����ư��", "̾��", "Ϣ�λ�",
803 "����", "��³��,��ư��", "��(��)", "��(��)",
804 "��Ƭ��", "������", "������", "����",
805 "���(������)", "��ͭ̾��", "����ư��(����)", "ñ����"
806 };
807 /*
808 :��(��):��(��):��(��)
809 */
810
811
812 #define KOMEI_SZ 3 /* "��ͭ̾��" */
813 static char *komei_name[] = { "��̾", "��̾", "��̾&��̾" };
814
815 #define MEISI_SZ 1 /* "̾��" */
816 static char *meisi_name[] = { "����ư��&̾��" };
817
818 #define JOSUU_SZ 2 /* "������" */
819 static char *josuu_name[] = { "��Ƭ������", "����������" };
820
821 #define SETTO_SZ 7 /* "��Ƭ��" */
822 static char *setto_name[] = { "��Ƭ�줪", "��Ƭ����", "��Ƭ��̾",
823 "���ƻ첽����ư��", "����ư��", "����(����)&̾�첽������",
824 "����ư�첽������"
825 };
826
827 #define SETUBI_SZ 4 /* "������" */
828 static char *setubi_name[] = {
829 "������̾", "������̾", "������̾", "��������(����)����̾̾��"
830 };
831
832 #define DOUSI_SZ 15
833 static char *dousi_name[] = {
834 "��ư��", "", "��ư��", "��ư��",
835 "��ư��", "��ư��", "��ư��", "��ư��",
836 "��ư��", "��ư��", "", "��ư��",
837 "", "����ư��", "����ư��"
838 };
839
840 static char *dou_renyou_name[] = {
841 "��ưϢ�Ѵ�", "", "��ưϢ�Ѵ�", "��ưϢ�Ѵ�",
842 "��ưϢ�Ѵ�", "��ưϢ�Ѵ�", "��ưϢ�Ѵ�", "��ưϢ�Ѵ�",
843 "��ưϢ�Ѵ�", "��ưϢ�Ѵ�", "", "��ưϢ�Ѵ�",
844 "", "����ưϢ�Ѵ�", "����ưϢ�Ѵ�"
845 };
846
847 static int
oldh_to_newh(hinsi,new)848 oldh_to_newh (hinsi, new)
849 int hinsi;
850 unsigned short **new;
851 {
852 register int i, j;
853 static unsigned short tmp[OLD_HINSI_SZ + 1];
854 register int tmptmp; /* H.T. to compile PCC */
855
856 for (i = j = 0; hinsi != 0 && i < OLD_HINSI_SZ; i++)
857 {
858 if ((hinsi & 0x01) != 0)
859 {
860 /* if((tmptmp = wnn_find_hinsi_by_name(new_name[i])) != -1){ */
861 wnn_Sstrcpy (wchartmp, new_name[i]);
862 if ((tmptmp = jl_hinsi_number (buf, wchartmp)) != -1)
863 {
864 tmp[j] = tmptmp;
865 j++;
866 }
867 else
868 {
869 tmp[j] = tmptmp;
870 }
871
872 /* H.T. unsigned short comparison with -1
873 if ((tmp[j] = wnn_find_hinsi_by_name(new_name[i])) != -1)
874 j++;
875 */
876 }
877 hinsi >>= 1;
878 }
879
880 tmp[j] = -1;
881 *new = tmp;
882 return (j);
883 }
884
885 static int
newh_to_oldh(hinsi)886 newh_to_oldh (hinsi)
887 unsigned short hinsi;
888 {
889 register char *new_n;
890 register w_char *wnew_n;
891 register int i;
892
893 /* if ((new_n = wnn_get_hinsi_name(hinsi)) == 0) */
894 if ((wnew_n = jl_hinsi_name (buf, hinsi)) == 0)
895 return (-1);
896 wnn_sStrcpy (chartmp, wnew_n);
897 new_n = chartmp;
898 for (i = 0; i < OLD_HINSI_SZ; i++)
899 {
900 if (strcmp (new_n, new_name[i]) == 0)
901 return (0x1 << i);
902 }
903
904 for (i = 0; i < DOUSI_SZ; i++)
905 {
906 if (strcmp (new_n, dousi_name[i]) == 0)
907 return (0x1 << i);
908 }
909 for (i = 0; i < DOUSI_SZ; i++)
910 {
911 if (strcmp (new_n, dou_renyou_name[i]) == 0)
912 {
913 /* return(wnn_find_hinsi_by_name(new_name[i])); */
914 wnn_Sstrcpy (wchartmp, new_name[i]);
915 return (jl_hinsi_number (buf, wchartmp));
916 }
917 }
918
919 for (i = 0; i < KOMEI_SZ; i++)
920 {
921 if (strcmp (new_n, komei_name[i]) == 0)
922 return (KOMEI);
923 }
924 for (i = 0; i < MEISI_SZ; i++)
925 {
926 if (strcmp (new_n, meisi_name[i]) == 0)
927 return (MEISI);
928 }
929 for (i = 0; i < JOSUU_SZ; i++)
930 {
931 if (strcmp (new_n, josuu_name[i]) == 0)
932 return (JOSUU);
933 }
934 for (i = 0; i < SETTO_SZ; i++)
935 {
936 if (strcmp (new_n, setto_name[i]) == 0)
937 return (SETTO);
938 }
939 for (i = 0; i < SETUBI_SZ; i++)
940 {
941 if (strcmp (new_n, setubi_name[i]) == 0)
942 return (SETUBI);
943 }
944 return (0);
945 }
946 #endif /* ! NEWHINSI */
947