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