Mercurial > freewnn
comparison Wnn/jlib/jl.c @ 0:bbc77ca4def5
initial import
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Thu, 13 Dec 2007 04:30:14 +0900 |
parents | |
children | 790205f476c0 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bbc77ca4def5 |
---|---|
1 /* | |
2 * $Id: jl.c,v 1.14 2005/04/10 15:26:37 aonoto 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, 2003 | |
14 * | |
15 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp> | |
16 * | |
17 * This library is free software; you can redistribute it and/or | |
18 * modify it under the terms of the GNU Lesser General Public | |
19 * License as published by the Free Software Foundation; either | |
20 * version 2 of the License, or (at your option) any later version. | |
21 * | |
22 * This library 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 GNU | |
25 * Lesser General Public License for more details. | |
26 * | |
27 * You should have received a copy of the GNU Lesser General Public | |
28 * License along with this library; if not, write to the | |
29 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
30 * Boston, MA 02111-1307, USA. | |
31 */ | |
32 | |
33 /* | |
34 Nihongo Henkan Hi-level Library | |
35 */ | |
36 | |
37 #if defined(HAVE_CONFIG_H) | |
38 #include <config.h> | |
39 #endif | |
40 | |
41 #include <stdio.h> | |
42 #include <ctype.h> | |
43 #include <time.h> | |
44 #if STDC_HEADERS | |
45 # include <stdlib.h> | |
46 # include <string.h> | |
47 #else | |
48 # if HAVE_STRINGS_H | |
49 # include <strings.h> | |
50 # endif | |
51 # if HAVE_MALLOC_H | |
52 # include <malloc.h> | |
53 # endif | |
54 #endif /* STDC_HEADERS */ | |
55 #include <sys/types.h> | |
56 #include <sys/file.h> | |
57 #include <sys/stat.h> | |
58 #if HAVE_UNISTD_H | |
59 # include <unistd.h> | |
60 #endif | |
61 #include <pwd.h> | |
62 | |
63 #include "commonhd.h" | |
64 #include "wnn_config.h" | |
65 #include "wnnerror.h" | |
66 #include "jd_sock.h" | |
67 #include "jslib.h" | |
68 #include "jllib.h" | |
69 #include "msg.h" | |
70 #include "wnn_string.h" | |
71 #include "wnn_os.h" | |
72 | |
73 extern struct msg_cat *wnn_msg_cat; | |
74 | |
75 | |
76 #define MAXENVS 32 | |
77 | |
78 #define MAXINCLUDE 10 | |
79 | |
80 #define DEFAULT_BUN_LEN 3 | |
81 | |
82 #define DEFAULT_ZENKOUHO_LEN 3 | |
83 | |
84 #define DEFAULT_HEAP_LEN 3 | |
85 | |
86 #define INCREMENT 2 | |
87 | |
88 #define SHO 0 | |
89 #define DAI 1 | |
90 | |
91 #define BUN 0 | |
92 #define ZENKOUHO 1 /* Must not change!, they are assigned to two bit flag */ | |
93 #define ZENKOUHO_DAI 3 /* DAI << 1 | ZENKOUHO */ | |
94 | |
95 #define if_dead_disconnect(env, ret) \ | |
96 { \ | |
97 if (wnn_errorno == WNN_JSERVER_DEAD) { \ | |
98 jl_disconnect_if_server_dead(env);\ | |
99 return(ret); \ | |
100 } else { \ | |
101 return(ret); \ | |
102 } \ | |
103 } | |
104 | |
105 #define if_dead_disconnect_b(buf, ret) \ | |
106 { \ | |
107 if (wnn_errorno == WNN_JSERVER_DEAD) { \ | |
108 jl_disconnect_if_server_dead(buf->env);\ | |
109 buf->env = 0; \ | |
110 return(ret); \ | |
111 } else { \ | |
112 return(ret); \ | |
113 } \ | |
114 } | |
115 | |
116 static struct wnn_ret_buf rb = { 0, NULL }; | |
117 static struct wnn_ret_buf dicrb = { 0, NULL }; | |
118 static struct wnn_ret_buf wordrb = { 0, NULL }; | |
119 | |
120 static int dumbhinsi; | |
121 static w_char *mae_fzk; | |
122 static int syuutanv; | |
123 static int syuutanv1; | |
124 | |
125 #define CONFIRM 1 | |
126 #define CONFIRM1 2 | |
127 #define CREATE_WITHOUT_CONFIRM 3 | |
128 #define NO_CREATE 4 | |
129 | |
130 int confirm_state; | |
131 | |
132 static void add_down_bnst (); | |
133 static int alloc_heap (); | |
134 static int call_error_handler (); | |
135 static int change_ascii_to_int (); | |
136 static int create_file (); | |
137 static int dai_end (); | |
138 static int expand_expr (); | |
139 static int expand_expr_all (); | |
140 static int file_discard (); | |
141 static int file_exist (); | |
142 static int file_read (); | |
143 static int file_remove (); | |
144 static int find_same_kouho (); | |
145 static int find_same_kouho_dai (); | |
146 static void free_bun (); | |
147 static void free_down (); | |
148 static void free_sho (); | |
149 static void free_zenkouho (); | |
150 static int get_c_jikouho (); | |
151 static int get_c_jikouho_dai (); | |
152 static int get_c_jikouho_from_zenkouho (); | |
153 static int get_c_jikouho_from_zenkouho_dai (); | |
154 static int get_pwd (); | |
155 static int insert_dai (); | |
156 static int insert_sho (); | |
157 static int make_dir1 (); | |
158 static int make_dir_rec1 (); | |
159 static void make_space_for (); | |
160 static void make_space_for_bun (); | |
161 static void make_space_for_zenkouho (); | |
162 static void message_out (); | |
163 static int ren_conv1 (); | |
164 static void set_dai (); | |
165 static void set_sho (); | |
166 static int tan_conv1 (); | |
167 | |
168 /* | |
169 * Sub-routines to handle files, enviroments and connections. | |
170 */ | |
171 | |
172 struct wnn_file_name_id | |
173 { | |
174 struct wnn_file_name_id *next; | |
175 int id; | |
176 char name[1]; | |
177 }; | |
178 | |
179 struct wnn_jl_env | |
180 { | |
181 WNN_JSERVER_ID *js; | |
182 struct wnn_env *env; | |
183 char env_n[WNN_ENVNAME_LEN]; | |
184 char server_n[WNN_HOSTLEN]; | |
185 char lang[32]; | |
186 int ref_cnt; | |
187 struct wnn_file_name_id *file; | |
188 } | |
189 envs[MAXENVS]; | |
190 | |
191 /* | |
192 * File management routines. | |
193 */ | |
194 | |
195 static struct wnn_jl_env * | |
196 find_jl_env (env) | |
197 register struct wnn_env *env; | |
198 { | |
199 register int k; | |
200 for (k = 0; k < MAXENVS; k++) | |
201 { | |
202 if (envs[k].env == env) | |
203 return (envs + k); | |
204 } | |
205 return (NULL); | |
206 } | |
207 | |
208 | |
209 static struct wnn_env * | |
210 find_env_of_same_js_id (js_id) | |
211 register WNN_JSERVER_ID *js_id; | |
212 { | |
213 register int k; | |
214 | |
215 for (k = 0; k < MAXENVS; k++) | |
216 { | |
217 if (envs[k].js == js_id) | |
218 { | |
219 return (envs[k].env); | |
220 } | |
221 } | |
222 return (NULL); | |
223 } | |
224 | |
225 static WNN_JSERVER_ID * | |
226 find_same_server (server_n, lang) | |
227 register char *server_n, *lang; | |
228 { | |
229 register int k; | |
230 | |
231 if (server_n == NULL || lang == NULL) | |
232 return (NULL); | |
233 for (k = 0; k < MAXENVS; k++) | |
234 { | |
235 if (strncmp (envs[k].server_n, server_n, WNN_HOSTLEN - 1) == 0 && strcmp (envs[k].lang, lang) == 0) | |
236 { | |
237 return (envs[k].js); | |
238 } | |
239 } | |
240 return (NULL); | |
241 } | |
242 | |
243 static int | |
244 find_same_server_from_id (js) | |
245 register WNN_JSERVER_ID *js; | |
246 { | |
247 register int k; | |
248 for (k = 0; k < MAXENVS; k++) | |
249 { | |
250 if (envs[k].js == js) | |
251 return (1); | |
252 } | |
253 return (0); | |
254 } | |
255 | |
256 #ifdef nodef | |
257 static | |
258 delete_server_from_id (js) | |
259 WNN_JSERVER_ID *js; | |
260 { | |
261 int k; | |
262 for (k = 0; k < MAXENVS; k++) | |
263 { | |
264 if (envs[k].js == js) | |
265 { | |
266 envs[k].js = 0; | |
267 strcpy (envs[k].server_n, ""); | |
268 break; | |
269 } | |
270 } | |
271 } | |
272 #endif | |
273 | |
274 | |
275 static struct wnn_env * | |
276 find_same_env (js, env_n, lang) | |
277 register WNN_JSERVER_ID *js; | |
278 register char *env_n; | |
279 char *lang; | |
280 { | |
281 register int k; | |
282 | |
283 if (env_n == NULL || lang == NULL) | |
284 return (NULL); | |
285 for (k = 0; k < MAXENVS; k++) | |
286 { | |
287 if (envs[k].js == js && strcmp (envs[k].env_n, env_n) == 0 && strcmp (envs[k].lang, lang) == 0) | |
288 { | |
289 envs[k].ref_cnt++; | |
290 return (envs[k].env); | |
291 } | |
292 } | |
293 return (NULL); | |
294 } | |
295 | |
296 static char * | |
297 env_name (env) | |
298 register struct wnn_env *env; | |
299 { | |
300 register int k; | |
301 | |
302 for (k = 0; k < MAXENVS; k++) | |
303 { | |
304 if (envs[k].env == env) | |
305 { | |
306 return (envs[k].env_n); | |
307 } | |
308 } | |
309 return (NULL); | |
310 } | |
311 | |
312 | |
313 static void | |
314 add_new_env (js, env, env_n, server_n, lang) | |
315 register WNN_JSERVER_ID *js; | |
316 register struct wnn_env *env; | |
317 char *env_n, *server_n, *lang; | |
318 { | |
319 register int k; | |
320 | |
321 for (k = 0; k < MAXENVS; k++) | |
322 { | |
323 if (envs[k].ref_cnt == 0) | |
324 { | |
325 strncpy (envs[k].server_n, server_n, WNN_HOSTLEN - 1); | |
326 envs[k].server_n[WNN_HOSTLEN - 1] = '\0'; | |
327 strcpy (envs[k].env_n, env_n); | |
328 strcpy (envs[k].lang, lang); | |
329 envs[k].js = js; | |
330 envs[k].env = env; | |
331 envs[k].ref_cnt = 1; | |
332 envs[k].file = NULL; | |
333 break; | |
334 } | |
335 } | |
336 } | |
337 | |
338 static int | |
339 delete_env (env) | |
340 register struct wnn_env *env; | |
341 { | |
342 register int k; | |
343 | |
344 for (k = 0; k < MAXENVS; k++) | |
345 { | |
346 if (envs[k].env == env) | |
347 { | |
348 if (--envs[k].ref_cnt == 0) | |
349 { | |
350 strcpy (envs[k].server_n, ""); | |
351 strcpy (envs[k].env_n, ""); | |
352 strcpy (envs[k].lang, ""); | |
353 envs[k].js = NULL; | |
354 envs[k].env = NULL; | |
355 return (1); /* Need To delete env */ | |
356 } | |
357 else | |
358 { | |
359 return (0); /* Need not to delete env */ | |
360 } | |
361 } | |
362 } | |
363 return (-1); /* This must not happen */ | |
364 } | |
365 | |
366 | |
367 /* Routines to manipulate files */ | |
368 | |
369 static int | |
370 add_file_to_env (env, id, name) | |
371 struct wnn_env *env; | |
372 int id; | |
373 register char *name; | |
374 { | |
375 register struct wnn_file_name_id *f, *f1; | |
376 if ((f = (struct wnn_file_name_id *) malloc (sizeof (struct wnn_file_name_id) + strlen (name) + 1)) == NULL) | |
377 { | |
378 wnn_errorno = WNN_ALLOC_FAIL; | |
379 return (-1); | |
380 } | |
381 strcpy (f->name, name); | |
382 f->id = id; | |
383 f1 = find_jl_env (env)->file; | |
384 f->next = f1; | |
385 find_jl_env (env)->file = f; | |
386 return (0); | |
387 } | |
388 | |
389 static char * | |
390 find_file_name_from_id (env, id) | |
391 struct wnn_env *env; | |
392 register int id; | |
393 { | |
394 register struct wnn_file_name_id *f; | |
395 f = find_jl_env (env)->file; | |
396 for (; f; f = f->next) | |
397 { | |
398 if (f->id == id) | |
399 { | |
400 return (f->name); | |
401 } | |
402 } | |
403 /* wnn_errorno=WNN_FILE_NOT_READ_FROM_CLIENT; */ | |
404 return (NULL); | |
405 } | |
406 | |
407 static int | |
408 delete_file_from_env (env, id) | |
409 struct wnn_env *env; | |
410 register int id; | |
411 { | |
412 struct wnn_file_name_id *f; | |
413 register struct wnn_file_name_id **prev; | |
414 register struct wnn_jl_env *jl_env_p; | |
415 | |
416 jl_env_p = find_jl_env (env); | |
417 if (!jl_env_p->file) | |
418 return (0); | |
419 for (prev = &jl_env_p->file; f = *prev; prev = &f->next) | |
420 { | |
421 if (f->id == id) | |
422 { | |
423 *prev = f->next; | |
424 free (f); | |
425 return (0); | |
426 } | |
427 } | |
428 wnn_errorno = WNN_FILE_NOT_READ_FROM_CLIENT; | |
429 return (-1); | |
430 } | |
431 | |
432 /* | |
433 * Libraries which handle Connection To Jserver | |
434 */ | |
435 | |
436 struct wnn_env * | |
437 jl_connect_lang (env_n, server_n, lang, wnnrc_n, error_handler, message_handler, timeout) | |
438 register char *env_n, *server_n, *wnnrc_n, *lang; | |
439 int (*error_handler) (), (*message_handler) (); | |
440 int timeout; | |
441 { | |
442 register WNN_JSERVER_ID *js = NULL; | |
443 struct wnn_env *env; | |
444 int env_exist; | |
445 char p_lang[16]; | |
446 register char *p, *l; | |
447 extern char *getenv (); | |
448 extern char *_wnn_get_machine_of_serv_defs (); | |
449 | |
450 wnn_errorno = 0; | |
451 /* if lang not specified use $LANG */ | |
452 if (!lang || !*lang) | |
453 { | |
454 lang = getenv ("LANG"); | |
455 } | |
456 if (!lang || !*lang) | |
457 { | |
458 /* Sorry! Default is Japanese. :-) */ | |
459 strcpy (p_lang, "ja_JP"); | |
460 } | |
461 else | |
462 { | |
463 /* Use only [language]_[teritorry] */ | |
464 for (p = p_lang, l = lang; *l != '@' && *l != '.' && *l != 0; p++, l++) | |
465 *p = *l; | |
466 *p = 0; | |
467 } | |
468 | |
469 /* To See serverdefs file when server_n is not specified. */ | |
470 if (!server_n || !*server_n) | |
471 { | |
472 /* find server machine name from table by lang */ | |
473 if (server_n = _wnn_get_machine_of_serv_defs (p_lang)) | |
474 { | |
475 if ((js = find_same_server (server_n, p_lang)) == NULL) | |
476 { | |
477 if ((js = js_open_lang (server_n, p_lang, timeout)) == NULL) | |
478 { | |
479 server_n = NULL; | |
480 } | |
481 } | |
482 } | |
483 if (!server_n || !*server_n) | |
484 { | |
485 server_n = "unix"; | |
486 } | |
487 } | |
488 | |
489 if (js == NULL) | |
490 { | |
491 if ((js = find_same_server (server_n, p_lang)) == NULL) | |
492 { | |
493 if ((js = js_open_lang (server_n, p_lang, timeout)) == NULL) | |
494 { | |
495 return (NULL); | |
496 } | |
497 /* js_hinsi_list(js); */ | |
498 } | |
499 } | |
500 if ((env_exist = js_env_exist (js, env_n)) < 0) | |
501 return (NULL); | |
502 if ((env = find_same_env (js, env_n, p_lang)) == NULL) | |
503 { /* Incr ref_cnt */ | |
504 if ((env = js_connect_lang (js, env_n, p_lang)) == NULL) | |
505 { | |
506 return (NULL); | |
507 } | |
508 add_new_env (js, env, env_n, server_n, p_lang); | |
509 } | |
510 if (env_exist == 0 && wnnrc_n) | |
511 { | |
512 jl_set_env_wnnrc (env, wnnrc_n, error_handler, message_handler); | |
513 } | |
514 return (env); | |
515 } | |
516 | |
517 void | |
518 jl_disconnect (env) | |
519 register struct wnn_env *env; | |
520 { | |
521 int ret; | |
522 wnn_errorno = 0; | |
523 if ((ret = delete_env (env)) < 0) | |
524 { | |
525 return; | |
526 } | |
527 else if (ret) | |
528 { | |
529 js_disconnect (env); | |
530 } | |
531 if (!find_same_server_from_id (env->js_id)) | |
532 { | |
533 js_close (env->js_id); | |
534 env->js_id = 0; | |
535 } | |
536 } | |
537 | |
538 int | |
539 jl_isconnect_e (env) | |
540 register struct wnn_env *env; | |
541 { | |
542 if (js_isconnect (env) == 0) | |
543 return (1); | |
544 else | |
545 return (0); | |
546 } | |
547 | |
548 /* JSERVER が死んだら env を disconnect して回る */ | |
549 void | |
550 jl_disconnect_if_server_dead (env) | |
551 register struct wnn_env *env; | |
552 { | |
553 register struct wnn_env *same_env; | |
554 int ret; | |
555 | |
556 if ((ret = delete_env (env)) < 0) | |
557 { | |
558 return; | |
559 } | |
560 else if (ret) | |
561 { | |
562 js_disconnect (env); | |
563 } | |
564 while ((same_env = find_env_of_same_js_id (env->js_id)) != 0) | |
565 { | |
566 if (delete_env (same_env)) | |
567 { | |
568 js_disconnect (same_env); | |
569 } | |
570 | |
571 } | |
572 js_close (env->js_id); | |
573 env->js_id = 0; | |
574 } | |
575 | |
576 | |
577 struct wnn_buf * | |
578 jl_open_lang (env_n, server_n, lang, wnnrc_n, error_handler, message_handler, timeout) | |
579 char *env_n, *server_n, *wnnrc_n, *lang; | |
580 int (*error_handler) (), (*message_handler) (); | |
581 int timeout; | |
582 { | |
583 register int k, dmy; | |
584 register struct wnn_buf *buf; | |
585 struct wnn_env *env; | |
586 | |
587 wnn_errorno = 0; | |
588 if (rb.size == 0) | |
589 rb.buf = (char *) malloc ((unsigned) (rb.size = 1024)); | |
590 | |
591 #define ALLOC_SET(pter, type, size, size_var) \ | |
592 ((pter) = ((type *)malloc((unsigned)(sizeof(type) * ((size_var) = (size)))))) | |
593 | |
594 if (!ALLOC_SET (buf, struct wnn_buf, 1, dmy)) | |
595 { | |
596 wnn_errorno = WNN_ALLOC_FAIL; | |
597 return NULL; | |
598 } | |
599 | |
600 buf->bun_suu = 0; | |
601 buf->zenkouho_suu = 0; | |
602 buf->zenkouho_daip = 0; | |
603 buf->c_zenkouho = -1; | |
604 buf->zenkouho_bun = -1; | |
605 buf->zenkouho_end_bun = -1; | |
606 buf->free_heap = NULL; | |
607 buf->heap = NULL; | |
608 buf->zenkouho_dai_suu = 0; | |
609 | |
610 if (!ALLOC_SET (buf->bun, WNN_BUN *, DEFAULT_BUN_LEN, buf->msize_bun) || | |
611 !ALLOC_SET (buf->zenkouho_dai, int, DEFAULT_ZENKOUHO_LEN + 1, buf->msize_zenkouho) || | |
612 !ALLOC_SET (buf->zenkouho, WNN_BUN *, DEFAULT_ZENKOUHO_LEN, buf->msize_zenkouho) || !ALLOC_SET (buf->down_bnst, WNN_BUN *, DEFAULT_BUN_LEN, buf->msize_bun)) | |
613 { | |
614 wnn_errorno = WNN_ALLOC_FAIL; | |
615 return NULL; | |
616 } | |
617 | |
618 for (k = 0; k < DEFAULT_BUN_LEN; k++) | |
619 { | |
620 buf->down_bnst[k] = NULL; | |
621 } | |
622 | |
623 if (alloc_heap (buf, DEFAULT_HEAP_LEN) == -1) | |
624 { | |
625 return NULL; | |
626 } | |
627 | |
628 env = jl_connect_lang (env_n, server_n, lang, wnnrc_n, error_handler, message_handler, timeout); | |
629 buf->env = env; | |
630 return (buf); | |
631 } | |
632 | |
633 | |
634 static int | |
635 alloc_heap (buf, len) | |
636 struct wnn_buf *buf; | |
637 register int len; | |
638 { | |
639 char **c; | |
640 register WNN_BUN *d; | |
641 | |
642 if ((c = (char **) malloc ((unsigned) (len * sizeof (WNN_BUN) + sizeof (char *)))) == NULL) | |
643 { | |
644 wnn_errorno = WNN_ALLOC_FAIL; | |
645 return (-1); | |
646 } | |
647 | |
648 *c = buf->heap; | |
649 buf->heap = (char *) c; | |
650 d = (WNN_BUN *) (c + 1); | |
651 for (--len; len > 0; len--, d++) | |
652 { | |
653 d->free_next = d + 1; | |
654 } | |
655 d->free_next = buf->free_heap; | |
656 buf->free_heap = (WNN_BUN *) (c + 1); | |
657 return (0); | |
658 } | |
659 | |
660 void | |
661 jl_close (buf) | |
662 register struct wnn_buf *buf; | |
663 { | |
664 register char *c, *next; | |
665 | |
666 wnn_errorno = 0; | |
667 if (buf == NULL) | |
668 return; | |
669 | |
670 if (buf->env) | |
671 { | |
672 jl_disconnect (buf->env); | |
673 buf->env = 0; | |
674 } | |
675 | |
676 if (buf->bun) | |
677 free ((char *) buf->bun); | |
678 if (buf->zenkouho) | |
679 free ((char *) buf->zenkouho); | |
680 if (buf->zenkouho_dai) | |
681 free ((char *) buf->zenkouho_dai); | |
682 if (buf->down_bnst) | |
683 free ((char *) buf->down_bnst); | |
684 for (c = buf->heap; c; c = next) | |
685 { | |
686 next = *(char **) c; | |
687 free (c); | |
688 } | |
689 free ((char *) buf); | |
690 } | |
691 | |
692 /* | |
693 * Conversion Libraries | |
694 */ | |
695 | |
696 int | |
697 jl_ren_conv (buf, yomi, bun_no, bun_no2, use_maep) | |
698 register struct wnn_buf *buf; | |
699 register w_char *yomi; | |
700 int bun_no, bun_no2; | |
701 int use_maep; | |
702 { | |
703 wnn_errorno = 0; | |
704 if (bun_no < 0) | |
705 return (-1); | |
706 if (bun_no2 >= buf->bun_suu || bun_no2 < 0) | |
707 bun_no2 = buf->bun_suu; | |
708 free_down (buf, bun_no, bun_no2); | |
709 return (ren_conv1 (buf, yomi, bun_no, bun_no2, use_maep)); | |
710 } | |
711 | |
712 static int | |
713 ren_conv1 (buf, yomi, bun_no, bun_no2, use_maep) | |
714 register struct wnn_buf *buf; | |
715 w_char *yomi; | |
716 register int bun_no, bun_no2; | |
717 int use_maep; | |
718 { | |
719 int dcnt; | |
720 struct wnn_dai_bunsetsu *dp; | |
721 int size; | |
722 w_char yomi1[LENGTHBUNSETSU]; | |
723 | |
724 | |
725 if (yomi == NULL || *yomi == (w_char) 0) | |
726 return (0); | |
727 if (bun_no2 >= buf->bun_suu || bun_no2 < 0) | |
728 bun_no2 = buf->bun_suu; | |
729 | |
730 if (use_maep & WNN_USE_MAE && bun_no > 0) | |
731 { | |
732 dumbhinsi = buf->bun[bun_no - 1]->hinsi; | |
733 jl_get_yomi (buf, bun_no - 1, bun_no, yomi1); | |
734 mae_fzk = yomi1 + buf->bun[bun_no - 1]->jirilen; | |
735 } | |
736 else | |
737 { | |
738 dumbhinsi = WNN_BUN_SENTOU; | |
739 mae_fzk = (w_char *) 0; | |
740 } | |
741 if (use_maep & WNN_USE_ATO && bun_no2 < buf->bun_suu) | |
742 { | |
743 syuutanv = buf->bun[bun_no2]->kangovect; | |
744 syuutanv1 = WNN_VECT_KANREN; | |
745 } | |
746 else | |
747 { | |
748 syuutanv = WNN_VECT_KANREN; | |
749 syuutanv1 = WNN_VECT_NO; | |
750 if (bun_no2 < buf->bun_suu) | |
751 { | |
752 buf->bun[bun_no2]->dai_top = 1; | |
753 } | |
754 } | |
755 if ((dcnt = js_kanren (buf->env, yomi, dumbhinsi, mae_fzk, syuutanv, syuutanv1, WNN_VECT_BUNSETSU, &rb)) < 0) | |
756 { | |
757 if_dead_disconnect_b (buf, -1); | |
758 } | |
759 | |
760 dp = (struct wnn_dai_bunsetsu *) rb.buf; | |
761 | |
762 free_bun (buf, bun_no, bun_no2); | |
763 | |
764 if (use_maep & WNN_USE_ATO && bun_no2 < buf->bun_suu) | |
765 { | |
766 buf->bun[bun_no2]->dai_top = (dp[dcnt - 1].sbn[dp[dcnt - 1].sbncnt - 1].status_bkwd == WNN_CONNECT_BK) ? 0 : 1; | |
767 } | |
768 | |
769 size = insert_dai (buf, BUN, bun_no, bun_no2, dp, dcnt, 0); | |
770 if (buf->zenkouho_end_bun > bun_no && buf->zenkouho_bun < bun_no2) | |
771 { | |
772 free_zenkouho (buf); | |
773 } | |
774 else if (buf->zenkouho_bun >= bun_no2) | |
775 { | |
776 buf->zenkouho_bun += size - bun_no2; | |
777 buf->zenkouho_end_bun += size - bun_no2; | |
778 | |
779 } | |
780 return (buf->bun_suu); | |
781 } | |
782 | |
783 int | |
784 jl_tan_conv (buf, yomi, bun_no, bun_no2, use_maep, ich_shop) | |
785 register struct wnn_buf *buf; | |
786 w_char *yomi; | |
787 register int bun_no, bun_no2; | |
788 int use_maep, ich_shop; | |
789 { | |
790 wnn_errorno = 0; | |
791 if (bun_no < 0) | |
792 return (-1); | |
793 if (bun_no2 >= buf->bun_suu || bun_no2 < 0) | |
794 bun_no2 = buf->bun_suu; | |
795 free_down (buf, bun_no, bun_no2); | |
796 if (tan_conv1 (buf, yomi, bun_no, bun_no2, use_maep, ich_shop) == -1) | |
797 return (-1); | |
798 return (buf->bun_suu); | |
799 } | |
800 | |
801 static int | |
802 tan_conv1 (buf, yomi, bun_no, bun_no2, use_maep, ich_shop) | |
803 register struct wnn_buf *buf; | |
804 w_char *yomi; | |
805 register int bun_no, bun_no2; | |
806 int use_maep, ich_shop; | |
807 { | |
808 int dcnt; | |
809 struct wnn_dai_bunsetsu *dp; | |
810 struct wnn_sho_bunsetsu *sp; | |
811 int ret; | |
812 w_char yomi1[LENGTHBUNSETSU]; | |
813 | |
814 if (yomi == NULL || *yomi == (w_char) 0) | |
815 return (0); | |
816 if (bun_no2 >= buf->bun_suu || bun_no2 < 0) | |
817 bun_no2 = buf->bun_suu; | |
818 | |
819 if (use_maep & WNN_USE_MAE && bun_no > 0) | |
820 { | |
821 dumbhinsi = buf->bun[bun_no - 1]->hinsi; | |
822 jl_get_yomi (buf, bun_no - 1, bun_no, yomi1); | |
823 mae_fzk = yomi1 + buf->bun[bun_no - 1]->jirilen; | |
824 } | |
825 else | |
826 { | |
827 dumbhinsi = WNN_BUN_SENTOU; | |
828 mae_fzk = (w_char *) 0; | |
829 } | |
830 if (use_maep & WNN_USE_ATO && bun_no2 < buf->bun_suu) | |
831 { | |
832 syuutanv = buf->bun[bun_no2]->kangovect; | |
833 syuutanv1 = WNN_VECT_KANTAN; | |
834 } | |
835 else | |
836 { | |
837 syuutanv = WNN_VECT_KANTAN; | |
838 syuutanv1 = WNN_VECT_NO; | |
839 if (bun_no2 < buf->bun_suu) | |
840 { | |
841 buf->bun[bun_no2]->dai_top = 1; | |
842 } | |
843 } | |
844 if (ich_shop == WNN_SHO) | |
845 { | |
846 if ((dcnt = js_kantan_sho (buf->env, yomi, dumbhinsi, mae_fzk, syuutanv, syuutanv1, &rb)) < 0) | |
847 { | |
848 if_dead_disconnect_b (buf, -1); | |
849 } | |
850 sp = (struct wnn_sho_bunsetsu *) rb.buf; | |
851 if (use_maep & WNN_USE_ATO && bun_no2 < buf->bun_suu) | |
852 { | |
853 buf->bun[bun_no2]->dai_top = (sp[dcnt - 1].status_bkwd == WNN_CONNECT_BK) ? 0 : 1; | |
854 } | |
855 free_bun (buf, bun_no, bun_no2); | |
856 ret = insert_sho (buf, BUN, bun_no, bun_no2, sp, dcnt, 0); | |
857 } | |
858 else | |
859 { | |
860 if ((dcnt = js_kantan_dai (buf->env, yomi, dumbhinsi, mae_fzk, syuutanv, syuutanv1, &rb)) < 0) | |
861 { | |
862 if_dead_disconnect_b (buf, -1); | |
863 } | |
864 dp = (struct wnn_dai_bunsetsu *) rb.buf; | |
865 if (use_maep & WNN_USE_ATO && bun_no2 < buf->bun_suu) | |
866 { | |
867 buf->bun[bun_no2]->dai_top = (dp[dcnt - 1].sbn[dp[dcnt - 1].sbncnt - 1].status_bkwd == WNN_CONNECT_BK) ? 0 : 1; | |
868 } | |
869 free_bun (buf, bun_no, bun_no2); | |
870 ret = insert_dai (buf, BUN, bun_no, bun_no2, dp, dcnt, 0); | |
871 } | |
872 if (buf->zenkouho_end_bun > bun_no && buf->zenkouho_bun < bun_no2) | |
873 { | |
874 free_zenkouho (buf); | |
875 } | |
876 else if (buf->zenkouho_bun >= bun_no2) | |
877 { | |
878 buf->zenkouho_bun += ret - bun_no2; | |
879 buf->zenkouho_end_bun += ret - bun_no2; | |
880 } | |
881 return (ret); | |
882 } | |
883 | |
884 int | |
885 jl_nobi_conv (buf, bun_no, ichbn_len, bun_no2, use_maep, ich_shop) | |
886 register struct wnn_buf *buf; | |
887 int ichbn_len, use_maep, ich_shop; | |
888 register int bun_no, bun_no2; | |
889 { | |
890 w_char yomi[LENGTHCONV], ytmp; | |
891 int ret; | |
892 int len1; | |
893 | |
894 register WNN_BUN *b1; /* 学習がうまくいくように変更しました。H.T. */ | |
895 | |
896 wnn_errorno = 0; | |
897 if (bun_no < 0) | |
898 return (-1); | |
899 if (bun_no2 >= buf->bun_suu || bun_no2 < 0) | |
900 bun_no2 = buf->bun_suu; | |
901 | |
902 len1 = jl_get_yomi (buf, bun_no, bun_no2, yomi); | |
903 ytmp = yomi[ichbn_len]; | |
904 if (len1 < ichbn_len) | |
905 { | |
906 ichbn_len = len1; | |
907 } | |
908 yomi[ichbn_len] = 0; | |
909 | |
910 if (buf->bun[bun_no]->nobi_top != 1) | |
911 { /* need to add down_bnst */ | |
912 if (buf->bun[bun_no]) | |
913 add_down_bnst (buf, bun_no, buf->bun[bun_no]); | |
914 if (bun_no + 1 < buf->bun_suu) | |
915 { | |
916 add_down_bnst (buf, bun_no, buf->bun[bun_no + 1]); | |
917 /* 全て bun_no の down_bnst に加えるように変更 */ | |
918 } | |
919 } | |
920 b1 = buf->down_bnst[bun_no]; | |
921 buf->down_bnst[bun_no] = NULL; | |
922 free_down (buf, bun_no, bun_no2); | |
923 | |
924 if ((ret = tan_conv1 (buf, yomi, bun_no, bun_no2, use_maep & WNN_USE_MAE, ich_shop)) == -1) | |
925 { | |
926 return (-1); | |
927 } | |
928 yomi[ichbn_len] = ytmp; | |
929 if (ytmp) | |
930 { | |
931 int maep; | |
932 if (ich_shop) | |
933 { | |
934 maep = use_maep & ~WNN_USE_MAE; | |
935 } | |
936 else | |
937 { | |
938 maep = use_maep | WNN_USE_MAE; | |
939 } | |
940 if (ren_conv1 (buf, yomi + ichbn_len, ret, ret, maep) == -1) | |
941 { | |
942 return (-1); | |
943 } | |
944 } | |
945 buf->bun[bun_no]->nobi_top = 1; | |
946 buf->down_bnst[bun_no] = b1; | |
947 | |
948 return (buf->bun_suu); | |
949 } | |
950 | |
951 int | |
952 jl_nobi_conv_e2 (buf, env, bun_no, ichbn_len, bun_no2, use_maep, ich_shop) | |
953 register struct wnn_buf *buf; | |
954 struct wnn_env *env; | |
955 int ichbn_len, use_maep, ich_shop; | |
956 register int bun_no, bun_no2; | |
957 { | |
958 w_char yomi[LENGTHCONV], ytmp; | |
959 int ret; | |
960 int len1; | |
961 | |
962 wnn_errorno = 0; | |
963 if (bun_no < 0) | |
964 return (-1); | |
965 if (bun_no2 >= buf->bun_suu || bun_no2 < 0) | |
966 bun_no2 = buf->bun_suu; | |
967 | |
968 len1 = jl_get_yomi (buf, bun_no, bun_no2, yomi); | |
969 ytmp = yomi[ichbn_len]; | |
970 if (len1 < ichbn_len) | |
971 { | |
972 ichbn_len = len1; | |
973 } | |
974 yomi[ichbn_len] = 0; | |
975 | |
976 if (buf->bun[bun_no]->nobi_top != 1) | |
977 { /* need to add down_bnst */ | |
978 if (buf->bun[bun_no]) | |
979 add_down_bnst (buf, bun_no, buf->bun[bun_no]); | |
980 if (bun_no + 1 < buf->bun_suu) | |
981 { | |
982 if (ichbn_len < jl_yomi_len (buf, bun_no, bun_no + 1)) | |
983 { | |
984 add_down_bnst (buf, bun_no + 1, buf->bun[bun_no + 1]); | |
985 free_down (buf, bun_no + 2, bun_no2); | |
986 } | |
987 else | |
988 { | |
989 add_down_bnst (buf, bun_no, buf->bun[bun_no + 1]); | |
990 free_down (buf, bun_no + 1, bun_no2); | |
991 } | |
992 } | |
993 } | |
994 | |
995 if ((ret = tan_conv1 (buf, yomi, bun_no, bun_no2, use_maep & WNN_USE_MAE, ich_shop)) == -1) | |
996 { | |
997 return (-1); | |
998 } | |
999 | |
1000 buf->env = env; | |
1001 | |
1002 yomi[ichbn_len] = ytmp; | |
1003 if (ytmp) | |
1004 { | |
1005 int maep; | |
1006 if (ich_shop) | |
1007 { | |
1008 maep = use_maep & ~WNN_USE_MAE; | |
1009 } | |
1010 else | |
1011 { | |
1012 maep = use_maep | WNN_USE_MAE; | |
1013 } | |
1014 if (ren_conv1 (buf, yomi + ichbn_len, ret, ret, maep) == -1) | |
1015 { | |
1016 return (-1); | |
1017 } | |
1018 } | |
1019 buf->bun[bun_no]->nobi_top = 1; | |
1020 | |
1021 return (buf->bun_suu); | |
1022 } | |
1023 | |
1024 int | |
1025 jl_kill (buf, bun_no, bun_no2) | |
1026 struct wnn_buf *buf; | |
1027 register int bun_no, bun_no2; | |
1028 { | |
1029 wnn_errorno = 0; | |
1030 if (bun_no < 0) | |
1031 return (0); | |
1032 if (bun_no2 < bun_no || bun_no2 < 0) | |
1033 bun_no2 = buf->bun_suu; | |
1034 free_zenkouho (buf); /* toriaezu */ | |
1035 free_down (buf, bun_no, bun_no2); | |
1036 free_bun (buf, bun_no, bun_no2); | |
1037 bcopy ((char *) &buf->bun[bun_no2], (char *) &buf->bun[bun_no], (buf->bun_suu - bun_no2) * sizeof (WNN_BUN *)); | |
1038 bcopy ((char *) &buf->down_bnst[bun_no2], (char *) &buf->down_bnst[bun_no], (buf->bun_suu - bun_no2) * sizeof (WNN_BUN *)); | |
1039 buf->bun_suu -= bun_no2 - bun_no; | |
1040 return (buf->bun_suu); | |
1041 } | |
1042 | |
1043 int | |
1044 jl_zenkouho (buf, bun_no, use_maep, uniq_level) | |
1045 register struct wnn_buf *buf; | |
1046 int bun_no, use_maep, uniq_level; | |
1047 { | |
1048 int cnt; | |
1049 w_char yomi[LENGTHBUNSETSU], yomi1[LENGTHBUNSETSU]; | |
1050 struct wnn_sho_bunsetsu *sp; | |
1051 register int k; | |
1052 | |
1053 wnn_errorno = 0; | |
1054 jl_get_yomi (buf, bun_no, bun_no + 1, yomi); | |
1055 | |
1056 if (bun_no == buf->zenkouho_bun && buf->zenkouho_daip == SHO) | |
1057 return (buf->c_zenkouho); | |
1058 if (use_maep & WNN_USE_MAE && bun_no > 0) | |
1059 { | |
1060 dumbhinsi = buf->bun[bun_no - 1]->hinsi; | |
1061 jl_get_yomi (buf, bun_no - 1, bun_no, yomi1); | |
1062 mae_fzk = yomi1 + buf->bun[bun_no - 1]->jirilen; | |
1063 } | |
1064 else | |
1065 { | |
1066 dumbhinsi = WNN_BUN_SENTOU; | |
1067 mae_fzk = (w_char *) 0; | |
1068 } | |
1069 if (use_maep & WNN_USE_ATO && bun_no + 1 < buf->bun_suu) | |
1070 { | |
1071 | |
1072 syuutanv = buf->bun[bun_no + 1]->kangovect; | |
1073 syuutanv1 = WNN_VECT_KANZEN; | |
1074 buf->zenkouho_endvect = syuutanv; | |
1075 } | |
1076 else | |
1077 { | |
1078 syuutanv = WNN_VECT_KANZEN; | |
1079 syuutanv1 = WNN_VECT_NO; | |
1080 if (bun_no + 1 < buf->bun_suu) | |
1081 { | |
1082 buf->bun[bun_no + 1]->dai_top = 1; | |
1083 } | |
1084 buf->zenkouho_endvect = -1; | |
1085 } | |
1086 if ((cnt = js_kanzen_sho (buf->env, yomi, dumbhinsi, mae_fzk, syuutanv, syuutanv1, &rb)) < 0) | |
1087 { | |
1088 if_dead_disconnect_b (buf, -1); | |
1089 } | |
1090 | |
1091 sp = (struct wnn_sho_bunsetsu *) rb.buf; | |
1092 free_zenkouho (buf); | |
1093 if ((buf->bun[bun_no]->from_zenkouho & 1) == BUN) | |
1094 { | |
1095 set_sho (buf->bun[bun_no], &buf->zenkouho[0]); | |
1096 buf->zenkouho_suu = 1; | |
1097 /* Connection information of Old bunsetsu | |
1098 * May not be correct. | |
1099 */ | |
1100 k = get_c_jikouho (sp, cnt, buf->bun[bun_no]); | |
1101 if (k >= 0) | |
1102 { | |
1103 buf->zenkouho[0]->dai_top = (sp[k].status == WNN_CONNECT) ? 0 : 1; | |
1104 buf->zenkouho[0]->dai_end = (sp[k].status_bkwd == WNN_CONNECT_BK) ? 0 : 1; | |
1105 } | |
1106 if (uniq_level || k < 0) | |
1107 { | |
1108 insert_sho (buf, ZENKOUHO, -1, -1, sp, cnt, uniq_level); | |
1109 } | |
1110 else | |
1111 { | |
1112 insert_sho (buf, ZENKOUHO, -1, -1, sp, k, uniq_level); | |
1113 insert_sho (buf, ZENKOUHO, -1, -1, sp + k + 1, cnt - k - 1, uniq_level); | |
1114 } | |
1115 buf->c_zenkouho = 0; | |
1116 } | |
1117 else | |
1118 { | |
1119 insert_sho (buf, ZENKOUHO, -1, -1, sp, cnt, uniq_level); | |
1120 k = get_c_jikouho_from_zenkouho (buf, buf->bun[bun_no]); | |
1121 if (k < 0) | |
1122 { | |
1123 k = 0; /* Only when the kouho has been removed from dict. */ | |
1124 } | |
1125 buf->c_zenkouho = k; | |
1126 } | |
1127 buf->zenkouho_bun = bun_no; | |
1128 buf->zenkouho_end_bun = bun_no + 1; | |
1129 buf->zenkouho_daip = SHO; | |
1130 for (k = 0; k < buf->zenkouho_suu; k++) | |
1131 { | |
1132 if (buf->zenkouho[k]->ima && buf->zenkouho[k]->dic_no != -1) | |
1133 { | |
1134 add_down_bnst (buf, bun_no, buf->zenkouho[k]); | |
1135 } | |
1136 } | |
1137 return (buf->c_zenkouho); | |
1138 } | |
1139 | |
1140 int | |
1141 jl_zenkouho_dai (buf, bun_no, bun_no2, use_maep, uniq_level) | |
1142 register struct wnn_buf *buf; | |
1143 int bun_no, bun_no2, use_maep, uniq_level; | |
1144 { | |
1145 int cnt; | |
1146 w_char yomi[LENGTHBUNSETSU], yomi1[LENGTHBUNSETSU]; | |
1147 struct wnn_dai_bunsetsu *dp; | |
1148 int tmp; | |
1149 register int k; | |
1150 | |
1151 wnn_errorno = 0; | |
1152 if (bun_no2 > (tmp = dai_end (buf, bun_no)) || bun_no2 < 0) | |
1153 bun_no2 = tmp; | |
1154 jl_get_yomi (buf, bun_no, bun_no2, yomi); | |
1155 | |
1156 if (bun_no == buf->zenkouho_bun && buf->zenkouho_daip == DAI) | |
1157 { | |
1158 return (buf->c_zenkouho); | |
1159 } | |
1160 if (use_maep & WNN_USE_MAE && bun_no > 0) | |
1161 { | |
1162 dumbhinsi = buf->bun[bun_no - 1]->hinsi; | |
1163 jl_get_yomi (buf, bun_no - 1, bun_no, yomi1); | |
1164 mae_fzk = yomi1 + buf->bun[bun_no - 1]->jirilen; | |
1165 } | |
1166 else | |
1167 { | |
1168 dumbhinsi = WNN_BUN_SENTOU; | |
1169 mae_fzk = (w_char *) 0; | |
1170 } | |
1171 if (use_maep & WNN_USE_ATO && bun_no2 < buf->bun_suu) | |
1172 { | |
1173 syuutanv = buf->bun[bun_no2]->kangovect; | |
1174 syuutanv1 = WNN_VECT_KANZEN; | |
1175 buf->zenkouho_endvect = syuutanv; | |
1176 } | |
1177 else | |
1178 { | |
1179 syuutanv = WNN_VECT_KANZEN; | |
1180 syuutanv1 = WNN_VECT_NO; | |
1181 if (bun_no2 < buf->bun_suu) | |
1182 { | |
1183 buf->bun[bun_no2]->dai_top = 1; | |
1184 } | |
1185 buf->zenkouho_endvect = -1; | |
1186 } | |
1187 if ((cnt = js_kanzen_dai (buf->env, yomi, dumbhinsi, mae_fzk, syuutanv, syuutanv1, &rb)) < 0) | |
1188 { | |
1189 if_dead_disconnect_b (buf, -1); | |
1190 } | |
1191 dp = (struct wnn_dai_bunsetsu *) rb.buf; | |
1192 | |
1193 free_zenkouho (buf); | |
1194 /* Wander if it is OK, that is, only when all the | |
1195 * zenkouho's are got from zenkouho_dai, we need not move | |
1196 * the current dai-bunsetsu to the top of zenkouho's | |
1197 */ | |
1198 for (k = bun_no; k < bun_no2; k++) | |
1199 { | |
1200 if (buf->bun[k]->from_zenkouho != ZENKOUHO_DAI) | |
1201 break; | |
1202 } | |
1203 if (k != bun_no2) | |
1204 { /* move the current to the top. */ | |
1205 make_space_for (buf, ZENKOUHO, buf->zenkouho_suu, buf->zenkouho_suu, bun_no2 - bun_no); | |
1206 set_dai (&buf->bun[bun_no], &buf->zenkouho[0], bun_no2 - bun_no); | |
1207 buf->zenkouho_dai[0] = 0; | |
1208 buf->zenkouho_dai[1] = bun_no2 - bun_no; | |
1209 buf->zenkouho_dai_suu = 1; | |
1210 buf->zenkouho_suu = bun_no2 - bun_no; | |
1211 k = get_c_jikouho_dai (dp, cnt, buf->bun, bun_no); | |
1212 if (k >= 0) | |
1213 { | |
1214 buf->zenkouho[0]->dai_top = (dp[k].sbn->status == WNN_CONNECT) ? 0 : 1; | |
1215 buf->zenkouho[bun_no2 - bun_no - 1]->dai_end = (dp[k].sbn[dp[k].sbncnt - 1].status_bkwd == WNN_CONNECT_BK) ? 0 : 1; | |
1216 /* KURI *//* USO*? */ | |
1217 } | |
1218 if (uniq_level || k < 0) | |
1219 { | |
1220 insert_dai (buf, ZENKOUHO, -1, -1, dp, cnt, uniq_level); | |
1221 } | |
1222 else | |
1223 { | |
1224 insert_dai (buf, ZENKOUHO, -1, -1, dp, k, uniq_level); | |
1225 insert_dai (buf, ZENKOUHO, -1, -1, dp + k + 1, cnt - k - 1, uniq_level); | |
1226 } | |
1227 buf->c_zenkouho = 0; | |
1228 } | |
1229 else | |
1230 { | |
1231 insert_dai (buf, ZENKOUHO, -1, -1, dp, cnt, uniq_level); | |
1232 k = get_c_jikouho_from_zenkouho_dai (buf, buf->bun[bun_no]); | |
1233 if (k < 0) | |
1234 { | |
1235 k = 0; /* Only when the kouho has been removed from dict. */ | |
1236 } | |
1237 buf->c_zenkouho = k; | |
1238 } | |
1239 buf->zenkouho_bun = bun_no; | |
1240 buf->zenkouho_end_bun = bun_no2; | |
1241 buf->zenkouho_daip = DAI; | |
1242 for (k = 0; k < buf->zenkouho_suu; k++) | |
1243 { | |
1244 if (buf->zenkouho[k]->ima && buf->zenkouho[k]->dic_no != -1) | |
1245 { | |
1246 add_down_bnst (buf, bun_no, buf->zenkouho[k]); | |
1247 } | |
1248 } | |
1249 return (buf->c_zenkouho); | |
1250 } | |
1251 | |
1252 int | |
1253 jl_set_jikouho (buf, offset) | |
1254 register struct wnn_buf *buf; | |
1255 register int offset; | |
1256 { | |
1257 wnn_errorno = 0; | |
1258 if (buf->zenkouho_suu <= 0) | |
1259 return (-1); | |
1260 if (buf->zenkouho_daip != SHO) | |
1261 { | |
1262 return (-1); | |
1263 } | |
1264 offset = (offset + buf->zenkouho_suu) % buf->zenkouho_suu; | |
1265 if (buf->zenkouho_bun + 1 < buf->bun_suu && buf->zenkouho_endvect != -1) | |
1266 buf->bun[buf->zenkouho_bun + 1]->dai_top = buf->zenkouho[offset]->dai_end; | |
1267 free_sho (buf, &buf->bun[buf->zenkouho_bun]); | |
1268 set_sho (buf->zenkouho[offset], &buf->bun[buf->zenkouho_bun]); | |
1269 buf->c_zenkouho = offset; | |
1270 return (offset); | |
1271 } | |
1272 | |
1273 | |
1274 int | |
1275 jl_set_jikouho_dai (buf, offset) | |
1276 register struct wnn_buf *buf; | |
1277 int offset; | |
1278 { | |
1279 register int st, end, bun, k; | |
1280 | |
1281 wnn_errorno = 0; | |
1282 if (buf->zenkouho_suu <= 0) | |
1283 return (-1); | |
1284 if (buf->zenkouho_daip != DAI) | |
1285 { | |
1286 return (-1); | |
1287 } | |
1288 offset = (offset + buf->zenkouho_dai_suu) % buf->zenkouho_dai_suu; | |
1289 if (buf->zenkouho_end_bun < buf->bun_suu && buf->zenkouho_endvect != -1) | |
1290 buf->bun[buf->zenkouho_end_bun]->dai_top = buf->zenkouho[buf->zenkouho_dai[offset + 1] - 1]->dai_end; | |
1291 free_bun (buf, buf->zenkouho_bun, buf->zenkouho_end_bun); | |
1292 st = buf->zenkouho_dai[offset]; | |
1293 end = buf->zenkouho_dai[offset + 1]; | |
1294 make_space_for (buf, BUN, buf->zenkouho_bun, buf->zenkouho_end_bun, end - st); | |
1295 for (bun = buf->zenkouho_bun, k = st; k < end;) | |
1296 { | |
1297 set_sho (buf->zenkouho[k++], &buf->bun[bun++]); | |
1298 } | |
1299 buf->zenkouho_end_bun = buf->zenkouho_bun + end - st; | |
1300 buf->c_zenkouho = offset; | |
1301 return (offset); | |
1302 } | |
1303 | |
1304 int | |
1305 jl_update_hindo (buf, bun_no, bun_no2) | |
1306 register struct wnn_buf *buf; | |
1307 int bun_no, bun_no2; | |
1308 { | |
1309 register int k; | |
1310 register WNN_BUN *wb; | |
1311 | |
1312 wnn_errorno = 0; | |
1313 if (bun_no < 0) | |
1314 return (-1); | |
1315 if (bun_no2 >= buf->bun_suu || bun_no2 < 0) | |
1316 bun_no2 = buf->bun_suu; | |
1317 | |
1318 #ifdef JL_DEBUG | |
1319 printf ("\t\tDown Hindo\n"); | |
1320 #endif | |
1321 for (k = bun_no; k < bun_no2; k++) | |
1322 { | |
1323 if (buf->bun[k]->hindo_updated == 1) | |
1324 continue; | |
1325 for (wb = buf->down_bnst[k]; wb; wb = wb->down) | |
1326 { | |
1327 if (wb->bug == 1) | |
1328 break; | |
1329 wb->bug = 1; | |
1330 if (wb->dic_no != -1) | |
1331 { | |
1332 if (js_hindo_set (buf->env, wb->dic_no, wb->entry, WNN_IMA_OFF, WNN_HINDO_NOP) == -1) | |
1333 { | |
1334 if (wnn_errorno == WNN_JSERVER_DEAD) | |
1335 { | |
1336 jl_disconnect (buf->env); | |
1337 buf->env = 0; | |
1338 return (-1); | |
1339 } | |
1340 } | |
1341 #ifdef JL_DEBUG | |
1342 display_bun (wb); | |
1343 #endif | |
1344 } | |
1345 } | |
1346 } | |
1347 free_down (buf, bun_no, bun_no2); | |
1348 | |
1349 #ifdef JL_DEBUG | |
1350 printf ("\t\tUp Hindo\n"); | |
1351 #endif | |
1352 for (k = bun_no; k < bun_no2; k++) | |
1353 { | |
1354 if (buf->bun[k]->hindo_updated == 1) | |
1355 continue; | |
1356 buf->bun[k]->hindo_updated = 1; | |
1357 wb = buf->bun[k]; | |
1358 #ifdef JL_DEBUG | |
1359 display_bun (wb); | |
1360 #endif | |
1361 if (js_hindo_set (buf->env, wb->dic_no, wb->entry, WNN_IMA_ON, WNN_HINDO_INC) == -1) | |
1362 { | |
1363 if (wnn_errorno == WNN_JSERVER_DEAD) | |
1364 { | |
1365 jl_disconnect (buf->env); | |
1366 buf->env = 0; | |
1367 return (-1); | |
1368 } | |
1369 } | |
1370 } | |
1371 return (0); | |
1372 } | |
1373 | |
1374 | |
1375 static w_char * | |
1376 wnn_area (bp, area, kanjip) | |
1377 WNN_BUN *bp; | |
1378 w_char *area; | |
1379 int kanjip; | |
1380 { | |
1381 register WNN_BUN *bp1; | |
1382 register w_char *c, *end; | |
1383 | |
1384 for (bp1 = bp; bp1; bp1 = bp1->next) | |
1385 { | |
1386 if (bp1 != bp) | |
1387 c = (w_char *) bp1; | |
1388 else | |
1389 c = bp1->yomi; | |
1390 end = (w_char *) & bp1->next; | |
1391 for (; c < end;) | |
1392 { | |
1393 if (!kanjip) | |
1394 { | |
1395 if ((*area++ = *c++) == 0) | |
1396 { | |
1397 area--; | |
1398 goto out; | |
1399 } | |
1400 } | |
1401 else | |
1402 { | |
1403 if (*c++ == 0) | |
1404 kanjip--; | |
1405 } | |
1406 } | |
1407 } | |
1408 out: | |
1409 return (area); | |
1410 } | |
1411 | |
1412 static int | |
1413 dai_end (buf, bun_no) | |
1414 register struct wnn_buf *buf; | |
1415 register int bun_no; | |
1416 { | |
1417 bun_no++; | |
1418 for (; bun_no < buf->bun_suu && !buf->bun[bun_no]->dai_top; bun_no++); | |
1419 return (bun_no); | |
1420 } | |
1421 | |
1422 #define dai_end_zenkouho(buf, bun_no) (buf->zenkouho_dai[bun_no + 1]) | |
1423 | |
1424 #ifdef CONVERT_by_STROKE | |
1425 /* 筆形 (Bi Xing) */ | |
1426 void | |
1427 jl_get_zenkouho_yomi (buf, zen_num, area) | |
1428 register struct wnn_buf *buf; | |
1429 int zen_num; | |
1430 w_char *area; | |
1431 { | |
1432 register int k, end; | |
1433 | |
1434 wnn_errorno = 0; | |
1435 if (!buf->zenkouho_daip) | |
1436 { | |
1437 wnn_area (buf->zenkouho[zen_num], area, WNN_YOMI); | |
1438 } | |
1439 else | |
1440 { | |
1441 end = dai_end_zenkouho (buf, zen_num); | |
1442 for (k = buf->zenkouho_dai[zen_num]; k < end; k++) | |
1443 { | |
1444 area = wnn_area (buf->zenkouho[k], area, WNN_KANJI); | |
1445 } | |
1446 } | |
1447 } | |
1448 #endif | |
1449 | |
1450 void | |
1451 jl_get_zenkouho_kanji (buf, zen_num, area) | |
1452 register struct wnn_buf *buf; | |
1453 int zen_num; | |
1454 w_char *area; | |
1455 { | |
1456 register int k, end; | |
1457 | |
1458 wnn_errorno = 0; | |
1459 if (!buf->zenkouho_daip) | |
1460 { | |
1461 wnn_area (buf->zenkouho[zen_num], area, WNN_KANJI); | |
1462 } | |
1463 else | |
1464 { | |
1465 end = dai_end_zenkouho (buf, zen_num); | |
1466 for (k = buf->zenkouho_dai[zen_num]; k < end; k++) | |
1467 { | |
1468 area = wnn_area (buf->zenkouho[k], area, WNN_KANJI); | |
1469 } | |
1470 } | |
1471 } | |
1472 | |
1473 int | |
1474 wnn_get_area (buf, bun_no, bun_no2, area, kanjip) | |
1475 struct wnn_buf *buf; | |
1476 register int bun_no, bun_no2; | |
1477 w_char *area; | |
1478 int kanjip; | |
1479 { | |
1480 register int k; | |
1481 w_char *area1 = area; | |
1482 | |
1483 if (bun_no < 0) | |
1484 return (0); | |
1485 if (bun_no2 >= buf->bun_suu || bun_no2 < 0) | |
1486 bun_no2 = buf->bun_suu; | |
1487 | |
1488 for (k = bun_no; k < bun_no2; k++) | |
1489 { | |
1490 area = wnn_area (buf->bun[k], area, kanjip); | |
1491 } | |
1492 return (area - area1); | |
1493 } | |
1494 | |
1495 #define JISHO 1 | |
1496 #define HINDO 2 | |
1497 | |
1498 /*********************************/ | |
1499 int | |
1500 jl_dic_add_e (env, dic_name, hindo_name, rev, prio, rw, hrw, pwd_dic, pwd_hindo, error_handler, message_handler) | |
1501 register struct wnn_env *env; | |
1502 char *dic_name; | |
1503 char *hindo_name; | |
1504 int prio; | |
1505 int rw, hrw, rev; | |
1506 char *pwd_dic, *pwd_hindo; | |
1507 int (*error_handler) (), (*message_handler) (); | |
1508 { | |
1509 char tmp[256]; | |
1510 char pwd[WNN_PASSWD_LEN], hpwd[WNN_PASSWD_LEN]; | |
1511 int fid, hfid = -1; | |
1512 register int ret; | |
1513 | |
1514 | |
1515 if (file_exist (env, dic_name) == -1) | |
1516 { | |
1517 if (wnn_errorno == WNN_JSERVER_DEAD) | |
1518 { | |
1519 jl_disconnect (env); | |
1520 return (-1); | |
1521 } | |
1522 if ((int) error_handler == WNN_NO_CREATE || (rw == WNN_DIC_RDONLY)) | |
1523 { | |
1524 sprintf (tmp, "%s \"%s\" %s", msg_get (wnn_msg_cat, 200, NULL, env->lang), dic_name, msg_get (wnn_msg_cat, 201, NULL, env->lang)); | |
1525 /* | |
1526 "辞書ファイル \"%s\" が無いよ。", | |
1527 */ | |
1528 message_out (message_handler, tmp); | |
1529 wnn_errorno = WNN_NO_EXIST; | |
1530 return (-1); | |
1531 } | |
1532 sprintf (tmp, "%s \"%s\" %s%s", msg_get (wnn_msg_cat, 200, NULL, env->lang), dic_name, msg_get (wnn_msg_cat, 201, NULL, env->lang), msg_get (wnn_msg_cat, 202, NULL, env->lang)); | |
1533 /* | |
1534 "辞書ファイル \"%s\" が無いよ。作る?(Y/N)", | |
1535 */ | |
1536 if ((int) error_handler == WNN_CREATE || call_error_handler (error_handler, tmp)) | |
1537 { | |
1538 if (create_file (env, dic_name, JISHO, -1, /* -1 is dummy */ | |
1539 pwd_dic, (hindo_name && *hindo_name) ? "" : pwd_hindo, error_handler, message_handler) == -1) | |
1540 { | |
1541 return (-1); | |
1542 } | |
1543 } | |
1544 else | |
1545 { | |
1546 wnn_errorno = WNN_NO_EXIST; | |
1547 return (-1); | |
1548 } | |
1549 } | |
1550 if ((fid = file_read (env, dic_name)) == -1) | |
1551 if_dead_disconnect (env, -1); | |
1552 if (hindo_name && *hindo_name) | |
1553 { | |
1554 if (file_exist (env, hindo_name) == -1) | |
1555 { | |
1556 if (wnn_errorno == WNN_JSERVER_DEAD) | |
1557 { | |
1558 jl_disconnect (env); | |
1559 return (-1); | |
1560 } | |
1561 if ((int) error_handler == WNN_NO_CREATE || (hrw == WNN_DIC_RDONLY)) | |
1562 { | |
1563 sprintf (tmp, "%s \"%s\" %s", msg_get (wnn_msg_cat, 203, NULL, env->lang), hindo_name, msg_get (wnn_msg_cat, 201, NULL, env->lang)); | |
1564 /* | |
1565 "頻度ファイル \"%s\" が無いよ。", | |
1566 */ | |
1567 message_out (message_handler, tmp); | |
1568 wnn_errorno = WNN_NO_EXIST; | |
1569 return (-1); | |
1570 } | |
1571 sprintf (tmp, "%s \"%s\" %s%s", msg_get (wnn_msg_cat, 203, NULL, env->lang), hindo_name, msg_get (wnn_msg_cat, 201, NULL, env->lang), msg_get (wnn_msg_cat, 202, NULL, env->lang)); | |
1572 /* | |
1573 "頻度ファイル \"%s\" が無いよ。作る?(Y/N)", | |
1574 */ | |
1575 if ((int) error_handler == WNN_CREATE || call_error_handler (error_handler, tmp)) | |
1576 { | |
1577 if (create_file (env, hindo_name, HINDO, fid, "", pwd_hindo, error_handler, message_handler) == -1) | |
1578 return (-1); | |
1579 } | |
1580 else | |
1581 { | |
1582 wnn_errorno = WNN_NO_EXIST; | |
1583 return (-1); | |
1584 } | |
1585 } | |
1586 if ((hfid = file_read (env, hindo_name)) == -1) | |
1587 { | |
1588 if_dead_disconnect (env, -1); | |
1589 } | |
1590 } | |
1591 if (get_pwd (pwd_dic, pwd) == -1) | |
1592 return (-1); | |
1593 if (get_pwd (pwd_hindo, hpwd) == -1) | |
1594 return (-1); | |
1595 if ((ret = js_dic_add (env, fid, hfid, rev, prio, rw, hrw, pwd, hpwd)) < 0) | |
1596 { | |
1597 if (wnn_errorno == WNN_JSERVER_DEAD) | |
1598 { | |
1599 jl_disconnect (env); | |
1600 return (-1); | |
1601 } | |
1602 else if (wnn_errorno == WNN_HINDO_NO_MATCH) | |
1603 { | |
1604 if ((int) error_handler == WNN_NO_CREATE) | |
1605 { | |
1606 return (-1); | |
1607 } | |
1608 sprintf (tmp, msg_get (wnn_msg_cat, 204, NULL, env->lang), hindo_name); | |
1609 /* | |
1610 "辞書と頻度 \"%s\" の整合性が無いよ。作り直す?(Y/N)", | |
1611 */ | |
1612 if (!((int) error_handler == WNN_CREATE || call_error_handler (error_handler, tmp))) | |
1613 { | |
1614 return (-1); | |
1615 } | |
1616 if (file_discard (env, hfid) == -1) | |
1617 if_dead_disconnect (env, -1); | |
1618 if (file_remove (env->js_id, hindo_name, hpwd) == -1) | |
1619 if_dead_disconnect (env, -1); | |
1620 if (create_file (env, hindo_name, HINDO, fid, NULL, pwd_hindo, WNN_CREATE, message_handler) == -1) | |
1621 return (-1); | |
1622 if ((hfid = file_read (env, hindo_name)) == -1) | |
1623 if_dead_disconnect (env, -1); | |
1624 if ((ret = js_dic_add (env, fid, hfid, rev, prio, rw, hrw, pwd, hpwd)) < 0) | |
1625 if_dead_disconnect (env, -1); | |
1626 } | |
1627 } | |
1628 return (ret); | |
1629 } | |
1630 | |
1631 | |
1632 int | |
1633 jl_dic_delete_e (env, dic_no) | |
1634 register struct wnn_env *env; | |
1635 register int dic_no; | |
1636 { | |
1637 WNN_DIC_INFO dic; | |
1638 | |
1639 if (js_dic_info (env, dic_no, &dic) < 0) | |
1640 { | |
1641 if_dead_disconnect (env, -1); | |
1642 } | |
1643 if (js_dic_delete (env, dic_no) < 0) | |
1644 if_dead_disconnect (env, -1); | |
1645 /* dic Body */ | |
1646 if (file_discard (env, dic.body) < 0) | |
1647 { | |
1648 if_dead_disconnect (env, -1); | |
1649 } | |
1650 /* dic hindo */ | |
1651 if (dic.hindo != -1) | |
1652 { | |
1653 if (file_discard (env, dic.hindo) < 0) | |
1654 { | |
1655 if_dead_disconnect (env, -1); | |
1656 } | |
1657 } | |
1658 return (0); | |
1659 } | |
1660 | |
1661 static int | |
1662 get_pwd (pwd_dic, pwd) | |
1663 register char *pwd_dic, *pwd; | |
1664 { | |
1665 FILE *fp; | |
1666 | |
1667 if (pwd_dic && *pwd_dic) | |
1668 { | |
1669 if ((fp = fopen (pwd_dic, "r")) == NULL) | |
1670 { | |
1671 wnn_errorno = WNN_CANT_OPEN_PASSWD_FILE; | |
1672 return (-1); | |
1673 } | |
1674 fgets (pwd, WNN_PASSWD_LEN, fp); | |
1675 fclose (fp); | |
1676 } | |
1677 else | |
1678 { | |
1679 pwd[0] = 0; | |
1680 } | |
1681 return (0); | |
1682 } | |
1683 | |
1684 static int | |
1685 create_pwd_file (env, pwd_file, error_handler, message_handler) | |
1686 register struct wnn_env *env; | |
1687 char *pwd_file; | |
1688 int (*error_handler) (), (*message_handler) (); | |
1689 { | |
1690 FILE *fp; | |
1691 char gomi[256]; | |
1692 | |
1693 if (pwd_file == NULL || *pwd_file == 0) | |
1694 return (0); | |
1695 if (access (pwd_file, F_OK) != -1) | |
1696 return (0); | |
1697 sprintf (gomi, "%s \"%s\" %s%s", msg_get (wnn_msg_cat, 205, NULL, env->lang), pwd_file, msg_get (wnn_msg_cat, 201, NULL, env->lang), msg_get (wnn_msg_cat, 202, NULL, env->lang)); | |
1698 /* | |
1699 "password_file \"%s\" が無いよ。作る?(Y/N)", | |
1700 */ | |
1701 if (call_error_handler (error_handler, gomi) == 0) | |
1702 { | |
1703 wnn_errorno = WNN_NO_EXIST; | |
1704 return (-1); | |
1705 } | |
1706 if ((fp = fopen (pwd_file, "w")) == NULL) | |
1707 { | |
1708 wnn_errorno = WNN_CANT_OPEN_PASSWD_FILE; | |
1709 message_out (message_handler, wnn_perror_lang (env->lang)); | |
1710 return (-1); | |
1711 } | |
1712 SRAND (time (0) + getuid ()); | |
1713 fprintf (fp, "%d\n", (int) RAND ()); | |
1714 fclose (fp); | |
1715 #define MODE_PWD (0000000 | 0000400) | |
1716 chmod (pwd_file, MODE_PWD); | |
1717 return (0); | |
1718 } | |
1719 | |
1720 | |
1721 /** jl_fuzokugo_set **/ | |
1722 int | |
1723 jl_fuzokugo_set_e (env, fname) | |
1724 struct wnn_env *env; | |
1725 char *fname; | |
1726 { | |
1727 register int fid, orgfid; | |
1728 int ret; | |
1729 | |
1730 wnn_errorno = 0; | |
1731 orgfid = js_fuzokugo_get (env); | |
1732 /* If orgfid == -1, it must be | |
1733 because no fuzokugo_file is set to the env | |
1734 */ | |
1735 if ((fid = file_read (env, fname)) == -1) | |
1736 if_dead_disconnect (env, -1); | |
1737 if ((ret = js_fuzokugo_set (env, fid)) < 0) | |
1738 if_dead_disconnect (env, ret); | |
1739 if (fid != orgfid && orgfid != -1) | |
1740 { | |
1741 js_file_discard (env, orgfid); | |
1742 } | |
1743 return (ret); | |
1744 } | |
1745 | |
1746 /** jl_fuzokugo_get **/ | |
1747 int | |
1748 jl_fuzokugo_get_e (env, fname) | |
1749 register struct wnn_env *env; | |
1750 char *fname; | |
1751 { | |
1752 WNN_FILE_INFO_STRUCT file; | |
1753 int fid; | |
1754 char *c; | |
1755 | |
1756 wnn_errorno = 0; | |
1757 fname[0] = 0; | |
1758 if ((fid = js_fuzokugo_get (env)) < 0) | |
1759 if_dead_disconnect (env, -1); | |
1760 if (js_file_info (env, fid, &file) < 0) | |
1761 if_dead_disconnect (env, -1); | |
1762 c = find_file_name_from_id (env, fid); | |
1763 if (c == NULL) | |
1764 { | |
1765 c = file.name; | |
1766 } | |
1767 strcpy (fname, c); | |
1768 return (fid); | |
1769 } | |
1770 | |
1771 /** jl_dic_save **/ | |
1772 int | |
1773 jl_dic_save_e (env, dic_no) | |
1774 register struct wnn_env *env; | |
1775 int dic_no; | |
1776 { | |
1777 WNN_DIC_INFO dic; | |
1778 WNN_FILE_INFO_STRUCT file; | |
1779 char *c; | |
1780 | |
1781 wnn_errorno = 0; | |
1782 if (js_dic_info (env, dic_no, &dic) < 0) | |
1783 if_dead_disconnect (env, -1); | |
1784 /* dic Body */ | |
1785 c = find_file_name_from_id (env, dic.body); | |
1786 if (c == NULL) | |
1787 { | |
1788 if (dic.localf) | |
1789 { | |
1790 c = dic.fname; | |
1791 } | |
1792 else | |
1793 { | |
1794 wnn_errorno = WNN_FILE_NOT_READ_FROM_CLIENT; | |
1795 return (-1); | |
1796 } | |
1797 } | |
1798 if (c[0] != C_LOCAL) | |
1799 { | |
1800 if (js_file_write (env, dic.body, c) < 0) | |
1801 { | |
1802 if (wnn_errorno == WNN_JSERVER_DEAD) | |
1803 { | |
1804 jl_disconnect_if_server_dead (env); | |
1805 return (-1); | |
1806 } | |
1807 } | |
1808 } | |
1809 else | |
1810 { | |
1811 if (js_file_receive (env, dic.body, c + 1) < 0) | |
1812 { | |
1813 if (wnn_errorno == WNN_JSERVER_DEAD) | |
1814 { | |
1815 jl_disconnect_if_server_dead (env); | |
1816 return (-1); | |
1817 } | |
1818 } | |
1819 } | |
1820 /* dic hindo */ | |
1821 if (dic.hindo != -1) | |
1822 { | |
1823 if (js_file_info (env, dic.hindo, &file) < 0) | |
1824 if_dead_disconnect (env, -1); | |
1825 c = find_file_name_from_id (env, file.fid); | |
1826 if (c == NULL) | |
1827 { | |
1828 if (dic.hlocalf) | |
1829 { | |
1830 c = dic.hfname; | |
1831 } | |
1832 else | |
1833 { | |
1834 wnn_errorno = WNN_FILE_NOT_READ_FROM_CLIENT; | |
1835 return (-1); | |
1836 } | |
1837 } | |
1838 if (c[0] != C_LOCAL) | |
1839 { | |
1840 if (js_file_write (env, dic.hindo, c) < 0) | |
1841 { | |
1842 if_dead_disconnect (env, -1); | |
1843 } | |
1844 } | |
1845 else | |
1846 { | |
1847 if (js_file_receive (env, dic.hindo, c + 1) < 0) | |
1848 { | |
1849 if_dead_disconnect (env, -1); | |
1850 } | |
1851 } | |
1852 } | |
1853 return (0); | |
1854 } | |
1855 | |
1856 int | |
1857 jl_dic_save_all_e (env) | |
1858 struct wnn_env *env; | |
1859 { | |
1860 register WNN_DIC_INFO *dic; | |
1861 register int k; | |
1862 char *c; | |
1863 | |
1864 register int cnt; | |
1865 | |
1866 wnn_errorno = 0; | |
1867 if ((cnt = js_dic_list (env, &dicrb)) == -1) | |
1868 if_dead_disconnect (env, -1); | |
1869 dic = (WNN_DIC_INFO *) dicrb.buf; | |
1870 for (k = 0; k < cnt; k++, dic++) | |
1871 { | |
1872 if ((c = find_file_name_from_id (env, dic->body)) == NULL) | |
1873 { | |
1874 if (dic->localf) | |
1875 { | |
1876 c = dic->fname; | |
1877 } | |
1878 else | |
1879 { | |
1880 wnn_errorno = WNN_FILE_NOT_READ_FROM_CLIENT; | |
1881 } | |
1882 } | |
1883 if (c) | |
1884 { | |
1885 if (c[0] != C_LOCAL) | |
1886 { | |
1887 if (js_file_write (env, dic->body, c) < 0) | |
1888 { | |
1889 if (wnn_errorno == WNN_JSERVER_DEAD) | |
1890 { | |
1891 jl_disconnect_if_server_dead (env); | |
1892 return (-1); | |
1893 } | |
1894 } | |
1895 } | |
1896 else | |
1897 { | |
1898 if (js_file_receive (env, dic->body, c + 1) < 0) | |
1899 { | |
1900 if (wnn_errorno == WNN_JSERVER_DEAD) | |
1901 { | |
1902 jl_disconnect_if_server_dead (env); | |
1903 return (-1); | |
1904 } | |
1905 } | |
1906 } | |
1907 } | |
1908 /* dic hindo */ | |
1909 if (dic->hindo != -1) | |
1910 { | |
1911 c = find_file_name_from_id (env, dic->hindo); | |
1912 if (c == NULL) | |
1913 { | |
1914 if (dic->hlocalf) | |
1915 { | |
1916 c = dic->hfname; | |
1917 } | |
1918 else | |
1919 { | |
1920 wnn_errorno = WNN_FILE_NOT_READ_FROM_CLIENT; | |
1921 } | |
1922 } | |
1923 if (c) | |
1924 { | |
1925 if (c[0] != C_LOCAL) | |
1926 { | |
1927 if (js_file_write (env, dic->hindo, c) < 0) | |
1928 { | |
1929 if (wnn_errorno == WNN_JSERVER_DEAD) | |
1930 { | |
1931 if_dead_disconnect (env, -1); | |
1932 } | |
1933 } | |
1934 } | |
1935 else | |
1936 { | |
1937 if (js_file_receive (env, dic->hindo, c + 1) < 0) | |
1938 { | |
1939 if (wnn_errorno == WNN_JSERVER_DEAD) | |
1940 { | |
1941 if_dead_disconnect (env, -1); | |
1942 } | |
1943 } | |
1944 } | |
1945 } | |
1946 } | |
1947 } | |
1948 if (wnn_errorno) | |
1949 return (-1); | |
1950 return (0); | |
1951 } | |
1952 | |
1953 /* | |
1954 * | |
1955 * bun manipulate routines | |
1956 * | |
1957 */ | |
1958 | |
1959 static void | |
1960 free_sho (buf, wbp) | |
1961 register struct wnn_buf *buf; | |
1962 WNN_BUN **wbp; | |
1963 { | |
1964 register WNN_BUN *wb; | |
1965 wb = *wbp; | |
1966 | |
1967 if (--wb->ref_cnt <= 0) | |
1968 { | |
1969 for (; wb;) | |
1970 { | |
1971 wb->free_next = buf->free_heap; | |
1972 buf->free_heap = wb; | |
1973 wb = wb->next; | |
1974 } | |
1975 } | |
1976 *wbp = NULL; | |
1977 } | |
1978 | |
1979 static void | |
1980 free_zenkouho (buf) | |
1981 register struct wnn_buf *buf; | |
1982 { | |
1983 register int k; | |
1984 | |
1985 for (k = 0; k < buf->zenkouho_suu; k++) | |
1986 { | |
1987 free_sho (buf, &buf->zenkouho[k]); | |
1988 } | |
1989 buf->zenkouho_suu = 0; | |
1990 buf->zenkouho_dai_suu = 0; | |
1991 buf->c_zenkouho = -1; | |
1992 buf->zenkouho_bun = -1; | |
1993 buf->zenkouho_end_bun = -1; | |
1994 } | |
1995 | |
1996 static void | |
1997 free_bun (buf, bun_no, bun_no2) | |
1998 struct wnn_buf *buf; | |
1999 register int bun_no, bun_no2; | |
2000 { | |
2001 register int k; | |
2002 | |
2003 for (k = bun_no; k < bun_no2; k++) | |
2004 { | |
2005 free_sho (buf, &buf->bun[k]); | |
2006 } | |
2007 } | |
2008 | |
2009 static void | |
2010 free_down (buf, bun_no, bun_no2) | |
2011 struct wnn_buf *buf; | |
2012 int bun_no, bun_no2; | |
2013 { | |
2014 register WNN_BUN **wbp, **wbp1; | |
2015 int k; | |
2016 | |
2017 for (k = bun_no; k < bun_no2; k++) | |
2018 { | |
2019 for (wbp = &buf->down_bnst[k]; *wbp; wbp = wbp1) | |
2020 { | |
2021 wbp1 = &(*wbp)->down; | |
2022 free_sho (buf, wbp); | |
2023 } | |
2024 } | |
2025 } | |
2026 | |
2027 static WNN_BUN * | |
2028 get_new_bun (buf) | |
2029 register struct wnn_buf *buf; | |
2030 { | |
2031 register WNN_BUN *wb; | |
2032 | |
2033 | |
2034 if (buf->free_heap == NULL) | |
2035 { | |
2036 if (alloc_heap (buf, INCREMENT) == -1) | |
2037 return (NULL); | |
2038 } | |
2039 wb = buf->free_heap; | |
2040 buf->free_heap = wb->free_next; | |
2041 wb->free_next = NULL; | |
2042 wb->daihyoka = -1; | |
2043 | |
2044 return (wb); | |
2045 } | |
2046 | |
2047 static WNN_BUN * | |
2048 get_sho (buf, sb, zenp, daip) | |
2049 struct wnn_buf *buf; | |
2050 struct wnn_sho_bunsetsu *sb; | |
2051 int zenp, daip; | |
2052 { | |
2053 register w_char *c, *end, *s; | |
2054 register WNN_BUN *wb; | |
2055 WNN_BUN *wb1; | |
2056 int where = 1; | |
2057 int len; | |
2058 | |
2059 if ((wb = get_new_bun (buf)) == NULL) | |
2060 return (NULL); | |
2061 | |
2062 wb->jirilen = sb->jiriend - sb->start + 1; | |
2063 wb->dic_no = sb->dic_no; | |
2064 wb->entry = sb->entry; | |
2065 wb->kangovect = sb->kangovect; | |
2066 wb->hinsi = sb->hinsi; | |
2067 wb->hindo = sb->hindo; | |
2068 wb->ima = sb->ima; | |
2069 wb->hindo_updated = 0; | |
2070 wb->bug = 0; | |
2071 wb->dai_top = 0; | |
2072 wb->nobi_top = 0; | |
2073 wb->ref_cnt = 1; | |
2074 wb->hyoka = sb->hyoka; | |
2075 wb->down = NULL; | |
2076 wb->from_zenkouho = daip << 1 | zenp; | |
2077 len = wnn_Strlen (sb->fuzoku); | |
2078 wb->yomilen = wnn_Strlen (sb->yomi) + len; | |
2079 wb->kanjilen = wnn_Strlen (sb->kanji) + len; | |
2080 /* | |
2081 wb->dai_top = (sb->status == WNN_CONNECT)? 0:1; | |
2082 大文節の先頭以外の小文節に関しては、status はいい加減な値が入っている。 | |
2083 */ | |
2084 s = sb->yomi; | |
2085 | |
2086 for (wb1 = wb;;) | |
2087 { | |
2088 if (wb1 == wb) | |
2089 c = wb1->yomi; | |
2090 else | |
2091 c = (w_char *) wb1; | |
2092 end = (w_char *) & wb1->next; | |
2093 | |
2094 for (; c < end;) | |
2095 { | |
2096 if ((*c++ = *s++) == 0) | |
2097 { | |
2098 if (where == 1) | |
2099 { | |
2100 where = 3; | |
2101 c--; | |
2102 s = sb->fuzoku; | |
2103 } | |
2104 else if (where == 3) | |
2105 { | |
2106 where = 0; | |
2107 s = sb->kanji; | |
2108 } | |
2109 else if (where == 0) | |
2110 { | |
2111 where = 4; | |
2112 c--; | |
2113 s = sb->fuzoku; | |
2114 } | |
2115 else | |
2116 { | |
2117 goto out; | |
2118 } | |
2119 } | |
2120 } | |
2121 wb1->next = get_new_bun (buf); | |
2122 wb1 = wb1->next; | |
2123 } | |
2124 out: | |
2125 wb1->next = NULL; | |
2126 return (wb); | |
2127 } | |
2128 | |
2129 static void | |
2130 make_space_for (buf, zenp, bun_no, bun_no2, cnt) | |
2131 register struct wnn_buf *buf; | |
2132 int bun_no, bun_no2, zenp; | |
2133 int cnt; | |
2134 { | |
2135 switch (zenp) | |
2136 { | |
2137 case BUN: | |
2138 make_space_for_bun (buf, bun_no, bun_no2, cnt); | |
2139 break; | |
2140 case ZENKOUHO: | |
2141 make_space_for_zenkouho (buf, bun_no, bun_no2, cnt); | |
2142 } | |
2143 } | |
2144 | |
2145 static void | |
2146 make_space_for_bun (buf, bun_no, bun_no2, cnt) | |
2147 register struct wnn_buf *buf; | |
2148 int bun_no, bun_no2; | |
2149 int cnt; | |
2150 { | |
2151 int newsize; | |
2152 register int k; | |
2153 | |
2154 newsize = buf->bun_suu + cnt - (bun_no2 - bun_no); | |
2155 | |
2156 #define Realloc(a, b) realloc((char *)(a), (unsigned)(b)) | |
2157 | |
2158 if (newsize > buf->msize_bun) | |
2159 { | |
2160 buf->bun = (WNN_BUN **) Realloc (buf->bun, newsize * sizeof (WNN_BUN *)); | |
2161 buf->down_bnst = (WNN_BUN **) Realloc (buf->down_bnst, newsize * sizeof (WNN_BUN *)); | |
2162 buf->msize_bun = newsize; | |
2163 } | |
2164 | |
2165 | |
2166 for (k = buf->bun_suu; k < newsize; k++) | |
2167 { | |
2168 buf->down_bnst[k] = NULL; | |
2169 } | |
2170 bcopy ((char *) &buf->bun[bun_no2], (char *) &buf->bun[bun_no + cnt], (buf->bun_suu - bun_no2) * sizeof (WNN_BUN *)); | |
2171 bcopy ((char *) &buf->down_bnst[bun_no2], (char *) &buf->down_bnst[bun_no + cnt], (buf->bun_suu - bun_no2) * sizeof (WNN_BUN *)); | |
2172 if (bun_no2 < bun_no + cnt) | |
2173 { | |
2174 bzero ((char *) &buf->down_bnst[bun_no2], (bun_no + cnt - bun_no2) * sizeof (WNN_BUN *)); | |
2175 } | |
2176 buf->bun_suu = newsize; | |
2177 } | |
2178 | |
2179 static void | |
2180 make_space_for_zenkouho (buf, bun_no, bun_no2, cnt) | |
2181 struct wnn_buf *buf; | |
2182 int bun_no, bun_no2; | |
2183 register int cnt; | |
2184 { | |
2185 register int newsize; | |
2186 | |
2187 newsize = buf->zenkouho_suu + cnt - (bun_no2 - bun_no); | |
2188 | |
2189 if (newsize > buf->msize_zenkouho) | |
2190 { | |
2191 buf->zenkouho = (WNN_BUN **) Realloc (buf->zenkouho, newsize * sizeof (WNN_BUN *)); | |
2192 buf->zenkouho_dai = (int *) Realloc (buf->zenkouho_dai, (1 + newsize) * sizeof (int *)); | |
2193 buf->msize_zenkouho = newsize; | |
2194 } | |
2195 bcopy ((char *) &buf->zenkouho[bun_no2], (char *) &buf->zenkouho[bun_no + cnt], (buf->zenkouho_suu - bun_no2) * sizeof (WNN_BUN *)); | |
2196 buf->zenkouho_suu = newsize; | |
2197 } | |
2198 | |
2199 | |
2200 static int | |
2201 insert_sho (buf, zenp, bun_no, bun_no2, sp, cnt, uniq_level) | |
2202 struct wnn_buf *buf; | |
2203 int bun_no, bun_no2; | |
2204 register struct wnn_sho_bunsetsu *sp; | |
2205 int cnt; | |
2206 int zenp; /* daip */ | |
2207 int uniq_level; /* uniq is only supported when bun_no = -1 | |
2208 and zenp == ZENKOUHO */ | |
2209 { | |
2210 register WNN_BUN **b; | |
2211 register int k; | |
2212 | |
2213 if (bun_no == -1) | |
2214 { | |
2215 bun_no = bun_no2 = (zenp == BUN) ? buf->bun_suu : buf->zenkouho_suu; | |
2216 } | |
2217 | |
2218 /* It will make too big space when uniq_level > 0, but That's OK! */ | |
2219 make_space_for (buf, zenp, bun_no, bun_no2, cnt); | |
2220 | |
2221 b = ((zenp == BUN) ? buf->bun : buf->zenkouho) + bun_no; | |
2222 for (k = bun_no; k < bun_no + cnt; k++, sp++) | |
2223 { | |
2224 if (uniq_level) | |
2225 { | |
2226 if (find_same_kouho (sp, buf->zenkouho, b, uniq_level)) | |
2227 continue; | |
2228 } | |
2229 *b = get_sho (buf, sp, zenp, SHO); | |
2230 (*b)->dai_top = (sp->status == WNN_CONNECT) ? 0 : 1; | |
2231 if (zenp != BUN) | |
2232 { | |
2233 if (buf->zenkouho_endvect != -1) | |
2234 { | |
2235 (*b)->dai_end = (sp->status_bkwd == WNN_CONNECT_BK) ? 0 : 1; | |
2236 } | |
2237 else | |
2238 { | |
2239 (*b)->dai_end = 1; | |
2240 } | |
2241 } | |
2242 b++; | |
2243 } | |
2244 if (uniq_level && zenp == ZENKOUHO) | |
2245 { | |
2246 buf->zenkouho_suu = b - buf->zenkouho; | |
2247 } | |
2248 return (cnt + bun_no); | |
2249 } | |
2250 | |
2251 /* for zenkouho, assume bun_no = bun_no2 = zenkouho_suu */ | |
2252 static int | |
2253 insert_dai (buf, zenp, bun_no, bun_no2, dp, dcnt, uniq_level) | |
2254 struct wnn_buf *buf; | |
2255 int bun_no, bun_no2; | |
2256 struct wnn_dai_bunsetsu *dp; | |
2257 int dcnt; | |
2258 int zenp; | |
2259 int uniq_level; | |
2260 { | |
2261 register WNN_BUN **b, **b0; | |
2262 register int k, l, m; | |
2263 register int cnt = 0; | |
2264 struct wnn_sho_bunsetsu *sp, *sp1; | |
2265 | |
2266 if (bun_no == -1) | |
2267 { | |
2268 if (zenp == BUN) | |
2269 { | |
2270 bun_no = bun_no2 = buf->bun_suu; | |
2271 } | |
2272 else | |
2273 { | |
2274 bun_no = bun_no2 = buf->zenkouho_suu; | |
2275 } | |
2276 } | |
2277 | |
2278 for (k = 0; k < dcnt; k++) | |
2279 { | |
2280 cnt += dp[k].sbncnt; | |
2281 } | |
2282 make_space_for (buf, zenp, bun_no, bun_no2, cnt); | |
2283 /* zenkouho_dai_suu must not be initialized */ | |
2284 | |
2285 if (zenp == BUN) | |
2286 { | |
2287 b = buf->bun + bun_no; | |
2288 } | |
2289 else | |
2290 { | |
2291 b = buf->zenkouho + bun_no; | |
2292 } | |
2293 | |
2294 for (k = 0, m = buf->zenkouho_dai_suu; k < dcnt; k++) | |
2295 { | |
2296 if (uniq_level) | |
2297 { | |
2298 if (find_same_kouho_dai (&dp[k], buf, m, uniq_level)) | |
2299 continue; | |
2300 } | |
2301 sp = dp[k].sbn; | |
2302 if (zenp == ZENKOUHO) | |
2303 { | |
2304 buf->zenkouho_dai[m++] = b - buf->zenkouho; | |
2305 } | |
2306 b0 = b; | |
2307 sp1 = sp; | |
2308 for (l = 0; l < dp[k].sbncnt; l++, b++, sp++) | |
2309 { | |
2310 *b = get_sho (buf, sp, zenp, DAI); | |
2311 if (zenp == ZENKOUHO) | |
2312 { | |
2313 if ((l == dp[k].sbncnt - 1) | |
2314 && (buf->zenkouho_endvect != -1) | |
2315 && (sp->status_bkwd != WNN_CONNECT_BK)) | |
2316 { | |
2317 (*b)->dai_end = 1; | |
2318 } | |
2319 else | |
2320 { | |
2321 (*b)->dai_end = 0; | |
2322 } | |
2323 } | |
2324 } | |
2325 if (sp1->status == WNN_CONNECT) | |
2326 { | |
2327 (*b0)->dai_top = 0; | |
2328 } | |
2329 else | |
2330 { | |
2331 (*b0)->dai_top = 1; | |
2332 } | |
2333 (*b0)->daihyoka = dp[k].hyoka; | |
2334 } | |
2335 if (zenp == ZENKOUHO) | |
2336 { | |
2337 buf->zenkouho_dai[m] = b - buf->zenkouho; | |
2338 buf->zenkouho_suu = b - buf->zenkouho; | |
2339 buf->zenkouho_dai_suu = m; | |
2340 } | |
2341 return (cnt + bun_no); | |
2342 } | |
2343 | |
2344 static void | |
2345 set_sho (b, p) | |
2346 register WNN_BUN *b; | |
2347 register WNN_BUN **p; | |
2348 { | |
2349 b->ref_cnt++; | |
2350 *p = b; | |
2351 } | |
2352 | |
2353 static void | |
2354 set_dai (b, p, n) | |
2355 register WNN_BUN **b; | |
2356 register WNN_BUN **p; | |
2357 register int n; | |
2358 { | |
2359 for (; n; n--) | |
2360 { | |
2361 (*b)->ref_cnt++; | |
2362 *p++ = *b++; | |
2363 } | |
2364 } | |
2365 | |
2366 static int | |
2367 get_c_jikouho_from_zenkouho (buf, dest) | |
2368 struct wnn_buf *buf; | |
2369 WNN_BUN *dest; | |
2370 { | |
2371 register int k; | |
2372 w_char area[LENGTHKANJI]; | |
2373 w_char area1[LENGTHKANJI]; | |
2374 register WNN_BUN *b; | |
2375 | |
2376 wnn_area (dest, area, WNN_KANJI); | |
2377 for (k = 0; k < buf->zenkouho_suu; k++) | |
2378 { | |
2379 b = buf->zenkouho[k]; | |
2380 if (b->entry == dest->entry && b->dic_no == dest->dic_no) | |
2381 { | |
2382 wnn_area (b, area1, WNN_KANJI); | |
2383 if (wnn_Strcmp (area, area1) == 0) | |
2384 { | |
2385 return (k); | |
2386 } | |
2387 } | |
2388 } | |
2389 return (-1); | |
2390 } | |
2391 | |
2392 static int | |
2393 get_c_jikouho_from_zenkouho_dai (buf, dest) | |
2394 struct wnn_buf *buf; | |
2395 WNN_BUN *dest; | |
2396 { | |
2397 register int k; | |
2398 w_char area[LENGTHKANJI]; | |
2399 w_char area1[LENGTHKANJI]; | |
2400 register WNN_BUN *b; | |
2401 register int l; | |
2402 | |
2403 wnn_area (dest, area, WNN_KANJI); | |
2404 for (k = 0; k < buf->zenkouho_dai_suu; k++) | |
2405 { | |
2406 b = buf->zenkouho[buf->zenkouho_dai[k]]; | |
2407 for (l = 0; l < buf->zenkouho_dai[k + 1]; l++, dest++, b++) | |
2408 { | |
2409 if (b->entry != dest->entry || b->dic_no != dest->dic_no) | |
2410 break; | |
2411 wnn_area (b, area1, WNN_KANJI); | |
2412 if (wnn_Strcmp (area, area1) != 0) | |
2413 { | |
2414 break; | |
2415 } | |
2416 } | |
2417 if (l == buf->zenkouho_dai[k + 1]) | |
2418 { | |
2419 return (k); | |
2420 } | |
2421 } | |
2422 return (-1); | |
2423 } | |
2424 | |
2425 | |
2426 static int | |
2427 get_c_jikouho (sp, cnt, dest) | |
2428 struct wnn_sho_bunsetsu *sp; | |
2429 int cnt; | |
2430 WNN_BUN *dest; | |
2431 { | |
2432 register int k; | |
2433 register int len; | |
2434 w_char area[LENGTHKANJI]; | |
2435 | |
2436 wnn_area (dest, area, WNN_KANJI); | |
2437 for (k = 0; k < cnt; k++, sp++) | |
2438 { | |
2439 if (sp->entry == dest->entry && sp->dic_no == dest->dic_no && sp->kangovect == dest->kangovect) | |
2440 { | |
2441 if (wnn_Strncmp (area, sp->kanji, len = wnn_Strlen (sp->kanji)) == 0 && wnn_Strcmp (area + len, sp->fuzoku) == 0) | |
2442 { | |
2443 return (k); | |
2444 } | |
2445 } | |
2446 } | |
2447 return (-1); | |
2448 } | |
2449 | |
2450 static int | |
2451 get_c_jikouho_dai (dp, cnt, dest, bun_no) | |
2452 struct wnn_dai_bunsetsu *dp; | |
2453 int cnt; | |
2454 WNN_BUN **dest; | |
2455 int bun_no; | |
2456 { | |
2457 register int k, l; | |
2458 register int len; | |
2459 w_char area[LENGTHKANJI]; | |
2460 register struct wnn_sho_bunsetsu *sp; | |
2461 | |
2462 for (k = 0; k < cnt; k++, dp++) | |
2463 { | |
2464 sp = dp->sbn; | |
2465 for (l = 0; l < dp->sbncnt; l++, sp++) | |
2466 { | |
2467 if (sp->entry != (dest[bun_no + l])->entry || sp->kangovect != (dest[bun_no + l])->kangovect || sp->dic_no != (dest[bun_no + l])->dic_no) | |
2468 { | |
2469 break; | |
2470 } | |
2471 wnn_area (dest[bun_no + l], area, WNN_KANJI); | |
2472 if (wnn_Strncmp (area, sp->kanji, len = wnn_Strlen (sp->kanji)) != 0 || wnn_Strcmp (area + len, sp->fuzoku) != 0) | |
2473 { | |
2474 break; | |
2475 } | |
2476 } | |
2477 if (l == dp->sbncnt) | |
2478 return (k); | |
2479 } | |
2480 return (-1); | |
2481 } | |
2482 | |
2483 | |
2484 static int | |
2485 find_same_kouho (sp, st, end, level) | |
2486 struct wnn_sho_bunsetsu *sp; | |
2487 register WNN_BUN **st, **end; | |
2488 int level; | |
2489 { | |
2490 register int len; | |
2491 w_char area[LENGTHKANJI]; | |
2492 register WNN_BUN *b; | |
2493 | |
2494 if (level == WNN_UNIQ) | |
2495 { | |
2496 for (; st < end; st++) | |
2497 { | |
2498 b = *st; | |
2499 if (sp->hinsi == b->hinsi) | |
2500 { | |
2501 wnn_area (b, area, WNN_KANJI); | |
2502 if (wnn_Strncmp (area, sp->kanji, len = wnn_Strlen (sp->kanji)) == 0 && wnn_Strcmp (area + len, sp->fuzoku) == 0) | |
2503 { | |
2504 return (1); | |
2505 } | |
2506 } | |
2507 } | |
2508 } | |
2509 else | |
2510 { /* level = WNN_UNIQ_KNJ */ | |
2511 for (; st < end; st++) | |
2512 { | |
2513 b = *st; | |
2514 wnn_area (b, area, WNN_KANJI); | |
2515 if (wnn_Strncmp (area, sp->kanji, len = wnn_Strlen (sp->kanji)) == 0 && wnn_Strcmp (area + len, sp->fuzoku) == 0) | |
2516 { | |
2517 return (1); | |
2518 } | |
2519 } | |
2520 } | |
2521 return (0); | |
2522 } | |
2523 | |
2524 static int | |
2525 find_same_kouho_dai (dp, buf, top, level) | |
2526 struct wnn_dai_bunsetsu *dp; | |
2527 struct wnn_buf *buf; | |
2528 int top; | |
2529 int level; | |
2530 { | |
2531 int len; | |
2532 register int k, l; | |
2533 w_char area[LENGTHKANJI]; | |
2534 WNN_BUN *b; | |
2535 register struct wnn_sho_bunsetsu *sp; | |
2536 | |
2537 for (k = 0; k < top; k++) | |
2538 { | |
2539 for (l = 0, sp = dp->sbn; l < dp->sbncnt; l++, sp++) | |
2540 { | |
2541 b = buf->zenkouho[buf->zenkouho_dai[k] + l]; | |
2542 if (sp->end - sp->start + 1 != b->yomilen) | |
2543 break; /* From: tsuiki */ | |
2544 if (level != WNN_UNIQ_KNJ) | |
2545 { | |
2546 if (sp->hinsi != b->hinsi) | |
2547 break; | |
2548 } | |
2549 wnn_area (b, area, WNN_KANJI); | |
2550 if (wnn_Strncmp (area, sp->kanji, len = wnn_Strlen (sp->kanji)) != 0 || wnn_Strcmp (area + len, sp->fuzoku) != 0) | |
2551 { | |
2552 break; | |
2553 } | |
2554 } | |
2555 if (l == dp->sbncnt) | |
2556 return (1); | |
2557 } | |
2558 return (0); | |
2559 } | |
2560 | |
2561 int | |
2562 wnn_cnt_free (buf) | |
2563 struct wnn_buf *buf; | |
2564 { | |
2565 register int n; | |
2566 register WNN_BUN *b; | |
2567 | |
2568 for (n = 0, b = buf->free_heap; b; n++, b = b->free_next); | |
2569 return (n); | |
2570 } | |
2571 | |
2572 | |
2573 struct wnn_jdata * | |
2574 jl_word_info_e (env, dic_no, entry) | |
2575 register struct wnn_env *env; | |
2576 int dic_no, entry; | |
2577 { | |
2578 wnn_errorno = 0; | |
2579 if (js_word_info (env, dic_no, entry, &wordrb) < 0) | |
2580 if_dead_disconnect (env, NULL); | |
2581 return ((struct wnn_jdata *) (wordrb.buf)); | |
2582 } | |
2583 | |
2584 int | |
2585 jl_dic_list_e (env, dicinfo) | |
2586 struct wnn_env *env; | |
2587 WNN_DIC_INFO **dicinfo; | |
2588 { | |
2589 WNN_DIC_INFO *info; | |
2590 int cnt; | |
2591 register int k; | |
2592 register char *c; | |
2593 | |
2594 wnn_errorno = 0; | |
2595 if ((cnt = js_dic_list (env, &dicrb)) < 0) | |
2596 if_dead_disconnect (env, -1); | |
2597 info = (WNN_DIC_INFO *) (dicrb.buf); | |
2598 | |
2599 /* If the file is loaded from this client, change the file name to the one | |
2600 used in loading it. */ | |
2601 for (k = 0; k < cnt; k++) | |
2602 { | |
2603 c = find_file_name_from_id (env, info[k].body); | |
2604 if (c != NULL) | |
2605 { | |
2606 strcpy (info[k].fname, c); | |
2607 } | |
2608 | |
2609 c = find_file_name_from_id (env, info[k].hindo); | |
2610 if (c != NULL) | |
2611 { | |
2612 strcpy (info[k].hfname, c); | |
2613 } | |
2614 } | |
2615 *dicinfo = info; | |
2616 return (cnt); | |
2617 } | |
2618 | |
2619 | |
2620 static int | |
2621 sort_func_ws (a, b) | |
2622 register char *a, *b; | |
2623 { | |
2624 int ah, bh, ai, bi, iah, ibh, iai, ibi; | |
2625 ah = ((struct wnn_jdata *) a)->hindo; | |
2626 bh = ((struct wnn_jdata *) b)->hindo; | |
2627 iah = ((struct wnn_jdata *) a)->int_hindo; | |
2628 ibh = ((struct wnn_jdata *) b)->int_hindo; | |
2629 ai = ((struct wnn_jdata *) a)->ima; | |
2630 bi = ((struct wnn_jdata *) b)->ima; | |
2631 iai = ((struct wnn_jdata *) a)->int_ima; | |
2632 ibi = ((struct wnn_jdata *) b)->int_ima; | |
2633 | |
2634 if (ai == WNN_IMA_OFF && ah == WNN_ENTRY_NO_USE) | |
2635 return (1); | |
2636 if (bi == WNN_IMA_OFF && bh == WNN_ENTRY_NO_USE) | |
2637 return (-1); | |
2638 if (iai == WNN_IMA_OFF && iah == WNN_ENTRY_NO_USE) | |
2639 return (1); | |
2640 if (ibi == WNN_IMA_OFF && ibh == WNN_ENTRY_NO_USE) | |
2641 return (-1); | |
2642 | |
2643 if (ai != bi) | |
2644 { | |
2645 if (ai < bi) | |
2646 return (1); | |
2647 return (-1); | |
2648 } | |
2649 if (iah >= 0) | |
2650 { | |
2651 ah += iah; | |
2652 bh += ibh; | |
2653 } | |
2654 if (ah > bh) | |
2655 return (-1); | |
2656 if (ah < bh) | |
2657 return (1); | |
2658 return (0); | |
2659 } | |
2660 | |
2661 int | |
2662 jl_word_search_e (env, dic_no, yomi, jdp) | |
2663 register struct wnn_env *env; | |
2664 int dic_no; | |
2665 w_char *yomi; | |
2666 struct wnn_jdata **jdp; | |
2667 { | |
2668 register int cnt; | |
2669 struct wnn_jdata *jd; | |
2670 | |
2671 wnn_errorno = 0; | |
2672 if ((cnt = js_word_search (env, dic_no, yomi, &wordrb)) < 0) | |
2673 if_dead_disconnect (env, -1); | |
2674 jd = (struct wnn_jdata *) wordrb.buf; | |
2675 /* for(cnt = 0 ; jd[cnt].dic_no != -1; cnt++); */ | |
2676 qsort ((char *) jd, cnt, sizeof (struct wnn_jdata), sort_func_ws); | |
2677 *jdp = jd; | |
2678 return (cnt); | |
2679 } | |
2680 | |
2681 int | |
2682 jl_word_search_by_env_e (env, yomi, jdp) | |
2683 register struct wnn_env *env; | |
2684 struct wnn_jdata **jdp; | |
2685 w_char *yomi; | |
2686 { | |
2687 register int cnt; | |
2688 struct wnn_jdata *jd; | |
2689 | |
2690 wnn_errorno = 0; | |
2691 if ((cnt = js_word_search_by_env (env, yomi, &wordrb)) < 0) | |
2692 if_dead_disconnect (env, -1); | |
2693 jd = (struct wnn_jdata *) wordrb.buf; | |
2694 /* for(cnt = 0 ; jd[cnt].dic_no != -1; cnt++); */ | |
2695 qsort ((char *) jd, cnt, sizeof (struct wnn_jdata), sort_func_ws); | |
2696 *jdp = jd; | |
2697 return (cnt); | |
2698 } | |
2699 | |
2700 #ifdef JL_DEBUG | |
2701 static void | |
2702 display_bun (b) | |
2703 WNN_BUN *b; | |
2704 { | |
2705 w_char yomi[LENGTHBUNSETSU]; | |
2706 wnn_area (b, yomi, 1); | |
2707 putws (yomi); | |
2708 printf ("\t"); | |
2709 wnn_area (b, yomi, 0); | |
2710 putws (yomi); | |
2711 printf ("\t"); | |
2712 printf ("Jirilen:%d Dic_no:%d Serial:%d Hinsi:%d Hindo:%c%d\n Hindo_Updated:%d Nobi_Top:%d Dai_top:%d Ref_cnt:%d Down:%d\n", | |
2713 b->jirilen, b->dic_no, b->entry, b->hinsi, (b->ima) ? '*' : ' ', b->hindo, b->hindo_updated, b->nobi_top, b->dai_top, b->ref_cnt, b->down); | |
2714 } | |
2715 #endif | |
2716 | |
2717 | |
2718 static void | |
2719 add_down_bnst (buf, k, b) | |
2720 register struct wnn_buf *buf; | |
2721 register int k; | |
2722 register WNN_BUN *b; | |
2723 { | |
2724 if (b->down) | |
2725 return; /* In order to prevent roop! */ | |
2726 if (b == buf->down_bnst[k]) | |
2727 return; /* In order to prevent roop! */ | |
2728 /* It occurs when Zenkouho-->Nobi-conv */ | |
2729 b->down = buf->down_bnst[k]; | |
2730 buf->down_bnst[k] = b; | |
2731 b->ref_cnt++; | |
2732 } | |
2733 | |
2734 #ifdef JL_DEBUG | |
2735 static void | |
2736 print_jdata (jd) | |
2737 struct wnn_jdata *jd; | |
2738 { | |
2739 putws (jd->kanji); | |
2740 printf ("\tDict:%d Serial:%d Hinsi:%s Hindo:%c%d ExHindo:%c%d\n", | |
2741 jd->dic_no, jd->serial, wnn_get_hinsi_name (jd->hinshi), (jd->ima) ? '*' : ' ', jd->hindo, (jd->int_ima) ? '*' : ' ', jd->int_hindo); | |
2742 } | |
2743 #endif | |
2744 | |
2745 #define REAL_PARAM(x) (strcmp(x, "-")) | |
2746 | |
2747 | |
2748 /** wnnrc を見てのパラメータの設定 */ | |
2749 int | |
2750 jl_set_env_wnnrc (env, wnnrc_n, error_handler, message_handler) | |
2751 register struct wnn_env *env; | |
2752 char *wnnrc_n; | |
2753 int (*error_handler) (), (*message_handler) (); | |
2754 { | |
2755 int level = 0; | |
2756 int x; | |
2757 wnn_errorno = 0; | |
2758 if ((int) error_handler == WNN_CREATE) | |
2759 { | |
2760 confirm_state = CREATE_WITHOUT_CONFIRM; | |
2761 } | |
2762 else if ((int) error_handler == WNN_NO_CREATE) | |
2763 { | |
2764 confirm_state = NO_CREATE; | |
2765 } | |
2766 else | |
2767 { | |
2768 confirm_state = CONFIRM; | |
2769 } | |
2770 x = jl_set_env_wnnrc1 (env, wnnrc_n, error_handler, message_handler, level); | |
2771 confirm_state = 0; | |
2772 return (x); | |
2773 } | |
2774 | |
2775 int | |
2776 jl_set_env_wnnrc1 (env, wnnrc_n, error_handler, message_handler, level) | |
2777 register struct wnn_env *env; | |
2778 char *wnnrc_n; | |
2779 int (*error_handler) (), (*message_handler) (); | |
2780 int level; | |
2781 { | |
2782 register int num; | |
2783 char s[20][EXPAND_PATH_LENGTH]; | |
2784 char code[EXPAND_PATH_LENGTH]; | |
2785 char tmp[1024]; | |
2786 register FILE *fp; | |
2787 | |
2788 wnn_errorno = 0; | |
2789 if (level > MAXINCLUDE) | |
2790 { | |
2791 message_out (message_handler, msg_get (wnn_msg_cat, 206, NULL, env->lang)); | |
2792 /* | |
2793 "include のレベルが多過ぎます。" | |
2794 */ | |
2795 return (-1); | |
2796 } | |
2797 if ((fp = fopen (wnnrc_n, "r")) == NULL) | |
2798 { | |
2799 message_out (message_handler, msg_get (wnn_msg_cat, 207, NULL, env->lang), wnnrc_n); | |
2800 /* | |
2801 "file \"%s\"が open できません", | |
2802 */ | |
2803 return (-1); | |
2804 } | |
2805 while (fgets (tmp, 1024, fp) != NULL) | |
2806 { | |
2807 num = sscanf (tmp, | |
2808 "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", code, | |
2809 s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15], s[16], s[17], s[18], s[19]); | |
2810 if (num <= 0) | |
2811 { | |
2812 continue; | |
2813 } | |
2814 if (code[0] == ';') | |
2815 { | |
2816 continue; | |
2817 | |
2818 } | |
2819 else if (strcmp (code, "include") == 0) | |
2820 { | |
2821 expand_expr_all (s[0], env); | |
2822 if (jl_set_env_wnnrc1 (env, s[0], error_handler, message_handler, level + 1) == -1) | |
2823 { | |
2824 fclose (fp); | |
2825 return (-1); | |
2826 } | |
2827 } | |
2828 else if (strcmp (code, "setdic") == 0) | |
2829 { | |
2830 /* dic_add */ | |
2831 int prio, rdonly, hrdonly, rev; | |
2832 int (*error_handler1) () = (int (*)()) 0; | |
2833 expand_expr_all (s[0], env); | |
2834 if (num < 3 || !REAL_PARAM (s[1])) | |
2835 { | |
2836 s[1][0] = 0; | |
2837 } | |
2838 else | |
2839 { | |
2840 expand_expr_all (s[1], env); | |
2841 } | |
2842 prio = (num >= 4 && REAL_PARAM (s[2])) ? atoi (s[2]) : WNN_DIC_PRIO_DEFAULT; | |
2843 rdonly = (num >= 5 && REAL_PARAM (s[3])) ? atoi (s[3]) : 0; | |
2844 hrdonly = (num >= 6 && REAL_PARAM (s[4])) ? atoi (s[4]) : 0; | |
2845 if (num < 7 || !REAL_PARAM (s[5])) | |
2846 s[5][0] = 0; | |
2847 if (num < 8 || !REAL_PARAM (s[6])) | |
2848 s[6][0] = 0; | |
2849 rev = (num >= 9 && REAL_PARAM (s[7])) ? atoi (s[7]) : 0; | |
2850 | |
2851 if (confirm_state == CONFIRM || confirm_state == CONFIRM1) | |
2852 { | |
2853 error_handler1 = error_handler; | |
2854 } | |
2855 else if (confirm_state == CREATE_WITHOUT_CONFIRM) | |
2856 { | |
2857 | |
2858 error_handler1 = (int (*)()) WNN_CREATE; | |
2859 } | |
2860 else if (confirm_state == NO_CREATE) | |
2861 { | |
2862 error_handler1 = (int (*)()) WNN_NO_CREATE; | |
2863 } | |
2864 if (jl_dic_add_e (env, s[0], s[1], rev, prio, rdonly, hrdonly, s[5], s[6], error_handler1, message_handler) == -1 && wnn_errorno != 0) | |
2865 { | |
2866 if (wnn_errorno != WNN_JSERVER_DEAD) | |
2867 message_out (message_handler, "%s (%s) :%s\n", s[0], s[1], wnn_perror_lang (env->lang)); | |
2868 else | |
2869 message_out (message_handler, "%s\n", wnn_perror_lang (env->lang)); | |
2870 goto _Err_happend; | |
2871 } | |
2872 | |
2873 } | |
2874 else if ((strcmp (code, "setfuzokugo") == 0) || (strcmp (code, "setgrammar") == 0)) | |
2875 { | |
2876 /* fuzokugo_set */ | |
2877 expand_expr_all (s[0], env); | |
2878 if (jl_fuzokugo_set_e (env, s[0]) == -1) | |
2879 { | |
2880 if (wnn_errorno != WNN_JSERVER_DEAD) | |
2881 message_out (message_handler, "%s :%s\n", s[0], wnn_perror_lang (env->lang)); | |
2882 else | |
2883 message_out (message_handler, "%s\n", wnn_perror_lang (env->lang)); | |
2884 goto _Err_happend; | |
2885 } | |
2886 } | |
2887 else if (strcmp (code, "setparam") == 0) | |
2888 { | |
2889 struct wnn_param para; | |
2890 /* setparam --- set parameter */ | |
2891 change_ascii_to_int (s[0], ¶.n); | |
2892 change_ascii_to_int (s[1], ¶.nsho); | |
2893 change_ascii_to_int (s[2], ¶.p1); | |
2894 change_ascii_to_int (s[3], ¶.p2); | |
2895 change_ascii_to_int (s[4], ¶.p3); | |
2896 change_ascii_to_int (s[5], ¶.p4); | |
2897 change_ascii_to_int (s[6], ¶.p5); | |
2898 change_ascii_to_int (s[7], ¶.p6); | |
2899 change_ascii_to_int (s[8], ¶.p7); | |
2900 change_ascii_to_int (s[9], ¶.p8); | |
2901 | |
2902 change_ascii_to_int (s[10], ¶.p9); | |
2903 change_ascii_to_int (s[11], ¶.p10); | |
2904 change_ascii_to_int (s[12], ¶.p11); | |
2905 change_ascii_to_int (s[13], ¶.p12); | |
2906 change_ascii_to_int (s[14], ¶.p13); | |
2907 change_ascii_to_int (s[15], ¶.p14); | |
2908 change_ascii_to_int (s[16], ¶.p15); | |
2909 | |
2910 if (js_param_set (env, ¶) < 0) | |
2911 { | |
2912 fclose (fp); | |
2913 message_out (message_handler, msg_get (wnn_msg_cat, 208, NULL, env->lang), wnnrc_n); | |
2914 /* | |
2915 "ファイル \"%s\" で環境設定中に、エラーが発生したために、設定を中止します。\n", | |
2916 */ | |
2917 if_dead_disconnect (env, -1); | |
2918 } | |
2919 } | |
2920 else if (strcmp (code, "confirm") == 0) | |
2921 { | |
2922 confirm_state = CONFIRM; | |
2923 } | |
2924 else if (strcmp (code, "confirm1") == 0) | |
2925 { | |
2926 confirm_state = CONFIRM1; | |
2927 } | |
2928 else if (strcmp (code, "create_without_confirm") == 0) | |
2929 { | |
2930 confirm_state = CREATE_WITHOUT_CONFIRM; | |
2931 } | |
2932 else if (strcmp (code, "no_create") == 0) | |
2933 { | |
2934 confirm_state = NO_CREATE; | |
2935 } | |
2936 } | |
2937 fclose (fp); | |
2938 return (0); | |
2939 | |
2940 _Err_happend: | |
2941 message_out (message_handler, msg_get (wnn_msg_cat, 208, NULL, env->lang), wnnrc_n); | |
2942 /* | |
2943 "ファイル \"%s\" で環境設定中に、エラーが発生したために、設定を中止します。\n", | |
2944 */ | |
2945 fclose (fp); | |
2946 return (-1); | |
2947 } | |
2948 | |
2949 static int | |
2950 expand_expr_all (s, env) | |
2951 struct wnn_env *env; | |
2952 register char *s; | |
2953 { | |
2954 register char *c; | |
2955 | |
2956 for (c = s; *c; c++) | |
2957 { | |
2958 if (*c == '~' || *c == '@') | |
2959 { | |
2960 if (expand_expr (c, env) == -1) | |
2961 return (-1); | |
2962 } | |
2963 } | |
2964 return (0); | |
2965 } | |
2966 | |
2967 /* copy of js.c */ | |
2968 static char * | |
2969 getlogname () | |
2970 { | |
2971 struct passwd *getpwuid (); | |
2972 return getpwuid (getuid ())->pw_name; | |
2973 } | |
2974 | |
2975 | |
2976 static int | |
2977 expand_expr (s, env) | |
2978 struct wnn_env *env; | |
2979 /** ~user、@HOME、@LIBDIR @ENV @USR の展開(但し、文字列の先頭のみ)。 | |
2980 できない時は-1が | |
2981 返り、その場合sの中身は着々とそのまんま。sの長さ<256と仮定してる。*/ | |
2982 register char *s; | |
2983 { | |
2984 char *p, *s1; | |
2985 char tmp[EXPAND_PATH_LENGTH]; | |
2986 int noerr, expandsuc; | |
2987 struct passwd *u; | |
2988 extern char *getenv (); | |
2989 extern struct passwd *getpwnam (); | |
2990 | |
2991 if (*s != '~' && *s != '@') | |
2992 return (0); | |
2993 if ((int) strlen (s) >= EXPAND_PATH_LENGTH) | |
2994 return (-1); | |
2995 | |
2996 s1 = s; | |
2997 if (NULL != (p = strchr (++s1, '/'))) | |
2998 { | |
2999 strcpy (tmp, p); | |
3000 *p = '\0'; | |
3001 } | |
3002 else | |
3003 *tmp = '\0'; | |
3004 /* ここまでは準備。s…先頭、s1…2文字目、p…最初の'/'のあったところ | |
3005 (ここで一旦切る)、tmp…それ以後のコピー。 */ | |
3006 | |
3007 if (*s == '~') | |
3008 { | |
3009 if (*s1) | |
3010 { | |
3011 noerr = expandsuc = (NULL != (u = getpwnam (s1)) && (int) strlen (p = u->pw_dir) + (int) strlen (tmp) < EXPAND_PATH_LENGTH); | |
3012 | |
3013 } | |
3014 else | |
3015 { | |
3016 noerr = expandsuc = (NULL != (p = getenv ("HOME")) && (int) strlen (p) + (int) strlen (tmp) < EXPAND_PATH_LENGTH); | |
3017 } | |
3018 | |
3019 } | |
3020 else | |
3021 { /* then, *s must be '@' */ | |
3022 if (!strcmp (s1, "HOME")) | |
3023 { | |
3024 noerr = expandsuc = (NULL != (p = getenv ("HOME")) && (int) strlen (p) + (int) strlen (tmp) < EXPAND_PATH_LENGTH); | |
3025 } | |
3026 else if (!strcmp (s1, "WNN_DIC_DIR")) | |
3027 { | |
3028 char buf[EXPAND_PATH_LENGTH]; | |
3029 expandsuc = 1; | |
3030 noerr = (NULL != (p = getenv ("HOME")) && (int) strlen (p) + (int) strlen (tmp) < EXPAND_PATH_LENGTH); | |
3031 strcpy (buf, p); | |
3032 strcat (buf, "/"); | |
3033 | |
3034 p = getenv ("WNN_DIC_DIR"); | |
3035 if (p) | |
3036 { | |
3037 strcat (buf, p); | |
3038 } | |
3039 else | |
3040 { | |
3041 strcat (buf, "Wnn"); | |
3042 } | |
3043 p = buf; | |
3044 } | |
3045 else if (!strcmp (s1, "LIBDIR")) | |
3046 { | |
3047 noerr = expandsuc = ((int) strlen (p = LIBDIR) + (int) strlen (tmp) < EXPAND_PATH_LENGTH); | |
3048 } | |
3049 else if (!strcmp (s1, "ENV")) | |
3050 { /* Added */ | |
3051 noerr = expandsuc = (NULL != (p = env_name (env)) && (int) strlen (p) + (int) strlen (tmp) < EXPAND_PATH_LENGTH); | |
3052 } | |
3053 else if (!strcmp (s1, "USR")) | |
3054 { | |
3055 noerr = expandsuc = (NULL != (p = getlogname ()) && (int) strlen (p) + (int) strlen (tmp) < EXPAND_PATH_LENGTH); | |
3056 } | |
3057 else | |
3058 { /* @HOME, @LIBDIR @ENV igai ha kaenai */ | |
3059 noerr = 1; | |
3060 expandsuc = 0; | |
3061 } | |
3062 } | |
3063 | |
3064 if (expandsuc) | |
3065 strcpy (s, p); | |
3066 strcat (s, tmp); | |
3067 return (noerr ? 0 : -1); | |
3068 } | |
3069 | |
3070 static int | |
3071 change_ascii_to_int (st, dp) | |
3072 register char *st; | |
3073 int *dp; | |
3074 { | |
3075 register int total, flag; | |
3076 | |
3077 total = 0; | |
3078 flag = 0; | |
3079 while (*st != NULL) | |
3080 { | |
3081 if (isdigit (*st)) | |
3082 { | |
3083 total = total * 10 + (*st - '0'); | |
3084 } | |
3085 else if (*st == '+') | |
3086 { | |
3087 if (flag != 0) | |
3088 { | |
3089 return (-1); | |
3090 } | |
3091 flag = 1; | |
3092 } | |
3093 else if (*st == '-') | |
3094 { | |
3095 if (flag != 0) | |
3096 { | |
3097 return (-1); | |
3098 } | |
3099 flag = -1; | |
3100 } | |
3101 else | |
3102 { | |
3103 return (-1); | |
3104 } | |
3105 st++; | |
3106 } | |
3107 if (flag == 0) | |
3108 { | |
3109 flag = 1; | |
3110 } | |
3111 *dp = total * flag; | |
3112 return (1); | |
3113 } | |
3114 | |
3115 static int | |
3116 file_exist (env, n) | |
3117 struct wnn_env *env; | |
3118 char *n; | |
3119 { | |
3120 if (n[0] == C_LOCAL) | |
3121 { | |
3122 wnn_errorno = 0; | |
3123 return (access (n + 1, 4)); | |
3124 } | |
3125 else | |
3126 { | |
3127 return (js_access (env, n, 4)); | |
3128 } | |
3129 } | |
3130 | |
3131 static int | |
3132 create_file (env, n, d, fid, pwd_dic, pwd_hindo, error_handler, message_handler) | |
3133 register struct wnn_env *env; | |
3134 char *n; | |
3135 int d; | |
3136 int fid; | |
3137 char *pwd_dic, *pwd_hindo; | |
3138 int (*error_handler) (), (*message_handler) (); | |
3139 { | |
3140 char pwd[WNN_PASSWD_LEN], hpwd[WNN_PASSWD_LEN]; | |
3141 int rev_dict_type; | |
3142 | |
3143 if (make_dir_rec1 (env, n, error_handler, message_handler) == -1) | |
3144 { | |
3145 wnn_errorno = WNN_MKDIR_FAIL; | |
3146 return (-1); | |
3147 } | |
3148 if (d == HINDO) | |
3149 { | |
3150 if (create_pwd_file (env, pwd_hindo, error_handler, message_handler) == -1) | |
3151 return (-1); | |
3152 if (get_pwd (pwd_hindo, hpwd) == -1) | |
3153 return (-1); | |
3154 if (n[0] == C_LOCAL) | |
3155 { | |
3156 if (js_hindo_file_create_client (env, fid, n + 1, NULL, hpwd) == -1) | |
3157 { | |
3158 message_out (message_handler, wnn_perror_lang (env->lang)); | |
3159 if_dead_disconnect (env, -1); | |
3160 } | |
3161 else | |
3162 { | |
3163 message_out (message_handler, "%s \"%s\" %s", msg_get (wnn_msg_cat, 203, NULL, env->lang), n, msg_get (wnn_msg_cat, 209, NULL, env->lang)); | |
3164 /* | |
3165 "頻度ファイル \"%s\" を作りました。", | |
3166 */ | |
3167 chown (n + 1, getuid (), -1); /* H.T. */ | |
3168 return (0); | |
3169 } | |
3170 } | |
3171 else | |
3172 { | |
3173 if (js_hindo_file_create (env, fid, n, NULL, hpwd) == -1) | |
3174 { | |
3175 message_out (message_handler, wnn_perror_lang (env->lang)); | |
3176 if_dead_disconnect (env, -1); | |
3177 } | |
3178 else | |
3179 { | |
3180 message_out (message_handler, "%s \"%s\" %s", msg_get (wnn_msg_cat, 203, NULL, env->lang), n, msg_get (wnn_msg_cat, 209, NULL, env->lang)); | |
3181 /* | |
3182 "頻度ファイル \"%s\" を作りました。", | |
3183 */ | |
3184 return (0); | |
3185 } | |
3186 } | |
3187 } | |
3188 else | |
3189 { | |
3190 if (create_pwd_file (env, pwd_hindo, error_handler, message_handler) == -1) | |
3191 return (-1); | |
3192 if (get_pwd (pwd_hindo, hpwd) == -1) | |
3193 return (-1); | |
3194 if (create_pwd_file (env, pwd_dic, error_handler, message_handler) == -1) | |
3195 return (-1); | |
3196 if (get_pwd (pwd_dic, pwd) == -1) | |
3197 return (-1); | |
3198 | |
3199 #ifdef CONVERT_with_SiSheng | |
3200 if (!strncmp (js_get_lang (env), WNN_C_LANG, 5) || !strncmp (js_get_lang (env), WNN_T_LANG, 5)) | |
3201 rev_dict_type = CWNN_REV_DICT; | |
3202 else | |
3203 #endif | |
3204 rev_dict_type = WNN_REV_DICT; | |
3205 | |
3206 if (n[0] == C_LOCAL) | |
3207 { | |
3208 if (js_dic_file_create_client (env, n + 1, rev_dict_type, NULL, pwd, hpwd) == -1) | |
3209 { | |
3210 message_out (message_handler, wnn_perror_lang (env->lang)); | |
3211 if_dead_disconnect (env, -1); | |
3212 } | |
3213 else | |
3214 { | |
3215 message_out (message_handler, "%s \"%s\" %s", msg_get (wnn_msg_cat, 200, NULL, env->lang), n, msg_get (wnn_msg_cat, 209, NULL, env->lang)); | |
3216 /* | |
3217 "辞書ファイル \"%s\" を作りました。", | |
3218 */ | |
3219 chown (n + 1, getuid (), -1); | |
3220 return (0); | |
3221 } | |
3222 } | |
3223 else | |
3224 { | |
3225 if (js_dic_file_create (env, n, rev_dict_type, NULL, pwd, hpwd) == -1) | |
3226 { | |
3227 message_out (message_handler, wnn_perror_lang (env->lang)); | |
3228 if_dead_disconnect (env, -1); | |
3229 } | |
3230 else | |
3231 { | |
3232 message_out (message_handler, "%s \"%s\" %s", msg_get (wnn_msg_cat, 200, NULL, env->lang), n, msg_get (wnn_msg_cat, 209, NULL, env->lang)); | |
3233 /* | |
3234 "辞書ファイル \"%s\" を作りました。", | |
3235 */ | |
3236 return (0); | |
3237 } | |
3238 } | |
3239 } | |
3240 } | |
3241 | |
3242 static int | |
3243 make_dir_rec1 (env, path, error_handler, message_handler) | |
3244 struct wnn_env *env; | |
3245 register char *path; | |
3246 int (*error_handler) (), (*message_handler) (); | |
3247 { | |
3248 char gomi[128]; | |
3249 register char *c; | |
3250 for (c = path; *c; c++) | |
3251 { | |
3252 if (*c == '/') | |
3253 { | |
3254 strncpy (gomi, path, c - path); | |
3255 gomi[c - path] = 0; | |
3256 if (make_dir1 (env, gomi, error_handler, message_handler) == -1) | |
3257 { | |
3258 return (-1); | |
3259 } | |
3260 } | |
3261 } | |
3262 return (0); | |
3263 } | |
3264 | |
3265 static int | |
3266 make_dir1 (env, dirname, error_handler, message_handler) | |
3267 register struct wnn_env *env; | |
3268 register char *dirname; | |
3269 int (*error_handler) (), (*message_handler) (); | |
3270 { | |
3271 char gomi[128]; | |
3272 if (dirname[0] == C_LOCAL) | |
3273 { | |
3274 if (*(dirname + 1) == 0) | |
3275 return (0); | |
3276 if (access (dirname + 1, 0) == 0) | |
3277 { /* check for existence */ | |
3278 return (0); /* dir already exists */ | |
3279 } | |
3280 } | |
3281 else | |
3282 { | |
3283 if (*dirname == 0) | |
3284 return (0); | |
3285 if (js_access (env, dirname, 0) == 0) | |
3286 { /* check for existence */ | |
3287 return (0); /* dir already exists */ | |
3288 } | |
3289 } | |
3290 if ((int) error_handler != WNN_CREATE) | |
3291 { | |
3292 sprintf (gomi, "%s \"%s\" %s%s", msg_get (wnn_msg_cat, 210, NULL, env->lang), dirname, msg_get (wnn_msg_cat, 201, NULL, env->lang), msg_get (wnn_msg_cat, 202, NULL, env->lang)); | |
3293 /* | |
3294 "directry \"%s\" が無いよ。作る?(Y/N)", | |
3295 */ | |
3296 if (call_error_handler (error_handler, gomi) == 0) | |
3297 { | |
3298 wnn_errorno = WNN_MKDIR_FAIL; | |
3299 return (-1); | |
3300 } | |
3301 } | |
3302 if (dirname[0] == C_LOCAL) | |
3303 { /* Create Directory */ | |
3304 #define MODE (0000000 | 0000777) | |
3305 if (mkdir (dirname + 1, MODE) != 0) | |
3306 { | |
3307 wnn_errorno = WNN_MKDIR_FAIL; | |
3308 return (-1); | |
3309 } | |
3310 | |
3311 chmod (dirname + 1, MODE); | |
3312 chown (dirname + 1, getuid (), -1); | |
3313 } | |
3314 else | |
3315 { | |
3316 if (js_mkdir (env, dirname)) | |
3317 { | |
3318 if_dead_disconnect (env, -1); | |
3319 } | |
3320 } | |
3321 return (0); | |
3322 } | |
3323 | |
3324 | |
3325 static int | |
3326 call_error_handler (error_handler, c) | |
3327 int (*error_handler) (); | |
3328 char *c; | |
3329 { | |
3330 register int x; | |
3331 x = error_handler (c); | |
3332 if (confirm_state == CONFIRM1) | |
3333 { | |
3334 if (x) | |
3335 confirm_state = CREATE_WITHOUT_CONFIRM; | |
3336 else | |
3337 confirm_state = NO_CREATE; | |
3338 } | |
3339 return (x); | |
3340 } | |
3341 | |
3342 static void | |
3343 message_out (message_handler, format, s1, s2, s3, s4, s5, s6, s7, s8) | |
3344 int (*message_handler) (); | |
3345 char *format; | |
3346 int s1, s2, s3, s4, s5, s6, s7, s8; | |
3347 { | |
3348 char buf[256]; | |
3349 | |
3350 if (message_handler) | |
3351 { | |
3352 sprintf (buf, format, s1, s2, s3, s4, s5, s6, s7, s8); | |
3353 (*message_handler) (buf); | |
3354 } | |
3355 } | |
3356 | |
3357 | |
3358 int | |
3359 jl_yomi_len (buf, bun_no, bun_no2) | |
3360 struct wnn_buf *buf; | |
3361 register int bun_no, bun_no2; | |
3362 { | |
3363 register int len = 0; | |
3364 | |
3365 wnn_errorno = 0; | |
3366 if (bun_no2 >= buf->bun_suu || bun_no2 < 0) | |
3367 bun_no2 = buf->bun_suu; | |
3368 for (; bun_no < bun_no2; bun_no++) | |
3369 { | |
3370 len += buf->bun[bun_no]->yomilen; | |
3371 } | |
3372 return (len); | |
3373 } | |
3374 | |
3375 | |
3376 int | |
3377 jl_kanji_len (buf, bun_no, bun_no2) | |
3378 struct wnn_buf *buf; | |
3379 register int bun_no, bun_no2; | |
3380 { | |
3381 register int len = 0; | |
3382 | |
3383 wnn_errorno = 0; | |
3384 if (bun_no < 0) | |
3385 return (0); | |
3386 if (bun_no2 >= buf->bun_suu || bun_no2 < 0) | |
3387 bun_no2 = buf->bun_suu; | |
3388 for (; bun_no < bun_no2; bun_no++) | |
3389 { | |
3390 len += buf->bun[bun_no]->kanjilen; | |
3391 } | |
3392 return (len); | |
3393 } | |
3394 | |
3395 int wnn_word_use_initial_hindo = 0; | |
3396 | |
3397 int | |
3398 jl_word_use_e (env, dic_no, entry) | |
3399 register struct wnn_env *env; | |
3400 int dic_no, entry; | |
3401 { | |
3402 register struct wnn_jdata *jd; | |
3403 | |
3404 wnn_errorno = 0; | |
3405 if (js_word_info (env, dic_no, entry, &rb) == -1) | |
3406 if_dead_disconnect (env, -1); | |
3407 jd = (struct wnn_jdata *) (rb.buf); | |
3408 if (jd->hindo != -1) | |
3409 { | |
3410 if (js_hindo_set (env, dic_no, entry, WNN_IMA_OFF, WNN_ENTRY_NO_USE) == -1) | |
3411 { | |
3412 if_dead_disconnect (env, -1); | |
3413 } | |
3414 } | |
3415 else | |
3416 { | |
3417 if (js_hindo_set (env, dic_no, entry, (wnn_word_use_initial_hindo & 0x80) ? WNN_IMA_ON : WNN_IMA_OFF, wnn_word_use_initial_hindo & 0x7f) == -1) | |
3418 { | |
3419 if_dead_disconnect (env, -1); | |
3420 } | |
3421 } | |
3422 return (0); | |
3423 } | |
3424 | |
3425 void | |
3426 jl_env_set (buf, env) | |
3427 register struct wnn_env *env; | |
3428 register struct wnn_buf *buf; | |
3429 { | |
3430 wnn_errorno = 0; | |
3431 buf->env = env; | |
3432 } | |
3433 | |
3434 | |
3435 struct wnn_env * | |
3436 jl_env_get (buf) | |
3437 register struct wnn_buf *buf; | |
3438 { | |
3439 | |
3440 wnn_errorno = 0; | |
3441 return (buf->env); | |
3442 } | |
3443 | |
3444 | |
3445 int | |
3446 jl_param_set_e (env, para) | |
3447 register struct wnn_env *env; | |
3448 struct wnn_param *para; | |
3449 { | |
3450 register int x; | |
3451 | |
3452 wnn_errorno = 0; | |
3453 if ((x = js_param_set (env, para)) == -1) | |
3454 if_dead_disconnect (env, -1); | |
3455 return (x); | |
3456 } | |
3457 | |
3458 int | |
3459 jl_param_get_e (env, para) | |
3460 struct wnn_env *env; | |
3461 struct wnn_param *para; | |
3462 { | |
3463 register int x; | |
3464 wnn_errorno = 0; | |
3465 if ((x = js_param_get (env, para)) == -1) | |
3466 if_dead_disconnect (env, -1); | |
3467 return (x); | |
3468 } | |
3469 | |
3470 | |
3471 int | |
3472 jl_dic_use_e (env, dic_no, flag) | |
3473 struct wnn_env *env; | |
3474 int dic_no, flag; | |
3475 { | |
3476 register int x; | |
3477 wnn_errorno = 0; | |
3478 if ((x = js_dic_use (env, dic_no, flag)) == -1) | |
3479 if_dead_disconnect (env, -1); | |
3480 return (x); | |
3481 } | |
3482 | |
3483 int | |
3484 jl_word_add_e (env, dic_no, yomi, kanji, comment, hinsi, init_hindo) | |
3485 struct wnn_env *env; | |
3486 int dic_no; | |
3487 w_char *yomi, *kanji, *comment; | |
3488 int hinsi, init_hindo; | |
3489 | |
3490 { | |
3491 register int x; | |
3492 wnn_errorno = 0; | |
3493 if ((x = js_word_add (env, dic_no, yomi, kanji, comment, hinsi, init_hindo)) == -1) | |
3494 if_dead_disconnect (env, -1); | |
3495 return (x); | |
3496 } | |
3497 | |
3498 int | |
3499 jl_word_delete_e (env, dic_no, entry) | |
3500 struct wnn_env *env; | |
3501 int dic_no; | |
3502 int entry; | |
3503 { | |
3504 register int x; | |
3505 wnn_errorno = 0; | |
3506 if ((x = js_word_delete (env, dic_no, entry)) == -1) | |
3507 if_dead_disconnect (env, -1); | |
3508 return (x); | |
3509 } | |
3510 | |
3511 static int | |
3512 file_read (env, fname) | |
3513 struct wnn_env *env; | |
3514 char *fname; | |
3515 { | |
3516 register int fid; | |
3517 if (fname[0] == C_LOCAL) | |
3518 { | |
3519 fid = js_file_send (env, fname + 1); | |
3520 } | |
3521 else | |
3522 { | |
3523 fid = js_file_read (env, fname); | |
3524 } | |
3525 if (fid >= 0) | |
3526 { | |
3527 add_file_to_env (env, fid, fname); | |
3528 } | |
3529 return (fid); | |
3530 } | |
3531 | |
3532 static int | |
3533 file_remove (server, fname, pwd) | |
3534 register WNN_JSERVER_ID *server; | |
3535 char *fname; | |
3536 char *pwd; | |
3537 { | |
3538 if (fname[0] == C_LOCAL) | |
3539 { | |
3540 return (js_file_remove_client (server, fname + 1, pwd)); | |
3541 } | |
3542 else | |
3543 { | |
3544 return (js_file_remove (server, fname, pwd)); | |
3545 } | |
3546 } | |
3547 | |
3548 | |
3549 static int | |
3550 file_discard (env, fid) | |
3551 register struct wnn_env *env; | |
3552 register int fid; | |
3553 { | |
3554 delete_file_from_env (env, fid); | |
3555 return (js_file_discard (env, fid)); | |
3556 } | |
3557 | |
3558 int | |
3559 jl_hinsi_number_e (env, name) | |
3560 register struct wnn_env *env; | |
3561 w_char *name; | |
3562 { | |
3563 register int x; | |
3564 wnn_errorno = 0; | |
3565 if ((x = js_hinsi_number (env->js_id, name)) == -1) | |
3566 if_dead_disconnect (env, -1); | |
3567 return (x); | |
3568 } | |
3569 | |
3570 w_char * | |
3571 jl_hinsi_name_e (env, no) | |
3572 register struct wnn_env *env; | |
3573 register int no; | |
3574 { | |
3575 wnn_errorno = 0; | |
3576 if (js_hinsi_name (env->js_id, no, &rb) == -1) | |
3577 if_dead_disconnect (env, NULL); | |
3578 return ((w_char *) (rb.buf)); | |
3579 } | |
3580 | |
3581 int | |
3582 jl_hinsi_list_e (env, dic_no, name, area) | |
3583 register struct wnn_env *env; | |
3584 int dic_no; | |
3585 w_char *name; | |
3586 w_char ***area; | |
3587 { | |
3588 int x; | |
3589 wnn_errorno = 0; | |
3590 if ((x = js_hinsi_list (env, dic_no, name, &rb)) == -1) | |
3591 if_dead_disconnect (env, -1); | |
3592 *area = (w_char **) (rb.buf); | |
3593 return (x); | |
3594 } | |
3595 | |
3596 int | |
3597 jl_hinsi_dicts_e (env, no, area) | |
3598 register struct wnn_env *env; | |
3599 int no; | |
3600 int **area; | |
3601 { | |
3602 int x; | |
3603 wnn_errorno = 0; | |
3604 if ((x = js_hinsi_dicts (env, no, &rb)) == -1) | |
3605 if_dead_disconnect (env, -1); | |
3606 *area = (int *) (rb.buf); | |
3607 return (x); | |
3608 } | |
3609 | |
3610 | |
3611 int | |
3612 jl_word_comment_set_e (env, dic_no, entry, comment) | |
3613 register struct wnn_env *env; | |
3614 int dic_no, entry; | |
3615 w_char *comment; | |
3616 { | |
3617 register int x; | |
3618 wnn_errorno = 0; | |
3619 if ((x = js_word_comment_set (env, dic_no, entry, comment)) == -1) | |
3620 if_dead_disconnect (env, -1); | |
3621 return (x); | |
3622 } | |
3623 | |
3624 int | |
3625 jl_dic_comment_set_e (env, dic_no, comment) | |
3626 register struct wnn_env *env; | |
3627 int dic_no; | |
3628 w_char *comment; | |
3629 { | |
3630 register int x; | |
3631 WNN_DIC_INFO dic; | |
3632 WNN_FILE_INFO_STRUCT file; | |
3633 | |
3634 wnn_errorno = 0; | |
3635 if (js_dic_info (env, dic_no, &dic) < 0) | |
3636 if_dead_disconnect (env, -1); | |
3637 /* dic Body */ | |
3638 if (js_file_info (env, dic.body, &file) < 0) | |
3639 if_dead_disconnect (env, -1); | |
3640 if ((x = js_file_comment_set (env, file.fid, comment)) == -1) | |
3641 if_dead_disconnect (env, -1); | |
3642 return (x); | |
3643 } | |
3644 | |
3645 #ifdef nodef /*当面の間、頻度ファイルのコメントはユーザに見せない。 */ | |
3646 int | |
3647 jl_hindo_comment_set_e (env, dic_no, comment) | |
3648 register struct wnn_env *env; | |
3649 int dic_no; | |
3650 w_char *comment; | |
3651 { | |
3652 register int x; | |
3653 WNN_DIC_INFO dic; | |
3654 WNN_FILE_INFO_STRUCT file; | |
3655 | |
3656 wnn_errorno = 0; | |
3657 if (js_dic_info (env, dic_no, &dic) < 0) | |
3658 if_dead_disconnect (env, -1); | |
3659 /* dic Body */ | |
3660 if (dic.hindo == -1) | |
3661 { | |
3662 wnn_errorno = WNN_NO_HINDO_FILE; | |
3663 return (-1); | |
3664 } | |
3665 if (js_file_info (env, dic.hindo, &file) < 0) | |
3666 if_dead_disconnect (env, -1); | |
3667 if ((x = js_file_comment_set (env, file.fid, comment)) == -1) | |
3668 if_dead_disconnect (env, -1); | |
3669 return (x); | |
3670 } | |
3671 #endif |