1 /*
2  */
3 
4 /*
5 WNN7 CLIENT LIBRARY--SOFTWARE LICENSE TERMS AND CONDITIONS
6 
7 
8 Wnn7 Client Library :
9 (C) Copyright OMRON Corporation.       1995,1998,2000,2001 all rights reserved.
10 (C) Copyright OMRON Software Co., Ltd. 1995,1998,2000,2001 all rights reserved.
11 
12 Wnn Software :
13 (C) Copyright Kyoto University Research Institute for Mathematical Sciences
14      1987, 1988, 1989, 1990, 1991, 1992, 1993
15 (C) Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1993
16 (C) Copyright ASCTEC, Inc.  1987, 1988, 1989, 1990, 1991, 1992, 1993
17 
18 Preamble
19 
20 These Wnn7 Client Library--Software License Terms and Conditions
21  (the "License Agreement") shall state the conditions under which you are
22  permitted to copy, distribute or modify the software which can be used
23  to create Wnn7 Client Library (the "Wnn7 Client Library").  The License
24  Agreement can be freely copied and distributed verbatim, however, you
25  shall NOT add, delete or change anything on the License Agreement.
26 
27 OMRON Corporation and OMRON Software Co., Ltd. (collectively referred to
28  as "OMRON") jointly developed the Wnn7 Software (development code name
29  is FI-Wnn), based on the Wnn Software.  Starting from November, 1st, 1998,
30  OMRON publishes the source code of the Wnn7 Client Library, and OMRON
31  permits anyone to copy, distribute or change the Wnn7 Client Library under
32  the License Agreement.
33 
34 Wnn7 Client Library is based on the original version of Wnn developed by
35  Kyoto University Research Institute for Mathematical Sciences (KURIMS),
36  OMRON Corporation and ASTEC Inc.
37 
38 Article 1.  Definition.
39 
40 "Source Code" means the embodiment of the computer code, readable and
41  understandable by a programmer of ordinary skills.  It includes related
42  source code level system documentation, comments and procedural code.
43 
44 "Object File" means a file, in substantially binary form, which is directly
45  executable by a computer after linking applicable files.
46 
47 "Library" means a file, composed of several Object Files, which is directly
48  executable by a computer after linking applicable files.
49 
50 "Software" means a set of Source Code including information on its use.
51 
52 "Wnn7 Client Library" the computer program, originally supplied by OMRON,
53  which can be used to create Wnn7 Client Library.
54 
55 "Executable Module" means a file, created after linking Object Files or
56  Library, which is directly executable by a computer.
57 
58 "User" means anyone who uses the Wnn7 Client Library under the License
59  Agreement.
60 
61 Article 2.  Copyright
62 
63 2.1  OMRON Corporation and OMRON Software Co., Ltd. jointly own the Wnn7
64  Client Library, including, without limitation, its copyright.
65 
66 2.2  Following words followed by the above copyright notices appear
67  in all supporting documentation of software based on Wnn7 Client Library:
68 
69   This software is based on the original version of Wnn7 Client Library
70   developed by OMRON Corporation and OMRON Software Co., Ltd. and also based on
71   the original version of Wnn developed by Kyoto University Research Institute
72   for Mathematical Sciences (KURIMS), OMRON Corporation and ASTEC Inc.
73 
74 Article 3.  Grant
75 
76 3.1  A User is permitted to make and distribute verbatim copies of
77  the Wnn7 Client Library, including verbatim of copies of the License
78  Agreement, under the License Agreement.
79 
80 3.2  A User is permitted to modify the Wnn7 Client Library to create
81  Software ("Modified Software") under the License Agreement.  A User
82  is also permitted to make or distribute copies of Modified Software,
83  including verbatim copies of the License Agreement with the following
84  information.  Upon modifying the Wnn7 Client Library, a User MUST insert
85  comments--stating the name of the User, the reason for the modifications,
86  the date of the modifications, additional terms and conditions on the
87  part of the modifications if there is any, and potential risks of using
88  the Modified Software if they are known--right after the end of the
89  License Agreement (or the last comment, if comments are inserted already).
90 
91 3.3  A User is permitted to create Library or Executable Modules by
92  modifying the Wnn7 Client Library in whole or in part under the License
93  Agreement.  A User is also permitted to make or distribute copies of
94  Library or Executable Modules with verbatim copies of the License
95  Agreement under the License Agreement.  Upon modifying the Wnn7 Client
96  Library for creating Library or Executable Modules, except for porting
97  a computer, a User MUST add a text file to a package of the Wnn7 Client
98  Library, providing information on the name of the User, the reason for
99  the modifications, the date of the modifications, additional terms and
100  conditions on the part of the modifications if there is any, and potential
101  risks associated with using the modified Wnn7 Client Library, Library or
102  Executable Modules if they are known.
103 
104 3.4  A User is permitted to incorporate the Wnn7 Client Library in whole
105  or in part into another Software, although its license terms and
106  conditions may be different from the License Agreement, if such
107  incorporation or use associated with the incorporation does NOT violate
108  the License Agreement.
109 
110 Article 4. Warranty
111 
112 THE WNN7 CLIENT LIBRARY IS PROVIDED BY OMRON ON AN "AS IS" BAISIS.
113   OMRON EXPRESSLY DISLCIAMS ANY AND ALL WRRANTIES, EXPRESS OR IMPLIED,
114  INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY AND FITNESS
115  FOR A PARTICULAR PURPOSE, IN CONNECTION WITH THE WNN7 CLIENT LIBRARY
116  OR THE USE OR OTHER DEALING IN THE WNN7 CLIENT LIBRARY.  IN NO EVENT
117  SHALL OMRON BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, PUNITIVE
118  OR CONSEQUENTIAL DAMAGES OF ANY KIND WHATSOEVER IN CONNECTION WITH THE
119  WNN7 CLIENT LIBRARY OR THE USE OR OTHER DEALING IN THE WNN7 CLIENT
120 LIBRARY.
121 
122 ***************************************************************************
123 Wnn7 Client Library :
124 (C) Copyright OMRON Corporation.       1995,1998,2000,2001 all rights reserved.
125 (C) Copyright OMRON Software Co., Ltd. 1995,1998,2000,2001 all rights reserved.
126 
127 Wnn Software :
128 (C) Copyright Kyoto University Research Institute for Mathematical Sciences
129      1987, 1988, 1989, 1990, 1991, 1992, 1993
130 (C) Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1993
131 (C) Copyright ASCTEC, Inc.  1987, 1988, 1989, 1990, 1991, 1992, 1993
132 ***************************************************************************
133 
134 Comments on Modifications:
135 */
136 
137 /*	Version 4
138  */
139 /*
140 	Nihongo Henkan Hi-level Library
141 */
142 
143 #if defined(__DragonFly__)
144 #include <stdlib.h>
145 #include <string.h>
146 #include <unistd.h>
147 #include <sys/stat.h>
148 #include <time.h>
149 #endif
150 
151 #include "commonhd.h"
152 #include "config.h"
153 #include <stdio.h>
154 #include <stdlib.h>
155 #include <string.h>
156 #include <sys/types.h>
157 #ifdef SYSVR2
158 #   include <string.h>
159 #endif
160 #ifdef BSD42
161 #   include <strings.h>
162 #endif
163 #include <sys/file.h>
164 #include <ctype.h>
165 #include <pwd.h>
166 
167 #include "wnnerror.h"
168 #include "jd_sock.h"
169 #include "jslib.h"
170 #include "jllib.h"
171 #include "mt_jlib.h"
172 
173 #include "msg.h"
174 #include "wnn_string.h"
175 extern struct msg_cat *wnn_msg_cat;
176 
177 
178 #define MAXENVS WNN_MAX_ENV_OF_A_CLIENT
179 
180 #define MAXINCLUDE 10
181 
182 #define DEFAULT_BUN_LEN 3
183 
184 #define DEFAULT_ZENKOUHO_LEN 3
185 
186 #define DEFAULT_HEAP_LEN 3
187 
188 #define INCREMENT 2
189 
190 #define SHO 0
191 #define DAI 1
192 #define IKEIJI 2 /* ==WNN_IKEIJI */
193 /* Ϣ���Ѵ� NTWnn ���ή�� */
194 #define RENSOU 3 /* ==WNN_RENSOU */
195 
196 #define BUN 0
197 #define ZENKOUHO 1   /* Must not change!, they are assigned to two bit flag */
198 #define ZENKOUHO_DAI 3 /* DAI << 1 | ZENKOUHO */
199 #define ZENKOUHO_IKEIJI_DAI 5 /* IKEIJI << 1 | ZENKOUHO */
200 
201 #define	if_dead_disconnect(env) \
202 { \
203 	if (env_wnn_errorno_eql == WNN_JSERVER_DEAD) { \
204 		jl_disconnect_if_server_dead_body((WNN_ENV_INT *)env);\
205 	} \
206 }
207 
208 #define	if_dead_disconnect_b(buf) \
209 { \
210 	if (buf_wnn_errorno_eql == WNN_JSERVER_DEAD) { \
211        jl_disconnect_if_server_dead_body((WNN_ENV_INT *) \
212 					 ((WNN_BUF_MT *)buf)->orig.env);\
213 		((WNN_BUF_MT *)buf)->orig.env = NULL; \
214 	} \
215 }
216 
217 #define ARGS char
218 #define env_wnn_errorno_set wnn_errorno
219 #define env_wnn_errorno_eql wnn_errorno
220 #define buf_wnn_errorno_set wnn_errorno
221 #define buf_wnn_errorno_eql wnn_errorno
222 #define env_rb rb
223 #define buf_rb rb
224 
225 static struct wnn_ret_buf rb = {
226 	0, NULL};
227 static struct wnn_ret_buf dicrb = {
228 	0, NULL};
229 static struct wnn_ret_buf wordrb = {
230 	0, NULL};
231 
232 static int dumbhinsi;
233 static w_char *mae_fzk;
234 static int syuutanv;
235 static int syuutanv1;
236 
237 int confirm_state;
238 static int wnn_rendaku = -1;
239 static int wnn_settou = -1;
240 static int wnn_meisi = -1;
241 /* �ؽ�����ư�������ѳ��ꥫ������ */
242 static int kakutei_count = 0;
243 
244 #define jl_get_yomi_body(buf, bun_no, bun_no2, area, arealen) \
245                    wnn_get_area_body(buf, bun_no, bun_no2, area, WNN_YOMI, arealen)
246 
247 #define jl_get_kanji_body(buf, bun_no, bun_no2, area, arealen) \
248                    wnn_get_area_body(buf, bun_no, bun_no2, area, WNN_KANJI, arealen)
249 
250 #define CONFIRM  1
251 #define CONFIRM1 2
252 #define CREATE_WITHOUT_CONFIRM  3
253 #define NO_CREATE 4
254 
255 /* �հ�������θƤӽФ� */
256 #define REV_LOCAL 255
257 
258 static void add_down_bnst();
259 static int alloc_heap();
260 static int call_error_handler();
261 static int change_ascii_to_int();
262 static int create_file();
263 static int dai_end();
264 static int expand_expr();
265 static int expand_expr_all();
266 static int file_discard();
267 static int file_exist();
268 static int file_read();
269 static int file_remove();
270 static int find_same_kouho();
271 static int find_same_kouho_dai();
272 static void free_bun();
273 static void free_down();
274 static void free_sho();
275 static void free_zenkouho();
276 static int get_c_jikouho();
277 static int get_c_jikouho_dai();
278 static int get_c_jikouho_from_zenkouho();
279 static int get_c_jikouho_from_zenkouho_dai();
280 static int get_pwd();
281 static int insert_dai();
282 static int insert_sho();
283 static int jl_set_env_wnnrc1_body();
284 static int jl_yomi_len_body();
285 static int make_dir1();
286 static int make_dir_rec1();
287 static void make_space_for();
288 static void make_space_for_bun();
289 static void make_space_for_zenkouho();
290 static void message_out();
291 static int ren_conv1(), ren_conv_sub();
292 static int nobi_conv_sub();
293 static void set_dai();
294 static void set_sho();
295 static int tan_conv1(), tan_conv_sub();
296 static int wnn_get_area_body();
297 static w_char *wnn_area();
298 static void _Sstrcpy();
299 static void _sStrcpy();
300 static int jl_hinsi_number_e_body();
301 static int zen_conv_sho1();
302 static int zen_conv_dai1();
303 static int set_ima_off();
304 static int optimize_in_lib();
305 static int optimize_in_server();
306 
307 static int insert_dai_or_ikeiji();
308 static int jl_dic_save_all_e_body();
309 
310 static struct wnn_buf *jl_open_lang_core();
311 static struct wnn_env *jl_connect_lang_core();
312 
313 static void rev_setting();
314 int jl_set_henkan_hinsi_group(struct wnn_env_int *, int, int, int, int);
315 
316 /*
317  * Sub-routines to handle files, enviroments and connections.
318  */
319 
320 struct wnn_file_name_id {
321 	struct wnn_file_name_id *next;
322 	int id;
323 	char name[1];
324 };
325 
326 struct wnn_jl_env{
327 	WNN_JSERVER_ID *js;
328 	struct wnn_env_int *env;
329 	char env_n[WNN_ENVNAME_LEN];
330 	char server_n[MAXHOSTNAMELEN];
331 	char lang[32];
332 	int ref_cnt;
333 	struct wnn_file_name_id *file;
334 } envs[MAXENVS];
335 
336 /* �հ�������������¸�ѹ�¤�� */
337 struct st_rev_env *rev_env = NULL;
338 
339 static void
initialize_envs()340 initialize_envs()
341 {
342 	int i;
343 	for (i = 0; i < MAXENVS; i++) {
344 		envs[i].ref_cnt = 0;
345 	}
346 }
347 
348 /*
349  * File management routines.
350  */
351 
352 static
find_jl_env(env)353 struct wnn_jl_env *find_jl_env(env)
354 register struct wnn_env_int *env;
355 {
356 	register int k;
357 	for(k = 0 ; k < MAXENVS; k++){
358 		if(envs[k].env == env) return(envs + k);
359 	}
360 	return(NULL);
361 }
362 
363 
364 static
365 struct wnn_env_int *
find_env_of_same_js_id(js_id)366 find_env_of_same_js_id(js_id)
367 register WNN_JSERVER_ID *js_id;
368 {
369 	register int k;
370 
371 	for(k = 0 ; k < MAXENVS; k++){
372 		if (envs[k].js == NULL) continue;
373 		if (envs[k].js->sd == js_id->sd){
374 			return(envs[k].env);
375 		}
376 	}
377 	return(NULL);
378 }
379 
380 static
381 WNN_JSERVER_ID *
find_same_env_server(env_n,server_n,lang)382 find_same_env_server(env_n, server_n, lang)
383 register char *env_n, *server_n, *lang;
384 {
385 	register int k;
386 
387 	if (server_n == NULL || lang == NULL) return(NULL);
388 	for(k = 0 ; k < MAXENVS; k++){
389 		if(strncmp(envs[k].server_n, server_n, MAXHOSTNAMELEN - 1) == 0 &&
390 		    strcmp(envs[k].lang, lang) == 0){
391 			return(envs[k].js);
392 		}
393 	}
394 	return(NULL);
395 }
396 
397 static int
find_same_server_from_id(js)398 find_same_server_from_id(js)
399 register WNN_JSERVER_ID *js;
400 {
401 	register int k;
402 	for(k = 0 ; k < MAXENVS; k++){
403 		if(envs[k].js == NULL) continue;
404 		if(envs[k].js->sd == js->sd) return(1);
405 	}
406 	return(0);
407 }
408 
409 
410 
411 static
412 struct wnn_env_int *
find_same_env(js,env_n,lang)413 find_same_env(js, env_n, lang)
414 register WNN_JSERVER_ID *js;
415 register char *env_n;
416 char *lang;
417 {
418 	register int k;
419 
420 	if (env_n == NULL || lang == NULL) return(NULL);
421 	for(k = 0 ; k < MAXENVS; k++){
422 		if(envs[k].js == js && strcmp(envs[k].env_n, env_n) == 0
423 		    && strcmp(envs[k].lang, lang) == 0){
424 			envs[k].ref_cnt++;
425 			return(envs[k].env);
426 		}
427 	}
428 	return(NULL);
429 }
430 
431 static char *
env_name(env)432 env_name(env)
433 register struct wnn_env_int *env;
434 {
435 	register int k;
436 
437 	for(k = 0 ; k < MAXENVS; k++){
438 		if(envs[k].env == env){
439 			return(envs[k].env_n);
440 		}
441 	}
442 	return(NULL);
443 }
444 
445 
446 static void
add_new_env(js,env,env_n,server_n,lang)447 add_new_env(js, env, env_n, server_n, lang)
448 register WNN_JSERVER_ID *js;
449 register struct wnn_env_int *env;
450 char *env_n, *server_n, *lang;
451 {
452 	register int k;
453 
454 	for(k = 0 ; k < MAXENVS; k++){
455 		if(envs[k].ref_cnt == 0){
456 			strncpy(envs[k].server_n, server_n, MAXHOSTNAMELEN - 1);
457 			envs[k].server_n[MAXHOSTNAMELEN - 1] = '\0';
458 			strncpy(envs[k].env_n, env_n, WNN_ENVNAME_LEN - 1);
459 			envs[k].env_n[WNN_ENVNAME_LEN - 1] = '\0';
460 			strncpy(envs[k].lang, lang, sizeof(envs[k].lang) - 1);
461 			envs[k].lang[sizeof(envs[k].lang) - 1] = 0;
462 			envs[k].js = js;
463 			envs[k].env = env;
464 			envs[k].ref_cnt = 1;
465 			envs[k].file = NULL;
466 			break;
467 		}
468 	}
469 }
470 
471 static int
delete_env(env)472 delete_env(env)
473 register struct wnn_env_int *env;
474 {
475 	register int k;
476 
477 	for(k = 0 ; k < MAXENVS; k++){
478 		if(envs[k].env == env){
479 			if(--envs[k].ref_cnt == 0){
480 				strcpy(envs[k].server_n, "");
481 				strcpy(envs[k].env_n, "");
482 				strcpy(envs[k].lang, "");
483 				envs[k].js = NULL;
484 				envs[k].env = NULL;
485 				return(1);	/* Need To delete env */
486 			} else{
487 				return(0);	/* Need not to delete env */
488 			}
489 		}
490 	}
491 	return(-1);			/* This must not happen */
492 }
493 
494 /* Routines to manipulate files */
495 
496 static int
add_file_to_env(env,id,name)497 add_file_to_env(env, id, name)
498 struct wnn_env_int *env;
499 int id;
500 register char *name;
501 {
502 	register struct wnn_file_name_id *f, *f1;
503 	if((f = (struct wnn_file_name_id *)malloc(sizeof(struct wnn_file_name_id) +
504 	    strlen(name) + 1)) == NULL){
505 		env_wnn_errorno_set=WNN_ALLOC_FAIL;
506 		return(-1);
507 	}
508 	strcpy(f->name, name);
509 	f->id = id;
510 	f1 = find_jl_env(env)->file;
511 	f->next = f1;
512 	find_jl_env(env)->file = f;
513 	return(0);
514 }
515 
516 static char *
find_file_name_from_id(env,id)517 find_file_name_from_id(env, id)
518 struct wnn_env_int *env;
519 register int id;
520 {
521 	register struct wnn_file_name_id *f;
522 	f = find_jl_env(env)->file;
523 	for(;f; f = f->next){
524 		if(f->id == id){
525 			return(f->name);
526 		}
527 	}
528 	/*    env_wnn_errorno_set=WNN_FILE_NOT_READ_FROM_CLIENT; */
529 	return(NULL);
530 }
531 
532 static int
delete_file_from_env(env,id)533 delete_file_from_env(env, id)
534 struct wnn_env_int *env;
535 register int id;
536 {
537 	struct wnn_file_name_id *f;
538 	register struct wnn_file_name_id **prev;
539 	register struct wnn_jl_env *jl_env_p;
540 
541 	jl_env_p = find_jl_env(env);
542 	if (!jl_env_p->file) {
543 		return(0);
544 	}
545 	for(prev = &jl_env_p->file; (f = *prev); prev = &f->next){
546 		if (f->id == id) {
547 			*prev = f->next;
548 			free(f);
549 			return(0);
550 		}
551 	}
552 	env_wnn_errorno_set=WNN_FILE_NOT_READ_FROM_CLIENT;
553 	return(-1);
554 }
555 
556 /*
557  * Libraries which handle Connection To Jserver
558  */
559 
560 struct wnn_env *
jl_connect_lang(env_n,server_n,lang,wnnrc_n,error_handler,message_handler,timeout)561 jl_connect_lang(env_n, server_n, lang, wnnrc_n, error_handler, message_handler, timeout)
562 register char *env_n, *server_n, *wnnrc_n, *lang;
563 int  (*error_handler)(), (*message_handler)();
564 int timeout;
565 {
566 	return(jl_connect_lang_core(env_n, server_n, lang, wnnrc_n,
567 	    error_handler, message_handler, timeout
568 	    ));
569 }
570 
571 
572 
573 static struct wnn_env *
jl_connect_lang_core(env_n,server_n,lang,wnnrc_n,error_handler,message_handler,timeout)574 jl_connect_lang_core(env_n, server_n, lang, wnnrc_n,
575 error_handler, message_handler, timeout
576 )
577 register char *env_n, *server_n, *lang, *wnnrc_n;
578 int  (*error_handler)(), (*message_handler)();
579 int timeout;
580 {
581 	extern void jl_disconnect_if_server_dead_body_by_jsid();
582 	register WNN_JSERVER_ID	*js = NULL;
583 	struct wnn_env_int *env;
584 	int env_exist, cnt;
585 	char p_lang[16];
586 	register char *p, *l;
587 	static int initialized_envs = 0;
588 	extern char *getenv();
589 
590 	if (!initialized_envs) {
591 		initialize_envs();
592 		initialized_envs = 1;
593 	}
594 
595 	wnn_errorno = 0;
596 	/* if lang not specified use $LANG */
597 	if(!lang || !*lang){
598 		lang = getenv("LANG");
599 	}
600 	if (!lang || !*lang){
601 		/* Sorry! Default is Japanese. :-) */
602 		strcpy(p_lang, "ja_JP");
603 	} else {
604 		/* Use only [language]_[teritorry] */
605 		for (p = p_lang, l = lang, cnt = 0 ;
606 		    (*l != '@') && (*l != '.') && (*l != 0) &&
607 		    (cnt < sizeof(p_lang) - 1) ;
608 		    p++, l++, cnt++)
609 			*p = *l;
610 		*p = 0;
611 	}
612 
613 	if(!server_n || !*server_n){
614 		/* find server machine name from table by lang */
615 		server_n = "localhost";
616 		if((js = find_same_env_server(env_n, server_n, p_lang)) == NULL){
617 				js = js_open_lang(server_n, p_lang, timeout);
618 			if (js == NULL)
619 				server_n = NULL;
620 		}
621 		if (!server_n || !*server_n) {
622 			server_n = "unix";
623 		}
624 	}
625 
626 	if (js == NULL) {
627 		if((js = find_same_env_server(env_n, server_n, p_lang)) == NULL){
628 				js = js_open_lang(server_n, p_lang, timeout);
629 			if (js == NULL) {
630 				return(NULL);
631 			}
632 			/*	js_hinsi_list(js); */
633 		}
634 	}
635 	if ((env_exist = js_env_exist(js, env_n)) < 0) {
636 		jl_disconnect_if_server_dead_body_by_jsid(js);
637 		return (NULL);
638 	}
639 	if((env = find_same_env(js, env_n, p_lang)) == NULL){ /* Incr ref_cnt */
640 		if((env = (WNN_ENV_INT *)js_connect_lang(js, env_n, p_lang)) == NULL){
641 			js_close(js);
642 			return(NULL);
643 		}
644 		if(!strncmp(lang, WNN_J_LANG, 5)) {
645 			w_char tmp[8];
646 			_Sstrcpy(tmp, WNN_HINSI_RENDAKU);
647 			wnn_rendaku = jl_hinsi_number_e_body(env, tmp);
648 			_Sstrcpy(tmp, WNN_HINSI_SETTOUO);
649 			wnn_settou = jl_hinsi_number_e_body(env, tmp);
650 			_Sstrcpy(tmp, WNN_HINSI_MEISI);
651 			wnn_meisi = jl_hinsi_number_e_body(env, tmp);
652 		}
653 		add_new_env(js, env, env_n, server_n, p_lang);
654 	}
655 	if(env_exist == 0 && wnnrc_n){
656 		jl_set_env_wnnrc(env, wnnrc_n, error_handler, message_handler);
657 	} else {
658 		struct wnn_henkan_env henv;
659 		if(wnnrc_n)
660 			jl_set_env_wnnrc1_body(env, wnnrc_n, error_handler,
661 			    message_handler, 0, 1);
662 		if(js_get_henkan_env(env, &henv) == 0) {
663 			env->orig.muhenkan_mode = henv.muhenkan_flag;
664 			env->orig.bunsetsugiri_mode = henv.bunsetsugiri_flag;
665 		} else {
666 			env->orig.muhenkan_mode = WNN_DIC_RDONLY;
667 			env->orig.bunsetsugiri_mode = WNN_DIC_RDONLY;
668 		}
669 	}
670 	return((struct wnn_env *)env);
671 }
672 
673 static void
jl_disconnect_body(env)674 jl_disconnect_body(env)
675 register struct wnn_env *env;
676 {
677 	WNN_JSERVER_ID *js_id;
678 	int ret;
679 
680 	env_wnn_errorno_set = 0;
681 	if ((ret = delete_env(env)) < 0)
682 		return;
683 
684 	js_id = env->js_id;
685 	if (ret)
686 		js_disconnect(env);
687 
688 	if (!find_same_server_from_id(js_id))
689 		js_close(js_id);
690 }
691 
692 void
jl_disconnect(env)693 jl_disconnect(env)
694 register struct wnn_env *env;
695 {
696 	if(!env) return;
697 	jl_disconnect_body(env);
698 }
699 
700 int
jl_isconnect_e(env)701 jl_isconnect_e(env)
702 register struct wnn_env *env;
703 {
704 	if(!env) return(0);
705 	if (js_isconnect(env) == 0) {
706 		return(1);
707 	} else {
708 		return (0);
709 	}
710 }
711 
712 int
jl_isconnect(buf)713 jl_isconnect(buf)
714 register struct wnn_buf *buf;
715 {
716 	int x;
717 
718 	if(!buf) return(0);
719 	x = jl_isconnect_e(buf->env);
720 	return x;
721 }
722 
723 /* JSERVER �������� env �� disconnect ���Ʋ�� */
724 static void
jl_disconnect_if_server_dead_body(env)725 jl_disconnect_if_server_dead_body(env)
726 register struct wnn_env *env;
727 {
728 	register struct wnn_env_int *same_env;
729 	WNN_JSERVER_ID *js_id;
730 	int ret;
731 
732 	if((ret = delete_env((WNN_ENV_INT *)env)) < 0)
733 		return;
734 
735 	js_id = env->js_id;
736 	if (ret)
737 		js_disconnect(env);
738 
739 	while ((same_env = find_env_of_same_js_id(js_id)) != 0) {
740 		if (delete_env(same_env))
741 			js_disconnect((WNN_ENV *)same_env);
742 	}
743 
744 	js_close(js_id);
745 }
746 
747 void
jl_disconnect_if_server_dead_body_by_jsid(jsid)748 jl_disconnect_if_server_dead_body_by_jsid(jsid)
749 register WNN_JSERVER_ID	*jsid;
750 {
751 	register struct wnn_env_int *same_env;
752 
753 	while ((same_env = find_env_of_same_js_id(jsid)) != 0) {
754 		if (delete_env(same_env))
755 			js_disconnect((WNN_ENV *)same_env);
756 	}
757 	js_close(jsid);
758 }
759 
760 void
jl_disconnect_if_server_dead(env)761 jl_disconnect_if_server_dead(env)
762 register struct wnn_env *env;
763 {
764 	if(!env) return;
765 	jl_disconnect_if_server_dead_body((WNN_ENV_INT *)env);
766 }
767 
768 struct wnn_buf *
jl_open_lang(env_n,server_n,lang,wnnrc_n,error_handler,message_handler,timeout)769 jl_open_lang(env_n, server_n, lang, wnnrc_n, error_handler, message_handler, timeout)
770 char *env_n, *server_n, *wnnrc_n, *lang;
771 int  (*error_handler)(), (*message_handler)();
772 int timeout;
773 {
774 	return(jl_open_lang_core(env_n, server_n, lang, wnnrc_n,
775 	    error_handler, message_handler, timeout
776 	    ));
777 }
778 
779 
780 
781 static struct wnn_buf *
jl_open_lang_core(env_n,server_n,lang,wnnrc_n,error_handler,message_handler,timeout)782 jl_open_lang_core(env_n, server_n, lang, wnnrc_n,
783 error_handler, message_handler, timeout
784 )
785 char *env_n, *server_n, *lang, *wnnrc_n;
786 int  (*error_handler)(), (*message_handler)();
787 int timeout;
788 {
789 	register int k, dmy;
790 	register struct wnn_buf_mt *buf;
791 	struct wnn_env *env;
792 
793 	wnn_errorno = 0;
794 	if(rb.size == 0) rb.buf = (char *)malloc((unsigned)(rb.size = 1024));
795 
796 #define ALLOC_SET(pter, type, size, size_var) \
797     ((pter) = ((type *)malloc((unsigned)(sizeof(type) * ((size_var) = (size))))))
798 
799 	if(!ALLOC_SET(buf, struct wnn_buf_mt, 1, dmy)){
800 		wnn_errorno=WNN_ALLOC_FAIL;
801 		return NULL;
802 	}
803 
804 	buf->orig.bun_suu = 0;
805 	buf->orig.zenkouho_suu = 0;
806 	buf->orig.zenkouho_daip = 0;
807 	buf->orig.c_zenkouho = -1;
808 	buf->orig.zenkouho_bun = -1;
809 	buf->orig.zenkouho_end_bun = -1;
810 	buf->orig.free_heap = NULL;
811 	buf->orig.heap = NULL;
812 	buf->orig.zenkouho_dai_suu = 0;
813 	buf->orig.env = NULL;
814 	/*
815 	     * (Sep. 20, 1994)
816 	     * ���ѣƣɴط���������ѹ�¤�Τ���������
817 	     */
818 	buf->orig.fi_rb.size = buf->orig.fi_rb.num = 0;
819 	buf->orig.fi_rb.fi_buf = NULL;
820 	/* ľ�������������ν���� */
821 	for(k = 0; k < WNN_PREV_BUN_SUU; k++) {
822 		buf->orig.prev_bun[k].dic_no = -2;
823 		buf->orig.prev_bun[k].real_kanjilen = 0;
824 		buf->orig.prev_bun[k].kouho[0] = 0;
825 	}
826 
827 	buf->orig.bun = 0;
828 	buf->orig.zenkouho_dai = 0;
829 	buf->orig.zenkouho = 0;
830 	buf->orig.down_bnst = 0;
831 	if(!ALLOC_SET(buf->orig.bun, WNN_BUN *, DEFAULT_BUN_LEN, buf->orig.msize_bun) ||
832 	    !ALLOC_SET(buf->orig.zenkouho_dai, int, DEFAULT_ZENKOUHO_LEN + 1, buf->orig.msize_zenkouho) ||
833 	    !ALLOC_SET(buf->orig.zenkouho, WNN_BUN *, DEFAULT_ZENKOUHO_LEN, buf->orig.msize_zenkouho) ||
834 	    !ALLOC_SET(buf->orig.down_bnst, WNN_BUN *, DEFAULT_BUN_LEN, buf->orig.msize_bun)
835 	    ){
836 		jl_close(buf);
837 		wnn_errorno=WNN_ALLOC_FAIL;
838 		return NULL;
839 	}
840 
841 	for(k = 0 ; k < DEFAULT_BUN_LEN ; k++){
842 		buf->orig.down_bnst[k] = NULL;
843 	}
844 
845 	if(alloc_heap(buf, DEFAULT_HEAP_LEN) == -1){
846 		jl_close(buf);
847 		return NULL;
848 	}
849 
850 		env = jl_connect_lang(env_n, server_n, lang, wnnrc_n, error_handler, message_handler, timeout);
851 	if (!env) {
852 		jl_close(buf);
853 		return NULL;
854 	}
855 	buf->orig.env = env;
856 
857 	return((struct wnn_buf *)buf);
858 }
859 
860 static void
_Sstrcpy(ws,s)861 _Sstrcpy(ws, s)
862 w_char *ws;
863 unsigned char *s;
864 {
865 	register int eesiz = -1;
866 	register unsigned char x;
867 	register w_char *ie;
868 	register unsigned char *ee;
869 	register int cs_id, non_limit = 1;
870 	int _etc_cs[3];
871 	int cs_mask[3];
872 
873 	_etc_cs[0] = 2;
874 	_etc_cs[1] = 1;
875 	_etc_cs[2] = 2;
876 	cs_mask[0] = 0x8080;
877 	cs_mask[1] = 0x0080;
878 	cs_mask[2] = 0x8000;
879 	ie=ws;
880 	ee=s;
881 
882 	for(;(non_limit?(*ee):(eesiz>0));){
883 		x = *ee++;
884 		if(x > 0x9f || x == 0x8e || x == 0x8f){
885 			cs_id = ((x == 0x8e)? 1 : ((x == 0x8f)? 2: 0));
886 			if (cs_id == 1 || cs_id == 2) x = *ee++;
887 			if (_etc_cs[cs_id] <= 0) continue;
888 			if (_etc_cs[cs_id] > 1) {
889 				*ie = (w_char)(x & 0x7f) << 8;
890 				x = *ee++;
891 			} else {
892 				*ie = (w_char)0;
893 			}
894 			*ie |= (x & 0x7f);
895 			*ie++ |= cs_mask[cs_id];
896 			eesiz -= _etc_cs[cs_id] + 1;
897 		} else{
898 			*ie++ = x;
899 			eesiz--;
900 		}
901 	}
902 
903 	non_limit = ((char *)ie - (char *)ws) / sizeof(w_char);
904 	ws[non_limit] = 0;
905 }
906 
907 static void
_sStrcpy(s,ws)908 _sStrcpy(s, ws)
909 unsigned char *s;
910 w_char *ws;
911 {
912 	register int x;
913 	register w_char *ie;
914 	register unsigned char *ee;
915 	register int cs_id, mask, ret_pos;
916 	int _etc_cs[3];
917 	int cs_mask[3];
918 
919 	_etc_cs[0] = 2;
920 	_etc_cs[1] = 1;
921 	_etc_cs[2] = 2;
922 	cs_mask[0] = 0x8080;
923 	cs_mask[1] = 0x0080;
924 	cs_mask[2] = 0x8000;
925 	ie=ws;
926 	ee=s;
927 
928 	for(;(*ie);){
929 		x = *ie++;
930 		mask = x & cs_mask[0];
931 		if (mask == 0x0000 || x == 0xffff) {
932 			*ee++ = x;
933 		} else {
934 			cs_id = (mask == cs_mask[2])? 2:
935 			    ((mask == cs_mask[1])? 1: 0);
936 			if (_etc_cs[cs_id] <= 0) continue;
937 			if (cs_id == 1) *ee++ = 0x8e;
938 			else if (cs_id == 2) *ee++ = 0x8f;
939 			if (_etc_cs[cs_id] > 1) *ee++ = (x >> 8) | 0x80;
940 			if (_etc_cs[cs_id] > 0) *ee++ = (x & 0xff) | 0x80;
941 		}
942 	}
943 	ret_pos = ((char *)ee - (char *)s);
944 	s[ret_pos] = 0;
945 
946 }
947 
948 static int
alloc_heap(buf,len)949 alloc_heap(buf, len)
950 struct wnn_buf_mt *buf;
951 register int len;
952 {
953 	char **c;
954 	register WNN_BUN *d;
955 
956 	if((c =(char **)malloc((unsigned)(len * sizeof(WNN_BUN) + sizeof(char *)))) == NULL){
957 		buf_wnn_errorno_set=WNN_ALLOC_FAIL;
958 		return(-1);
959 	}
960 
961 	*c = buf->orig.heap;
962 	buf->orig.heap = (char *)c;
963 	d = (WNN_BUN *)(c + 1);
964 	for(--len; len > 0 ; len--, d++){
965 		d->free_next = d + 1;
966 	}
967 	d->free_next = buf->orig.free_heap;
968 	buf->orig.free_heap = (WNN_BUN *)(c + 1);
969 	return(0);
970 }
971 
972 void
jl_close(buf)973 jl_close(buf)
974 register struct wnn_buf *buf;
975 {
976 	register char *c, *next;
977 
978 	if(buf == NULL) return;
979 	if(buf->env){
980 		buf_wnn_errorno_set = 0;
981 		jl_disconnect_body(buf->env);
982 		buf->env = 0;
983 	}
984 
985 	if(buf->bun) free((char *)buf->bun);
986 	if(buf->zenkouho) free((char *)buf->zenkouho);
987 	if(buf->zenkouho_dai) free((char *)buf->zenkouho_dai);
988 	if(buf->down_bnst) free((char *)buf->down_bnst);
989 	for(c = buf->heap; c; c = next) {
990 		next = *(char **)c;
991 		free(c);
992 	}
993 	free((char *)buf);
994 }
995 
996 /*
997  * Conversion Libraries
998  */
999 
1000 /*:::DOC_START
1001  *
1002  *    Function Name: jl_ren_conv
1003  *    Description  : Ϣʸ���Ѵ���Ԥ�
1004  *    Parameter    :
1005  *         buf :      (InOut) �Хåե��ؤΥݥ���
1006  *         yomi :     (In) �Ѵ��ɤ�ʸ����ؤΥݥ���
1007  *         bun_no :   (In) �������ʸ�����Ƭʸ���ֹ�
1008  *         bun_no2 :  (In) �������ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1009  *         use_maep : (In) �������³��ʻȤ����ݡ˥ե饰
1010  *
1011  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1012  *
1013  *    Revision history:
1014  *	16-May-96: ���Ѻѣƣɴط��ǡ���������
1015  *
1016  *:::DOC_END
1017  */
1018 int
jl_ren_conv(buf,yomi,bun_no,bun_no2,use_maep)1019 jl_ren_conv(buf, yomi, bun_no, bun_no2, use_maep)
1020 register struct wnn_buf *buf;
1021 register w_char *yomi;
1022 int bun_no, bun_no2;
1023 int use_maep;
1024 {
1025 	int x;
1026 
1027 	if(!buf) return(-1);
1028 	buf_wnn_errorno_set = 0;
1029 
1030 	/* ���Ѻѣƣɴط��ǡ������������롣 05/16/96 */
1031 	buf->fi_rb.num = 0;
1032 
1033 	if(bun_no < 0) {
1034 		return(-1);
1035 	}
1036 
1037 	x = ren_conv_sub((WNN_BUF_MT *)buf, yomi, bun_no, bun_no2, use_maep,
1038 	    0, 0, NULL, 0);
1039 	return x;
1040 } /* End of jl_ren_conv */
1041 
1042 /*:::DOC_START
1043  *
1044  *    Function Name: jl_ren_conv_with_hinsi_name
1045  *    Description  : �Ѵ��˻��Ѥ����ʻ����ꤷ��Ϣʸ���Ѵ���Ԥ�
1046  *    Parameter    :
1047  *         buf :      (InOut) �Хåե��ؤΥݥ���
1048  *         yomi :     (In) �Ѵ��ɤ�ʸ����ؤΥݥ���
1049  *         bun_no :   (In) �������ʸ�����Ƭʸ���ֹ�
1050  *         bun_no2 :  (In) �������ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1051  *         use_maep : (In) �������³��ʻȤ����ݡ˥ե饰
1052  *	   nhinsi :   (In) �ʻ�����Ѵ����λ����ʻ��
1053  *         hlist :    (In) �ʻ�����Ѵ����λ����ʻ�̾����ؤΥݥ���
1054  *
1055  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1056  *
1057  *    Revision history:
1058  *	16-May-96: ���Ѻѣƣɴط��ǡ���������
1059  *
1060  *:::DOC_END
1061  */
1062 int
jl_ren_conv_with_hinsi_name(buf,yomi,bun_no,bun_no2,use_maep,nhinsi,hname)1063 jl_ren_conv_with_hinsi_name(buf, yomi, bun_no, bun_no2, use_maep, nhinsi, hname)
1064 register struct wnn_buf *buf;
1065 register w_char *yomi;
1066 int bun_no, bun_no2;
1067 int use_maep, nhinsi;
1068 char **hname;
1069 {
1070 	int x, i, hsize, *hno = NULL;
1071 	w_char tmp[64];
1072 
1073 	if(!buf) return(-1);
1074 	buf_wnn_errorno_set = 0;
1075 
1076 	/* ���Ѻѣƣɴط��ǡ������������롣 05/16/96 */
1077 	buf->fi_rb.num = 0;
1078 
1079 	if(bun_no < 0) {
1080 		return(-1);
1081 	}
1082 	if(nhinsi) {
1083 		hsize = abs(nhinsi);
1084 		hno = (int *)malloc(hsize * sizeof(int));
1085 		for(i = 0; i < hsize; i++) {
1086 			_Sstrcpy(tmp, hname[i]);
1087 			if((hno[i] = jl_hinsi_number_e(buf->env, tmp)) == -1) {
1088 				free((char *)hno);
1089 				return(-1);
1090 			}
1091 		}
1092 	}
1093 
1094 	x = ren_conv_sub((WNN_BUF_MT *)buf, yomi, bun_no, bun_no2, use_maep,
1095 	    0, nhinsi, hno, 0);
1096 	if(nhinsi) free((char *)hno);
1097 	return x;
1098 } /* End of jl_ren_conv_with_hinsi_name */
1099 
1100 /*:::DOC_START
1101  *
1102  *    Function Name: jl_fi_ren_conv
1103  *    Description  : Ϣʸ��ƣ��Ѵ���Ԥ�
1104  *    Parameter    :
1105  *         buf :      (InOut) �Хåե��ؤΥݥ���
1106  *	   yomi :     (In) �Ѵ��ɤ�ʸ����ؤΥݥ���
1107  *	   bun_no :   (In) �������ʸ�����Ƭʸ���ֹ�
1108  *	   bun_no2 :  (In) �������ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1109  * 	   use_maep : (In) �������³��ʻȤ����ݡ˥ե饰
1110  *
1111  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1112  *
1113  *    Revision history:
1114  *	16-May-96: ���Ѻѣƣɴط��ǡ���������
1115  *
1116  *:::DOC_END
1117  */
1118 int
jl_fi_ren_conv(buf,yomi,bun_no,bun_no2,use_maep)1119 jl_fi_ren_conv(buf, yomi, bun_no, bun_no2, use_maep)
1120 register struct wnn_buf *buf;
1121 register w_char *yomi;
1122 int bun_no, bun_no2;
1123 int use_maep;
1124 {
1125 	int x;
1126 
1127 	if(!buf) return(-1);
1128 	buf_wnn_errorno_set = 0;
1129 
1130 	/* ���Ѻѣƣɴط��ǡ������������롣 05/16/96 */
1131 	buf->fi_rb.num = 0;
1132 
1133 	if(bun_no < 0) {
1134 		return(-1);
1135 	}
1136 
1137 	x = ren_conv_sub((WNN_BUF_MT *)buf, yomi, bun_no, bun_no2, use_maep,
1138 	    0, 0, NULL, 1);
1139 	return x;
1140 } /* End of jl_fi_ren_conv */
1141 
1142 /*:::DOC_START
1143  *
1144  *    Function Name: ren_conv_sub
1145  *    Description  : Ϣʸ���Ѵ��Υ��֥롼����ؿ����Σ�
1146  *    Parameter    :
1147  *         buf :      (InOut) �Хåե��ؤΥݥ���
1148  *         yomi :     (In) �Ѵ��ɤ�ʸ����ؤΥݥ���
1149  *         bun_no :   (In) �������ʸ�����Ƭʸ���ֹ�
1150  *         bun_no2 :  (In) �������ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1151  *         use_maep : (In) �������³��ʻȤ����ݡ˥ե饰
1152  *	   fuku :     (In) ʣ���ͥ���Ѵ��ե饰
1153  *	   nhinsi :   (In) �ʻ�����Ѵ����λ����ʻ��
1154  * 	   hlist :    (In) �ʻ�����Ѵ����λ����ʻ��ֹ�����ؤΥݥ���
1155  * 	   fi_flag :  (In) ���Ѥ����ƣɴط������ʼ������ʤ���
1156  *			   �������˥ե饰
1157  *
1158  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1159  *
1160  *    Revision history:
1161  *
1162  *:::DOC_END
1163  */
1164 static int
ren_conv_sub(buf,yomi,bun_no,bun_no2,use_maep,fuku,nhinsi,hlist,fi_flag)1165 ren_conv_sub(buf, yomi, bun_no, bun_no2, use_maep, fuku, nhinsi, hlist, fi_flag)
1166 register struct wnn_buf *buf;
1167 w_char *yomi;
1168 register int bun_no, bun_no2;
1169 int use_maep, fuku, nhinsi, *hlist, fi_flag;
1170 {
1171 	int x;
1172 
1173 	if(bun_no2 >= buf->bun_suu || bun_no2 < 0) bun_no2 = buf->bun_suu;
1174 	free_down(buf, bun_no, bun_no2);
1175 	x = ren_conv1((WNN_BUF_MT *)buf, yomi, bun_no, bun_no2, use_maep,
1176 	    fuku, nhinsi, hlist, fi_flag);
1177 	return x;
1178 } /* End of ren_conv_sub */
1179 
1180 /*:::DOC_START
1181  *
1182  *    Function Name: ren_conv1
1183  *    Description  : Ϣʸ���Ѵ��Υ��֥롼����ؿ����Σ�
1184  *    Parameter    :
1185  *         buf :      (InOut) �Хåե��ؤΥݥ���
1186  *         yomi :     (In) �Ѵ��ɤ�ʸ����ؤΥݥ���
1187  *         bun_no :   (In) �������ʸ�����Ƭʸ���ֹ�
1188  *         bun_no2 :  (In) �������ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1189  *         use_maep : (In) �������³��ʻȤ����ݡ˥ե饰
1190  *         fuku :     (In) ʣ���ͥ���Ѵ��ե饰
1191  *         nhinsi :   (In) �ʻ�����Ѵ����λ����ʻ��
1192  *         hlist :    (In) �ʻ�����Ѵ����λ����ʻ��ֹ�����ؤΥݥ���
1193  *         fi_flag :  (In) ���Ѥ����ƣɴط������ʼ������ʤ���
1194  *                         �������˥ե饰
1195  *
1196  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1197  *
1198  *    Revision history:
1199  *
1200  *:::DOC_END
1201  */
1202 static int
ren_conv1(buf,yomi,bun_no,bun_no2,use_maep,fuku,nhinsi,hlist,fi_flag)1203 ren_conv1(buf, yomi, bun_no, bun_no2, use_maep, fuku, nhinsi, hlist, fi_flag)
1204 register struct wnn_buf_mt *buf;
1205 w_char *yomi;
1206 register int bun_no, bun_no2;
1207 int use_maep, fuku, nhinsi, *hlist, fi_flag;
1208 {
1209 	int dcnt;
1210 	struct wnn_dai_bunsetsu *dp;
1211 	int size;
1212 	w_char yomi1[LENGTHBUNSETSU];
1213 
1214 	if (yomi == NULL || *yomi == (w_char)0) return(0);
1215 	if(bun_no2 >= buf->orig.bun_suu || bun_no2 < 0)
1216 		bun_no2 = buf->orig.bun_suu;
1217 
1218 	if (use_maep & WNN_USE_MAE && bun_no > 0) {
1219 		dumbhinsi = buf->orig.bun[bun_no - 1]->hinsi;
1220 		jl_get_yomi_body(buf, bun_no - 1, bun_no, yomi1, sizeof(yomi1) / sizeof(w_char));
1221 		mae_fzk = yomi1 + buf->orig.bun[bun_no - 1]->jirilen;
1222 	} else {
1223 		dumbhinsi = WNN_BUN_SENTOU;
1224 		mae_fzk = (w_char *)0;
1225 	}
1226 	if(use_maep & WNN_USE_ATO && bun_no2 < buf->orig.bun_suu){
1227 		syuutanv = buf->orig.bun[bun_no2]->kangovect;
1228 		syuutanv1 = WNN_VECT_KANREN;
1229 	} else{
1230 		syuutanv = WNN_VECT_KANREN;
1231 		syuutanv1 = WNN_VECT_NO;
1232 		if(bun_no2 < buf->orig.bun_suu){
1233 			buf->orig.bun[bun_no2]->dai_top = 1;
1234 		}
1235 	}
1236 	if(!(buf->orig.env)) return(-1);
1237 	if(fuku == 0 && nhinsi == 0) {
1238 		if(fi_flag == 0) {
1239 			/* Ϣʸ���Ѵ� */
1240 			if((dcnt = js_kanren(buf->orig.env, yomi, dumbhinsi, mae_fzk,
1241 			    syuutanv, syuutanv1, WNN_VECT_BUNSETSU,
1242 			    &buf_rb)) < 0){
1243 				if_dead_disconnect_b(buf);
1244 				return(-1);
1245 			}
1246 		} else {
1247 			/* Ϣʸ��ƣ��Ѵ� */
1248 			if((dcnt = js_fi_kanren(buf->orig.env, yomi, dumbhinsi, mae_fzk,
1249 			    syuutanv, syuutanv1, WNN_VECT_BUNSETSU,
1250 			    buf->orig.prev_bun, &buf_rb, &(buf->orig.fi_rb))) < 0){
1251 				if_dead_disconnect_b(buf);
1252 				return(-1);
1253 			}
1254 		}
1255 	} else {
1256 		/* �Ѵ��Ķ�����Ϣʸ���Ѵ� */
1257 		if((dcnt = js_henkan_with_data(buf->orig.env, fuku, nhinsi, hlist,
1258 		    WNN_KANREN, yomi, dumbhinsi, mae_fzk,
1259 		    syuutanv, syuutanv1, WNN_VECT_BUNSETSU, &buf_rb)) < 0) {
1260 			if_dead_disconnect_b(buf);
1261 			return(-1);
1262 		}
1263 	}
1264 
1265 	dp = (struct wnn_dai_bunsetsu *)buf_rb.buf;
1266 
1267 	free_bun(buf, bun_no, bun_no2);
1268 
1269 	if(use_maep & WNN_USE_ATO && bun_no2 < buf->orig.bun_suu){
1270 		buf->orig.bun[bun_no2]->dai_top =
1271 		    (dp[dcnt-1].sbn[dp[dcnt-1].sbncnt-1].status_bkwd == WNN_CONNECT_BK)? 0:1;
1272 	}
1273 
1274 	size = insert_dai(buf, BUN, bun_no, bun_no2, dp, dcnt, 0, fuku, nhinsi, hlist);
1275 	if(buf->orig.zenkouho_end_bun > bun_no && buf->orig.zenkouho_bun < bun_no2){
1276 		free_zenkouho(buf);
1277 	} else if(buf->orig.zenkouho_bun >= bun_no2){
1278 		buf->orig.zenkouho_bun += size - bun_no2;
1279 		buf->orig.zenkouho_end_bun += size - bun_no2;
1280 
1281 	}
1282 	return(buf->orig.bun_suu);
1283 } /* End of ren_conv1 */
1284 
1285 /*:::DOC_START
1286  *
1287  *    Function Name: jl_tan_conv
1288  *    Description  : ñʸ���Ѵ���Ԥ�
1289  *    Parameter    :
1290  *         buf :      (InOut) �Хåե��ؤΥݥ���
1291  *         yomi :     (In) �Ѵ��ɤ�ʸ����ؤΥݥ���
1292  *         bun_no :   (In) �������ʸ�����Ƭʸ���ֹ�
1293  *         bun_no2 :  (In) �������ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1294  *         use_maep : (In) �������³��ʻȤ����ݡ˥ե饰
1295  *         ich_shop : (In) �ʾ�ʸ�᡿��ʸ����Ѵ��ե饰
1296  *
1297  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1298  *
1299  *    Revision history:
1300  *	16-May-96: ���Ѻѣƣɴط��ǡ���������
1301  *
1302  *:::DOC_END
1303  */
1304 int
jl_tan_conv(buf,yomi,bun_no,bun_no2,use_maep,ich_shop)1305 jl_tan_conv(buf, yomi, bun_no, bun_no2, use_maep, ich_shop)
1306 register struct wnn_buf *buf;
1307 w_char *yomi;
1308 register int bun_no, bun_no2;
1309 int use_maep, ich_shop;
1310 {
1311 	int x;
1312 
1313 	if(!buf) return(-1);
1314 	buf_wnn_errorno_set = 0;
1315 
1316 	/* ���Ѻѣƣɴط��ǡ������������롣 05/16/96 */
1317 	buf->fi_rb.num = 0;
1318 
1319 	if(bun_no < 0) {
1320 		return(-1);
1321 	}
1322 
1323 	if(tan_conv_sub((WNN_BUF_MT *)buf, yomi, bun_no, bun_no2, use_maep,
1324 	    ich_shop, 0, 0, NULL) == -1) {
1325 		return(-1);
1326 	}
1327 	x = buf->bun_suu;
1328 	return x;
1329 } /* End of jl_tan_conv */
1330 
1331 /*:::DOC_START
1332  *
1333  *    Function Name: jl_tan_conv_hinsi_flag
1334  *    Description  : �Ѵ��˻��Ѥ����ʻ����ꤷ��ñʸ���Ѵ���Ԥ�
1335  *    Parameter    :
1336  *         buf :      (InOut) �Хåե��ؤΥݥ���
1337  *         yomi :     (In) �Ѵ��ɤ�ʸ����ؤΥݥ���
1338  *         bun_no :   (In) �������ʸ�����Ƭʸ���ֹ�
1339  *         bun_no2 :  (In) �������ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1340  *         use_maep : (In) �������³��ʻȤ����ݡ˥ե饰
1341  *         ich_shop : (In) �ʾ�ʸ�᡿��ʸ����Ѵ��ե饰
1342  *	   hinsi_op : (In) �ʻ�����Ѵ����λ����ʻ�ե饰
1343  *
1344  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1345  *
1346  *    Revision history:
1347  *	16-May-96: ���Ѻѣƣɴط��ǡ���������
1348  *
1349  *:::DOC_END
1350  */
1351 int
jl_tan_conv_hinsi_flag(buf,yomi,bun_no,bun_no2,use_maep,ich_shop,hinsi_op)1352 jl_tan_conv_hinsi_flag(buf, yomi, bun_no, bun_no2, use_maep, ich_shop, hinsi_op)
1353 register struct wnn_buf *buf;
1354 w_char *yomi;
1355 register int bun_no, bun_no2;
1356 int use_maep, ich_shop, hinsi_op;
1357 {
1358 	int x, hno;
1359 	w_char tmp[64];
1360 
1361 	if(!buf) return(-1);
1362 	buf_wnn_errorno_set = 0;
1363 
1364 	/* ���Ѻѣƣɴط��ǡ������������롣 05/16/96 */
1365 	buf->fi_rb.num = 0;
1366 
1367 	if(bun_no < 0) {
1368 		return(-1);
1369 	}
1370 	if(strncmp(js_get_lang(buf->env), WNN_J_LANG, 5)) {
1371 		return(-1);
1372 	}
1373 	if(hinsi_op == WNN_ZIP)
1374 		_Sstrcpy(tmp, WNN_HINSI_ZIPCODE);
1375 	else if(hinsi_op == WNN_TEL)
1376 		_Sstrcpy(tmp, WNN_HINSI_TELNO);
1377 	else if(hinsi_op == WNN_TANKAN)
1378 		_Sstrcpy(tmp, WNN_HINSI_TANKAN);
1379 	else {
1380 		return(-1);
1381 	}
1382 	if((hno = jl_hinsi_number_e(buf->env, tmp)) == -1) {
1383 		return(-1);
1384 	}
1385 
1386 	if(tan_conv_sub((WNN_BUF_MT *)buf, yomi, bun_no, bun_no2, use_maep,
1387 	    ich_shop, 0, 1, &hno) == -1) {
1388 		return(-1);
1389 	}
1390 	x = buf->bun_suu;
1391 	return x;
1392 } /* jl_tan_conv_hinsi_flag */
1393 
1394 /*:::DOC_START
1395  *
1396  *    Function Name: jl_tan_conv_with_hinsi_name
1397  *    Description  : �Ѵ��˻��Ѥ����ʻ����ꤷ��ñʸ���Ѵ���Ԥ�
1398  *    Parameter    :
1399  *         buf :      (InOut) �Хåե��ؤΥݥ���
1400  *         yomi :     (In) �Ѵ��ɤ�ʸ����ؤΥݥ���
1401  *         bun_no :   (In) �������ʸ�����Ƭʸ���ֹ�
1402  *         bun_no2 :  (In) �������ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1403  *         use_maep : (In) �������³��ʻȤ����ݡ˥ե饰
1404  *         ich_shop : (In) �ʾ�ʸ�᡿��ʸ����Ѵ��ե饰
1405  *         nhinsi :   (In) �ʻ�����Ѵ����λ����ʻ��
1406  *         hlist :    (In) �ʻ�����Ѵ����λ����ʻ�̾����ؤΥݥ���
1407  *
1408  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1409  *
1410  *    Revision history:
1411  *	16-May-96: ���Ѻѣƣɴط��ǡ���������
1412  *
1413  *:::DOC_END
1414  */
1415 int
jl_tan_conv_with_hinsi_name(buf,yomi,bun_no,bun_no2,use_maep,ich_shop,nhinsi,hname)1416 jl_tan_conv_with_hinsi_name(buf, yomi, bun_no, bun_no2, use_maep, ich_shop, nhinsi, hname)
1417 register struct wnn_buf *buf;
1418 w_char *yomi;
1419 register int bun_no, bun_no2;
1420 int use_maep, ich_shop, nhinsi;
1421 char **hname;
1422 {
1423 	int i, x, hsize, *hno = NULL;
1424 	w_char tmp[64];
1425 
1426 	if(!buf) return(-1);
1427 	buf_wnn_errorno_set = 0;
1428 
1429 	/* ���Ѻѣƣɴط��ǡ������������롣 05/16/96 */
1430 	buf->fi_rb.num = 0;
1431 
1432 	if(bun_no < 0) {
1433 		return(-1);
1434 	}
1435 	if(nhinsi) {
1436 		hsize = abs(nhinsi);
1437 		hno = (int *)malloc(hsize * sizeof(int));
1438 		for(i = 0; i < hsize; i++) {
1439 			_Sstrcpy(tmp, hname[i]);
1440 			if((hno[i] = jl_hinsi_number_e(buf->env, tmp)) == -1) {
1441 				free((char *)hno);
1442 				return(-1);
1443 			}
1444 		}
1445 	}
1446 
1447 	if(tan_conv_sub((WNN_BUF_MT *)buf, yomi, bun_no, bun_no2, use_maep,
1448 	    ich_shop, 0, nhinsi, hno) == -1) {
1449 		if(nhinsi) free((char *)hno);
1450 		return(-1);
1451 	}
1452 	if(nhinsi) free((char *)hno);
1453 	x = buf->bun_suu;
1454 	return x;
1455 } /* jl_tan_conv_with_hinsi_name */
1456 
1457 /*:::DOC_START
1458  *
1459  *    Function Name: tan_conv_sub
1460  *    Description  : ñʸ���Ѵ��Υ��֥롼����ؿ����Σ�
1461  *    Parameter    :
1462  *         buf :      (InOut) �Хåե��ؤΥݥ���
1463  *         yomi :     (In) �Ѵ��ɤ�ʸ����ؤΥݥ���
1464  *         bun_no :   (In) �������ʸ�����Ƭʸ���ֹ�
1465  *         bun_no2 :  (In) �������ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1466  *         use_maep : (In) �������³��ʻȤ����ݡ˥ե饰
1467  *         ich_shop : (In) �ʾ�ʸ�᡿��ʸ����Ѵ��ե饰
1468  *         fuku :     (In) ʣ���ͥ���Ѵ��ե饰
1469  *         nhinsi :   (In) �ʻ�����Ѵ����λ����ʻ��
1470  *         hlist :    (In) �ʻ�����Ѵ����λ����ʻ��ֹ�����ؤΥݥ���
1471  *
1472  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1473  *
1474  *    Revision history:
1475  *
1476  *:::DOC_END
1477  */
1478 static int
tan_conv_sub(buf,yomi,bun_no,bun_no2,use_maep,ich_shop,fuku,nhinsi,hlist)1479 tan_conv_sub(buf, yomi, bun_no, bun_no2, use_maep, ich_shop, fuku, nhinsi, hlist)
1480 register struct wnn_buf *buf;
1481 w_char *yomi;
1482 register int bun_no, bun_no2;
1483 int use_maep, ich_shop, fuku, nhinsi, *hlist;
1484 {
1485 	int x;
1486 
1487 	if(bun_no2 >= buf->bun_suu || bun_no2 < 0) bun_no2 = buf->bun_suu;
1488 	free_down(buf, bun_no, bun_no2);
1489 	x = tan_conv1((WNN_BUF_MT *)buf, yomi, bun_no, bun_no2, use_maep,
1490 	    ich_shop, fuku, nhinsi, hlist);
1491 	return x;
1492 } /* End of tan_conv_sub */
1493 
1494 /*:::DOC_START
1495  *
1496  *    Function Name: tan_conv1
1497  *    Description  : ñʸ���Ѵ��Υ��֥롼����ؿ����Σ�
1498  *    Parameter    :
1499  *         buf :      (InOut) �Хåե��ؤΥݥ���
1500  *         yomi :     (In) �Ѵ��ɤ�ʸ����ؤΥݥ���
1501  *         bun_no :   (In) �������ʸ�����Ƭʸ���ֹ�
1502  *         bun_no2 :  (In) �������ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1503  *         use_maep : (In) �������³��ʻȤ����ݡ˥ե饰
1504  *	   ich_shop : (In) �ʾ�ʸ�᡿��ʸ����Ѵ��ե饰
1505  *         fuku :     (In) ʣ���ͥ���Ѵ��ե饰
1506  *         nhinsi :   (In) �ʻ�����Ѵ����λ����ʻ��
1507  *         hlist :    (In) �ʻ�����Ѵ����λ����ʻ��ֹ�����ؤΥݥ���
1508  *
1509  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1510  *
1511  *    Revision history:
1512  *
1513  *:::DOC_END
1514  */
1515 static int
tan_conv1(buf,yomi,bun_no,bun_no2,use_maep,ich_shop,fuku,nhinsi,hlist)1516 tan_conv1(buf, yomi, bun_no, bun_no2, use_maep, ich_shop, fuku, nhinsi, hlist)
1517 register struct wnn_buf_mt *buf;
1518 w_char *yomi;
1519 register int bun_no, bun_no2;
1520 int use_maep, ich_shop, fuku, nhinsi, *hlist;
1521 {
1522 	int dcnt;
1523 	struct wnn_dai_bunsetsu *dp;
1524 	struct wnn_sho_bunsetsu *sp;
1525 	int ret;
1526 	w_char yomi1[LENGTHBUNSETSU];
1527 
1528 	if (yomi == NULL || *yomi == (w_char)0) return(0);
1529 	if(bun_no2 >= buf->orig.bun_suu || bun_no2 < 0) bun_no2 = buf->orig.bun_suu;
1530 
1531 	if (use_maep & WNN_USE_MAE && bun_no > 0) {
1532 		dumbhinsi = buf->orig.bun[bun_no - 1]->hinsi;
1533 		jl_get_yomi_body(buf, bun_no - 1, bun_no, yomi1, sizeof(yomi1) / sizeof(w_char));
1534 		mae_fzk = yomi1 + buf->orig.bun[bun_no - 1]->jirilen;
1535 	} else {
1536 		dumbhinsi = WNN_BUN_SENTOU;
1537 		mae_fzk = (w_char *)0;
1538 	}
1539 	if(use_maep & WNN_USE_ATO && bun_no2 < buf->orig.bun_suu){
1540 		syuutanv = buf->orig.bun[bun_no2]->kangovect;
1541 		syuutanv1 = WNN_VECT_KANTAN;
1542 	} else{
1543 		syuutanv = WNN_VECT_KANTAN;
1544 		syuutanv1 = WNN_VECT_NO;
1545 		if(bun_no2 < buf->orig.bun_suu){
1546 			buf->orig.bun[bun_no2]->dai_top = 1;
1547 		}
1548 	}
1549 	if(!(buf->orig.env)) return(-1);
1550 	if(ich_shop == WNN_SHO){
1551 		if(fuku == 0 && nhinsi == 0) {
1552 			/* ��ʸ��ñʸ���Ѵ� */
1553 			if((dcnt = js_kantan_sho(buf->orig.env, yomi, dumbhinsi, mae_fzk,
1554 			    syuutanv, syuutanv1, &buf_rb)) < 0){
1555 				if_dead_disconnect_b(buf);
1556 				return(-1);
1557 			}
1558 		} else {
1559 			/* �Ѵ��Ķ����꾮ʸ��ñʸ���Ѵ� */
1560 			if((dcnt = js_henkan_with_data(buf->orig.env, fuku, nhinsi, hlist,
1561 			    WNN_KANTAN_SHO, yomi, dumbhinsi, mae_fzk,
1562 			    syuutanv, syuutanv1, WNN_VECT_BUNSETSU, &buf_rb)) < 0) {
1563 				if_dead_disconnect_b(buf);
1564 				return(-1);
1565 			}
1566 		}
1567 		sp = (struct wnn_sho_bunsetsu *)buf_rb.buf;
1568 		if(use_maep & WNN_USE_ATO && bun_no2 < buf->orig.bun_suu){
1569 			buf->orig.bun[bun_no2]->dai_top =
1570 			    (sp[dcnt-1].status_bkwd == WNN_CONNECT_BK)? 0:1;
1571 		}
1572 		free_bun(buf, bun_no, bun_no2);
1573 		ret = insert_sho(buf, BUN, bun_no, bun_no2, sp, dcnt, 0, fuku, nhinsi, hlist);
1574 	} else {
1575 		if(fuku == 0 && nhinsi == 0) {
1576 			/* ��ʸ��ñʸ���Ѵ� */
1577 			if((dcnt = js_kantan_dai(buf->orig.env, yomi, dumbhinsi, mae_fzk,
1578 			    syuutanv, syuutanv1, &buf_rb)) < 0){
1579 				if_dead_disconnect_b(buf);
1580 				return(-1);
1581 			}
1582 		} else {
1583 			/* �Ѵ��Ķ�������ʸ��ñʸ���Ѵ� */
1584 			if((dcnt = js_henkan_with_data(buf->orig.env, fuku, nhinsi, hlist,
1585 			    WNN_KANTAN_DAI, yomi, dumbhinsi, mae_fzk,
1586 			    syuutanv, syuutanv1, WNN_VECT_BUNSETSU, &buf_rb)) < 0) {
1587 				if_dead_disconnect_b(buf);
1588 				return(-1);
1589 			}
1590 		}
1591 		dp = (struct wnn_dai_bunsetsu *)buf_rb.buf;
1592 		if(use_maep & WNN_USE_ATO && bun_no2 < buf->orig.bun_suu){
1593 			buf->orig.bun[bun_no2]->dai_top =
1594 			    (dp[dcnt-1].sbn[dp[dcnt-1].sbncnt-1].status_bkwd == WNN_CONNECT_BK)? 0:1;
1595 		}
1596 		free_bun(buf, bun_no, bun_no2);
1597 		ret = insert_dai(buf, BUN, bun_no, bun_no2, dp, dcnt, 0, fuku, nhinsi, hlist);
1598 	}
1599 	if(buf->orig.zenkouho_end_bun > bun_no && buf->orig.zenkouho_bun < bun_no2){
1600 		free_zenkouho(buf);
1601 	} else if(buf->orig.zenkouho_bun >= bun_no2){
1602 		buf->orig.zenkouho_bun += ret - bun_no2;
1603 		buf->orig.zenkouho_end_bun += ret - bun_no2;
1604 	}
1605 	return(ret);
1606 } /* End of tan_conv1 */
1607 
1608 /*:::DOC_START
1609  *
1610  *    Function Name: jl_nobi_conv
1611  *    Description  : ����Ѵ���Ԥ�
1612  *    Parameter    :
1613  *         buf :       (InOut) �Хåե��ؤΥݥ���
1614  *         bun_no :    (In) �Ѵ�ʸ�����Ƭʸ���ֹ�
1615  *         ichbn_len : (In) ���ʸ���ܤ�Ĺ��
1616  *         bun_no2 :   (In) �Ѵ�ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1617  *         use_maep :  (In) �������³��ʻȤ����ݡ˥ե饰
1618  *         ich_shop :  (In) ��ʸ���ܤ�ʾ�ʸ�᡿��ʸ����Ѵ�����ե饰
1619  *
1620  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1621  *
1622  *    Revision history:
1623  *
1624  *:::DOC_END
1625  */
1626 int
jl_nobi_conv(buf,bun_no,ichbn_len,bun_no2,use_maep,ich_shop)1627 jl_nobi_conv(buf, bun_no, ichbn_len, bun_no2, use_maep, ich_shop)
1628 register struct wnn_buf *buf;
1629 int ichbn_len, use_maep, ich_shop;
1630 register int bun_no, bun_no2;
1631 {
1632 	int x;
1633 
1634 	if(!buf) return(-1);
1635 	buf_wnn_errorno_set = 0;
1636 	if(bun_no < 0) {
1637 		return(-1);
1638 	}
1639 
1640 	if(nobi_conv_sub(buf, bun_no, ichbn_len, bun_no2, use_maep, ich_shop,
1641 	    0, NULL, 0) == -1) {
1642 		return(-1);
1643 	}
1644 	x = buf->bun_suu;
1645 	return x;
1646 } /* End of jl_nobi_conv */
1647 
1648 /*:::DOC_START
1649  *
1650  *    Function Name: jl_nobi_conv_hinsi_flag
1651  *    Description  : �Ѵ��˻��Ѥ����ʻ����ꤷ�Ʊ���Ѵ���Ԥ�
1652  *    Parameter    :
1653  *         buf :       (InOut) �Хåե��ؤΥݥ���
1654  *         bun_no :    (In) �Ѵ�ʸ�����Ƭʸ���ֹ�
1655  *         ichbn_len : (In) ���ʸ���ܤ�Ĺ��
1656  *         bun_no2 :   (In) �Ѵ�ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1657  *         use_maep :  (In) �������³��ʻȤ����ݡ˥ե饰
1658  *         ich_shop :  (In) ��ʸ���ܤ�ʾ�ʸ�᡿��ʸ����Ѵ�����ե饰
1659  *	   hinsi_op :  (In) �ʻ�����Ѵ����λ����ʻ�ե饰
1660  *
1661  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1662  *
1663  *    Revision history:
1664  *
1665  *:::DOC_END
1666  */
1667 int
jl_nobi_conv_hinsi_flag(buf,bun_no,ichbn_len,bun_no2,use_maep,ich_shop,hinsi_op)1668 jl_nobi_conv_hinsi_flag(buf, bun_no, ichbn_len, bun_no2, use_maep, ich_shop, hinsi_op)
1669 register struct wnn_buf *buf;
1670 int ichbn_len, use_maep, ich_shop, hinsi_op;
1671 register int bun_no, bun_no2;
1672 {
1673 	int x, hno;
1674 	w_char tmp[64];
1675 
1676 	if(!buf) return(-1);
1677 	buf_wnn_errorno_set = 0;
1678 	if(bun_no < 0) {
1679 		return(-1);
1680 	}
1681 	if(strncmp(js_get_lang(buf->env), WNN_J_LANG, 5)) {
1682 		return(-1);
1683 	}
1684 	if(hinsi_op == WNN_ZIP)
1685 		_Sstrcpy(tmp, WNN_HINSI_ZIPCODE);
1686 	else if(hinsi_op == WNN_TEL)
1687 		_Sstrcpy(tmp, WNN_HINSI_TELNO);
1688 	else if(hinsi_op == WNN_TANKAN)
1689 		_Sstrcpy(tmp, WNN_HINSI_TANKAN);
1690 	else {
1691 		return(-1);
1692 	}
1693 	if((hno = jl_hinsi_number_e(buf->env, tmp)) == -1) {
1694 		return(-1);
1695 	}
1696 
1697 	if(nobi_conv_sub(buf, bun_no, ichbn_len, bun_no2, use_maep, ich_shop,
1698 	    1, &hno, 0) == -1) {
1699 		return(-1);
1700 	}
1701 	x = buf->bun_suu;
1702 	return x;
1703 } /* jl_nobi_conv_hinsi_flag */
1704 
1705 /*:::DOC_START
1706  *
1707  *    Function Name: jl_nobi_conv_with_hinsi_name
1708  *    Description  : �Ѵ��˻��Ѥ����ʻ����ꤷ�Ʊ���Ѵ���Ԥ�
1709  *    Parameter    :
1710  *         buf :       (InOut) �Хåե��ؤΥݥ���
1711  *         bun_no :    (In) �Ѵ�ʸ�����Ƭʸ���ֹ�
1712  *         ichbn_len : (In) ���ʸ���ܤ�Ĺ��
1713  *         bun_no2 :   (In) �Ѵ�ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1714  *         use_maep :  (In) �������³��ʻȤ����ݡ˥ե饰
1715  *         ich_shop :  (In) ��ʸ���ܤ�ʾ�ʸ�᡿��ʸ����Ѵ�����ե饰
1716  *         nhinsi :    (In) �ʻ�����Ѵ����λ����ʻ��
1717  *         hname :     (In) �ʻ�����Ѵ����λ����ʻ�̾����ؤΥݥ���
1718  *
1719  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1720  *
1721  *    Revision history:
1722  *
1723  *:::DOC_END
1724  */
1725 int
jl_nobi_conv_with_hinsi_name(buf,bun_no,ichbn_len,bun_no2,use_maep,ich_shop,nhinsi,hname)1726 jl_nobi_conv_with_hinsi_name(buf, bun_no, ichbn_len, bun_no2, use_maep, ich_shop, nhinsi, hname)
1727 register struct wnn_buf *buf;
1728 int ichbn_len, use_maep, ich_shop, nhinsi;
1729 register int bun_no, bun_no2;
1730 char **hname;
1731 {
1732 	int x, i, hsize, *hno = NULL;
1733 	w_char tmp[64];
1734 
1735 	if(!buf) return(-1);
1736 	buf_wnn_errorno_set = 0;
1737 	if(bun_no < 0) {
1738 		return(-1);
1739 	}
1740 	if(nhinsi) {
1741 		hsize = abs(nhinsi);
1742 		hno = (int *)malloc(hsize * sizeof(int));
1743 		for(i = 0; i < hsize; i++) {
1744 			_Sstrcpy(tmp, hname[i]);
1745 			if((hno[i] = jl_hinsi_number_e(buf->env, tmp)) == -1) {
1746 				free((char *)hno);
1747 				return(-1);
1748 			}
1749 		}
1750 	}
1751 
1752 	if(nobi_conv_sub(buf, bun_no, ichbn_len, bun_no2, use_maep, ich_shop,
1753 	    nhinsi, hno, 0) == -1) {
1754 		if(nhinsi) free((char *)hno);
1755 		return(-1);
1756 	}
1757 	if(nhinsi) free((char *)hno);
1758 	x = buf->bun_suu;
1759 	return x;
1760 } /* End of jl_nobi_conv_with_hinsi_name */
1761 
1762 /*:::DOC_START
1763  *
1764  *    Function Name: jl_fi_nobi_conv
1765  *    Description  : �ƣɱ���Ѵ���Ԥ�
1766  *    Parameter    :
1767  *         buf :       (InOut) �Хåե��ؤΥݥ���
1768  *         bun_no :    (In) �Ѵ�ʸ�����Ƭʸ���ֹ�
1769  *         ichbn_len : (In) ���ʸ���ܤ�Ĺ��
1770  *         bun_no2 :   (In) �Ѵ�ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1771  *         use_maep :  (In) �������³��ʻȤ����ݡ˥ե饰
1772  *         ich_shop :  (In) ��ʸ���ܤ�ʾ�ʸ�᡿��ʸ����Ѵ�����ե饰
1773  *
1774  *    Return value : -1==ERROR, else �Ѵ�ʸ���
1775  *
1776  *    Revision history:
1777  *
1778  *:::DOC_END
1779  */
1780 int
jl_fi_nobi_conv(buf,bun_no,ichbn_len,bun_no2,use_maep,ich_shop)1781 jl_fi_nobi_conv(buf, bun_no, ichbn_len, bun_no2, use_maep, ich_shop)
1782 register struct wnn_buf *buf;
1783 int ichbn_len, use_maep, ich_shop;
1784 register int bun_no, bun_no2;
1785 {
1786 	int x;
1787 
1788 	if(!buf) return(-1);
1789 	buf_wnn_errorno_set = 0;
1790 	if(bun_no < 0) {
1791 		return(-1);
1792 	}
1793 
1794 	if(nobi_conv_sub(buf, bun_no, ichbn_len, bun_no2, use_maep, ich_shop,
1795 	    0, NULL, 1) == -1) {
1796 		return(-1);
1797 	}
1798 	x = buf->bun_suu;
1799 	return x;
1800 } /* End of jl_fi_nobi_conv */
1801 
1802 /*:::DOC_START
1803  *
1804  *    Function Name: nobi_conv_sub
1805  *    Description  : ����Ѵ��Υ��֥롼����ؿ�
1806  *    Parameter    :
1807  *         buf :       (InOut) �Хåե��ؤΥݥ���
1808  *         bun_no :    (In) �Ѵ�ʸ�����Ƭʸ���ֹ�
1809  *	   ichbn_len : (In) ���ʸ���ܤ�Ĺ��
1810  *         bun_no2 :   (In) �Ѵ�ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
1811  *         use_maep :  (In) �������³��ʻȤ����ݡ˥ե饰
1812  *	   ich_shop :  (In) ��ʸ���ܤ�ʾ�ʸ�᡿��ʸ����Ѵ�����ե饰
1813  *         nhinsi :    (In) �ʻ�����Ѵ����λ����ʻ��
1814  *         hlist :     (In) �ʻ�����Ѵ����λ����ʻ��ֹ�����ؤΥݥ���
1815  *         fi_flag :   (In) ���Ѥ����ƣɴط������ʼ������ʤ���
1816  *                         �������˥ե饰
1817  *
1818  *    Return value : 0==SUCCESS, -1==ERROR
1819  *
1820  *    Revision history:
1821  *
1822  *:::DOC_END
1823  */
1824 static int
nobi_conv_sub(buf,bun_no,ichbn_len,bun_no2,use_maep,ich_shop,nhinsi,hlist,fi_flag)1825 nobi_conv_sub(buf, bun_no, ichbn_len, bun_no2, use_maep, ich_shop, nhinsi, hlist, fi_flag)
1826 register struct wnn_buf *buf;
1827 int ichbn_len, use_maep, ich_shop, nhinsi, *hlist, fi_flag;
1828 register int bun_no, bun_no2;
1829 {
1830 	w_char yomi[LENGTHCONV], ytmp;
1831 	int ret;
1832 	int len1;
1833 	register WNN_BUN *b1;  /* �ؽ������ޤ������褦���ѹ����ޤ�����H.T. */
1834 
1835 	if(bun_no2 >= buf->bun_suu || bun_no2 < 0) bun_no2 = buf->bun_suu;
1836 
1837 	len1 = jl_get_yomi_body((WNN_BUF_MT *)buf, bun_no, bun_no2, yomi, sizeof(yomi) / sizeof(w_char));
1838 	ytmp = yomi[ichbn_len];
1839 	if(len1 < ichbn_len){
1840 		ichbn_len = len1;
1841 	}
1842 	yomi[ichbn_len] = 0;
1843 
1844 	if(buf->bun[bun_no]->nobi_top != 1){  /* need to add down_bnst */
1845 		if(buf->bun[bun_no]) add_down_bnst((WNN_BUF_MT *)buf, bun_no,
1846 		    buf->bun[bun_no]);
1847 		if(bun_no + 1 < buf->bun_suu){
1848 			add_down_bnst((WNN_BUF_MT *)buf, bun_no, buf->bun[bun_no + 1]);
1849 			/* ���� bun_no �� down_bnst �˲ä���褦���ѹ� */
1850 		}
1851 	}
1852 	b1 = buf->down_bnst[bun_no];
1853 	buf->down_bnst[bun_no] = NULL;
1854 	free_down((WNN_BUF_MT *)buf, bun_no, bun_no2);
1855 
1856 	if((ret = tan_conv1((WNN_BUF_MT *)buf, yomi, bun_no, bun_no2,
1857 	    use_maep & WNN_USE_MAE, ich_shop,
1858 	    0, nhinsi, hlist)) == -1)
1859 		return(-1);
1860 
1861 	yomi[ichbn_len] = ytmp;
1862 	if(ytmp){
1863 		int maep;
1864 		if(ich_shop){
1865 			maep = use_maep & ~WNN_USE_MAE;
1866 		} else{
1867 			maep = use_maep | WNN_USE_MAE;
1868 		}
1869 		if(ren_conv1((WNN_BUF_MT *)buf, yomi + ichbn_len, ret, ret,
1870 		    maep, 0, 0, NULL, fi_flag) == -1)
1871 			return(-1);
1872 	}
1873 	buf->bun[bun_no]->nobi_top = 1;
1874 	buf->down_bnst[bun_no] = b1;
1875 	return(0);
1876 } /* End of nobi_conv_sub */
1877 
1878 int
jl_nobi_conv_e2(buf,env,bun_no,ichbn_len,bun_no2,use_maep,ich_shop)1879 jl_nobi_conv_e2(buf, env, bun_no, ichbn_len, bun_no2, use_maep, ich_shop)
1880 register struct wnn_buf *buf;
1881 struct wnn_env *env;
1882 int ichbn_len, use_maep, ich_shop;
1883 register int bun_no, bun_no2;
1884 {
1885 	w_char yomi[LENGTHCONV], ytmp;
1886 	int ret;
1887 	int len1;
1888 	int x;
1889 
1890 	if(!buf) return(-1);
1891 	buf_wnn_errorno_set = 0;
1892 	if(bun_no < 0) {
1893 		return(-1);
1894 	}
1895 	if(bun_no2 >= buf->bun_suu || bun_no2 < 0) bun_no2 = buf->bun_suu;
1896 
1897 	len1 = jl_get_yomi_body((WNN_BUF_MT *)buf, bun_no, bun_no2, yomi, sizeof(yomi) / sizeof(w_char));
1898 	ytmp = yomi[ichbn_len];
1899 	if(len1 < ichbn_len){
1900 		ichbn_len = len1;
1901 	}
1902 	yomi[ichbn_len] = 0;
1903 
1904 	if(buf->bun[bun_no]->nobi_top != 1){  /* need to add down_bnst */
1905 		if(buf->bun[bun_no]) add_down_bnst((WNN_BUF_MT *)buf, bun_no,
1906 		    buf->bun[bun_no]);
1907 		if(bun_no + 1 < buf->bun_suu){
1908 			if(ichbn_len < jl_yomi_len_body((WNN_BUF_MT *)buf, bun_no,
1909 			    bun_no + 1)){
1910 				add_down_bnst((WNN_BUF_MT *)buf, bun_no + 1,
1911 				    buf->bun[bun_no + 1]);
1912 				free_down((WNN_BUF_MT *)buf, bun_no + 2, bun_no2);
1913 			} else{
1914 				add_down_bnst((WNN_BUF_MT *)buf, bun_no, buf->bun[bun_no + 1]);
1915 				free_down((WNN_BUF_MT *)buf, bun_no + 1, bun_no2);
1916 			}
1917 		}
1918 	}
1919 
1920 	if((ret = tan_conv1((WNN_BUF_MT *)buf, yomi, bun_no, bun_no2,
1921 	    use_maep & WNN_USE_MAE, ich_shop, 0, 0, NULL)) == -1){
1922 		return(-1);
1923 	}
1924 
1925 	buf->env = env;
1926 
1927 	yomi[ichbn_len] = ytmp;
1928 	if(ytmp){
1929 		int maep;
1930 		if(ich_shop){
1931 			maep = use_maep & ~WNN_USE_MAE;
1932 		} else{
1933 			maep = use_maep | WNN_USE_MAE;
1934 		}
1935 		if(ren_conv1((WNN_BUF_MT *)buf, yomi + ichbn_len, ret, ret,
1936 		    maep, 0, 0, NULL, 0) == -1){
1937 			return(-1);
1938 		}
1939 	}
1940 	buf->bun[bun_no]->nobi_top = 1;
1941 	x = buf->bun_suu;
1942 
1943 	return x;
1944 }
1945 
1946 int
jl_kill(buf,bun_no,bun_no2)1947 jl_kill(buf, bun_no, bun_no2)
1948 struct wnn_buf *buf;
1949 register int bun_no, bun_no2;
1950 {
1951 	int x;
1952 
1953 	if(!buf) return(0);
1954 	buf_wnn_errorno_set = 0;
1955 	if(bun_no < 0) {
1956 		return(0);
1957 	}
1958 	if(bun_no2 < bun_no || bun_no2 < 0) bun_no2 = buf->bun_suu;
1959 	free_zenkouho((WNN_BUF_MT *)buf);     /* toriaezu */
1960 	free_down((WNN_BUF_MT *)buf, bun_no, bun_no2);
1961 	free_bun((WNN_BUF_MT *)buf, bun_no, bun_no2);
1962 	memcpy((char *)&buf->bun[bun_no], (char *)&buf->bun[bun_no2],
1963 	    (buf->bun_suu - bun_no2) * sizeof(WNN_BUN *));
1964 	memcpy((char *)&buf->down_bnst[bun_no], (char *)&buf->down_bnst[bun_no2],
1965 	    (buf->bun_suu - bun_no2) * sizeof(WNN_BUN *));
1966 	buf->bun_suu -= bun_no2 - bun_no;
1967 	x = buf->bun_suu;
1968 	return x;
1969 }
1970 
1971 int
jl_zenkouho(buf,bun_no,use_maep,uniq_level)1972 jl_zenkouho(buf, bun_no, use_maep, uniq_level)
1973 register struct wnn_buf *buf;
1974 int bun_no, use_maep, uniq_level;
1975 {
1976 	int x;
1977 
1978 	if(!buf) return(-1);
1979 	buf_wnn_errorno_set = 0;
1980 	x = zen_conv_sho1(buf, bun_no, use_maep, uniq_level, 0, 0, NULL);
1981 	return x;
1982 }
1983 
1984 static int
zen_conv_sho1(buf,bun_no,use_maep,uniq_level,fuku,nhinsi,hlist)1985 zen_conv_sho1(buf, bun_no, use_maep, uniq_level, fuku, nhinsi, hlist)
1986 register struct wnn_buf *buf;
1987 int bun_no, use_maep, uniq_level, fuku, nhinsi, *hlist;
1988 {
1989 	register struct wnn_buf_mt *buf_m = (WNN_BUF_MT *)buf;
1990 	int cnt;
1991 	w_char yomi[LENGTHBUNSETSU], yomi1[LENGTHBUNSETSU];
1992 	struct wnn_sho_bunsetsu *sp;
1993 	register int k;
1994 	int x;
1995 	int nobi_top;
1996 
1997 	jl_get_yomi_body(buf_m, bun_no, bun_no + 1, yomi, sizeof(yomi) / sizeof(w_char));
1998 	if (use_maep & WNN_USE_MAE && bun_no > 0) {
1999 		dumbhinsi = buf->bun[bun_no - 1]->hinsi;
2000 		jl_get_yomi_body(buf_m, bun_no - 1, bun_no, yomi1, sizeof(yomi1) / sizeof(w_char));
2001 		mae_fzk = yomi1 + buf->bun[bun_no - 1]->jirilen;
2002 	} else {
2003 		dumbhinsi = WNN_BUN_SENTOU;
2004 		mae_fzk = (w_char *)0;
2005 	}
2006 	if(use_maep & WNN_USE_ATO && bun_no + 1 < buf->bun_suu){
2007 		syuutanv = buf->bun[bun_no+1]->kangovect;
2008 		syuutanv1 = WNN_VECT_KANZEN;
2009 		buf->zenkouho_endvect = syuutanv;
2010 	} else{
2011 		syuutanv = WNN_VECT_KANZEN;
2012 		syuutanv1 = WNN_VECT_NO;
2013 		if(bun_no + 1 < buf->bun_suu){
2014 			buf->bun[bun_no + 1]->dai_top = 1;
2015 		}
2016 		buf->zenkouho_endvect = -1;
2017 	}
2018 
2019 	if(!(buf->env)) return(-1);
2020 	if(fuku == 0 && nhinsi == 0) {
2021 		if(buf->bun[bun_no]->fukugou == 0 && buf->bun[bun_no]->num_hinsi == 0) {
2022 			if((cnt = js_kanzen_sho(buf->env, yomi, dumbhinsi, mae_fzk,
2023 			    syuutanv, syuutanv1, &buf_rb)) < 0){
2024 				if_dead_disconnect_b(buf_m);
2025 				return(-1);
2026 			}
2027 		} else {
2028 			fuku = buf->bun[bun_no]->fukugou;
2029 			nhinsi = buf->bun[bun_no]->num_hinsi;
2030 			hlist = buf->bun[bun_no]->hinsi_list;
2031 			if((cnt = js_henkan_with_data(buf->env, fuku, nhinsi, hlist,
2032 			    WNN_KANZEN_SHO, yomi, dumbhinsi, mae_fzk, syuutanv,
2033 			    syuutanv1, WNN_VECT_BUNSETSU, &buf_rb)) < 0){
2034 				if_dead_disconnect_b(buf_m);
2035 				return(-1);
2036 			}
2037 		}
2038 	} else {
2039 		if((cnt = js_henkan_with_data(buf->env, fuku, nhinsi, hlist,
2040 		    WNN_KANZEN_SHO, yomi, dumbhinsi, mae_fzk, syuutanv,
2041 		    syuutanv1, WNN_VECT_BUNSETSU, &buf_rb)) < 0){
2042 			if_dead_disconnect_b(buf_m);
2043 			return(-1);
2044 		}
2045 	}
2046 
2047 	sp = (struct wnn_sho_bunsetsu *)buf_rb.buf;
2048 	free_zenkouho(buf_m);
2049 	nobi_top = buf->bun[bun_no]->nobi_top;
2050 	/* ��ʸ�ἡ������ä����ȡ��ʻ�����Ѵ��ʾ�ʸ��ˤ���������� (cnt) ��
2051 	       0 �ξ����μ�����ꥹ�Ȥ�ɽ�������Τǡ������å����ɲä���������
2052 	       ���������褦�ˤ��롣06/05/96 */
2053 	if((buf->bun[bun_no]->from_zenkouho & 1) == BUN || cnt == 0){
2054 		set_sho(buf->bun[bun_no], &buf->zenkouho[0]);
2055 		buf->zenkouho_suu = 1;
2056 		/* Connection information of Old bunsetsu
2057 						 * May not be correct.
2058 						 */
2059 		k = get_c_jikouho(sp, cnt, buf->bun[bun_no]);
2060 		if(k >= 0){
2061 			buf->zenkouho[0]->dai_top = (sp[k].status == WNN_CONNECT)? 0:1;
2062 			buf->zenkouho[0]->dai_end = (sp[k].status_bkwd == WNN_CONNECT_BK)? 0:1;
2063 		}
2064 		if(uniq_level || k < 0){
2065 			insert_sho(buf_m, ZENKOUHO, -1, -1, sp, cnt, uniq_level, fuku, nhinsi, hlist);
2066 		} else{
2067 			insert_sho(buf_m, ZENKOUHO, -1, -1, sp, k, uniq_level, fuku, nhinsi, hlist);
2068 			insert_sho(buf_m, ZENKOUHO, -1, -1, sp + k + 1, cnt - k - 1,
2069 			    uniq_level, fuku, nhinsi, hlist);
2070 		}
2071 		buf->c_zenkouho = 0;
2072 	} else{
2073 		insert_sho(buf_m, ZENKOUHO, -1, -1, sp, cnt, uniq_level, fuku, nhinsi, hlist);
2074 		k = get_c_jikouho_from_zenkouho(buf_m, buf->bun[bun_no]);
2075 		if(k < 0){
2076 			k = 0;	/* Only when the kouho has been removed from dict. */
2077 		}
2078 		buf->c_zenkouho = k;
2079 	}
2080 	buf->zenkouho_bun = bun_no;
2081 	buf->zenkouho_end_bun = bun_no + 1;
2082 	buf->zenkouho_daip = SHO;
2083 	for(k = 0 ; k < buf->zenkouho_suu; k++){
2084 		/* ������ꥹ�Ȥ���Ƭ�θ�����Ф��Ƥ�ɬ�����ӥåȤ���Ȥ��褦�ˤ���
2085 			   ��ʸ��Ĺ�ǽ����Ѻ�ͥ��� */
2086 		if(k == 0 ||
2087 		    (buf->zenkouho[k]->ima && buf->zenkouho[k]->dic_no != -1)){
2088 			add_down_bnst(buf_m, bun_no, buf->zenkouho[k]);
2089 		}
2090 		/*
2091 			 * ʸ�῭�Ф�/�̤��Ԥä��弡������ä����ˤϡ��������ʸ�����
2092 			 * �ˤ�ʸ�῭�Ф�/�̤�ξ����Ĥ��Ƥ�����ʸ���ڤ�ؽ��ǻ��Ѥ��롣
2093 			 */
2094 		if (nobi_top) buf->zenkouho[k]->nobi_top = 1;
2095 	}
2096 	x = buf->c_zenkouho;
2097 	return x;
2098 }
2099 
2100 int
jl_zenkouho_hinsi_flag(buf,bun_no,use_maep,uniq_level,hinsi_op)2101 jl_zenkouho_hinsi_flag(buf, bun_no, use_maep, uniq_level, hinsi_op)
2102 register struct wnn_buf *buf;
2103 int bun_no, use_maep, uniq_level, hinsi_op;
2104 {
2105 	int x, hno;
2106 	w_char tmp[64];
2107 
2108 	if(!buf) return(-1);
2109 	buf_wnn_errorno_set = 0;
2110 	if(strncmp(js_get_lang(buf->env), WNN_J_LANG, 5)) {
2111 		return(-1);
2112 	}
2113 	if(hinsi_op == WNN_ZIP)
2114 		_Sstrcpy(tmp, WNN_HINSI_ZIPCODE);
2115 	else if(hinsi_op == WNN_TEL)
2116 		_Sstrcpy(tmp, WNN_HINSI_TELNO);
2117 	else if(hinsi_op == WNN_TANKAN)
2118 		_Sstrcpy(tmp, WNN_HINSI_TANKAN);
2119 	else {
2120 		return(-1);
2121 	}
2122 	if((hno = jl_hinsi_number_e(buf->env, tmp)) == -1) {
2123 		return(-1);
2124 	}
2125 	x = zen_conv_sho1(buf, bun_no, use_maep, uniq_level, 0, 1, &hno);
2126 	return x;
2127 }
2128 
2129 int
jl_zenkouho_with_hinsi_name(buf,bun_no,use_maep,uniq_level,nhinsi,hname)2130 jl_zenkouho_with_hinsi_name(buf, bun_no, use_maep, uniq_level, nhinsi, hname)
2131 register struct wnn_buf *buf;
2132 int bun_no, use_maep, uniq_level, nhinsi;
2133 char **hname;
2134 {
2135 	int x, i, hsize, *hno = NULL;
2136 	w_char tmp[64];
2137 
2138 	if(!buf) return(-1);
2139 	buf_wnn_errorno_set = 0;
2140 	if(nhinsi){
2141 		hsize = abs(nhinsi);
2142 		hno = (int *)malloc(hsize * sizeof(int));
2143 		for(i = 0; i < hsize; i++) {
2144 			_Sstrcpy(tmp, hname[i]);
2145 			if((hno[i] = jl_hinsi_number_e(buf->env, tmp)) == -1) {
2146 				free((char *)hno);
2147 				return(-1);
2148 			}
2149 		}
2150 	}
2151 	x = zen_conv_sho1(buf, bun_no, use_maep, uniq_level, 0, nhinsi, hno);
2152 	if(nhinsi) free((char *)hno);
2153 	return x;
2154 }
2155 
2156 int
jl_zenkouho_dai(buf,bun_no,bun_no2,use_maep,uniq_level)2157 jl_zenkouho_dai(buf, bun_no, bun_no2, use_maep, uniq_level)
2158 register struct wnn_buf *buf;
2159 int bun_no, bun_no2, use_maep, uniq_level;
2160 {
2161 	int x;
2162 
2163 	if(!buf) return(-1);
2164 	buf_wnn_errorno_set = 0;
2165 	x = zen_conv_dai1(buf, bun_no, bun_no2, use_maep, uniq_level, 0, 0, NULL);
2166 	return x;
2167 }
2168 
2169 static int
zen_conv_dai1(buf,bun_no,bun_no2,use_maep,uniq_level,fuku,nhinsi,hlist)2170 zen_conv_dai1(buf, bun_no, bun_no2, use_maep, uniq_level, fuku, nhinsi, hlist)
2171 register struct wnn_buf *buf;
2172 int bun_no, bun_no2, use_maep, uniq_level, fuku, nhinsi, *hlist;
2173 {
2174 	register struct wnn_buf_mt *buf_m = (WNN_BUF_MT *)buf;
2175 	int cnt;
2176 	w_char yomi[LENGTHBUNSETSU], yomi1[LENGTHBUNSETSU];
2177 	struct wnn_dai_bunsetsu *dp;
2178 	int tmp;
2179 	register int k;
2180 	int x;
2181 	int nobi_top;
2182 
2183 	if(bun_no2 > (tmp = dai_end(buf_m, bun_no)) ||
2184 	    bun_no2 < 0) bun_no2 = tmp;
2185 	jl_get_yomi_body(buf_m, bun_no, bun_no2, yomi, sizeof(yomi) / sizeof(w_char));
2186 	if (use_maep & WNN_USE_MAE && bun_no > 0) {
2187 		dumbhinsi = buf->bun[bun_no - 1]->hinsi;
2188 		jl_get_yomi_body(buf_m, bun_no - 1, bun_no, yomi1, sizeof(yomi1) / sizeof(w_char));
2189 		mae_fzk = yomi1 + buf->bun[bun_no - 1]->jirilen;
2190 	} else {
2191 		dumbhinsi = WNN_BUN_SENTOU;
2192 		mae_fzk = (w_char *)0;
2193 	}
2194 	if(use_maep & WNN_USE_ATO && bun_no2 < buf->bun_suu){
2195 		syuutanv = buf->bun[bun_no2]->kangovect;
2196 		syuutanv1 = WNN_VECT_KANZEN;
2197 		buf->zenkouho_endvect = syuutanv;
2198 	} else{
2199 		syuutanv = WNN_VECT_KANZEN;
2200 		syuutanv1 = WNN_VECT_NO;
2201 		if(bun_no2 < buf->bun_suu){
2202 			buf->bun[bun_no2]->dai_top = 1;
2203 		}
2204 		buf->zenkouho_endvect = -1;
2205 	}
2206 	if(!(buf->env)) return(-1);
2207 	if(fuku == 0 && nhinsi == 0) {
2208 		if(buf->bun[bun_no]->fukugou == 0 && buf->bun[bun_no]->num_hinsi == 0) {
2209 			if((cnt = js_kanzen_dai(buf->env, yomi, dumbhinsi, mae_fzk,
2210 			    syuutanv, syuutanv1, &buf_rb)) < 0){
2211 				if_dead_disconnect_b(buf_m);
2212 				return(-1);
2213 			}
2214 		} else {
2215 			fuku = buf->bun[bun_no]->fukugou;
2216 			nhinsi = buf->bun[bun_no]->num_hinsi;
2217 			hlist = buf->bun[bun_no]->hinsi_list;
2218 			if((cnt = js_henkan_with_data(buf->env, fuku, nhinsi, hlist,
2219 			    WNN_KANZEN_DAI, yomi, dumbhinsi, mae_fzk, syuutanv,
2220 			    syuutanv1, WNN_VECT_BUNSETSU, &buf_rb)) < 0) {
2221 				if_dead_disconnect_b(buf_m);
2222 				return(-1);
2223 			}
2224 		}
2225 	} else {
2226 		if((cnt = js_henkan_with_data(buf->env, fuku, nhinsi, hlist,
2227 		    WNN_KANZEN_DAI, yomi, dumbhinsi, mae_fzk, syuutanv,
2228 		    syuutanv1, WNN_VECT_BUNSETSU, &buf_rb)) < 0) {
2229 			if_dead_disconnect_b(buf_m);
2230 			return(-1);
2231 		}
2232 	}
2233 
2234 	dp = (struct wnn_dai_bunsetsu *)buf_rb.buf;
2235 
2236 	free_zenkouho(buf_m);
2237 	/* Wander if it is OK, that is, only when all the
2238 			 * zenkouho's are got from zenkouho_dai, we need not move
2239 			 * the current dai-bunsetsu to the top of zenkouho's
2240 			 */
2241 	for(k = bun_no; k < bun_no2; k++){
2242 		if(buf->bun[k]->from_zenkouho != ZENKOUHO_DAI)break;
2243 	}
2244 	if (k >= bun_no2) k--;
2245 	nobi_top = buf->bun[k]->nobi_top;
2246 	if(k != bun_no2){		/* move the current to the top. */
2247 		make_space_for(buf_m, ZENKOUHO, buf->zenkouho_suu, buf->zenkouho_suu,
2248 		    bun_no2 - bun_no);
2249 		set_dai(&buf->bun[bun_no], &buf->zenkouho[0], bun_no2 - bun_no);
2250 		buf->zenkouho_dai[0] = 0;
2251 		buf->zenkouho_dai[1] = bun_no2 - bun_no;
2252 		buf->zenkouho_dai_suu = 1;
2253 		buf->zenkouho_suu = bun_no2 - bun_no;
2254 		k = get_c_jikouho_dai(dp, cnt, buf->bun, bun_no);
2255 		if(k >= 0){
2256 			buf->zenkouho[0]->dai_top =
2257 			    (dp[k].sbn->status == WNN_CONNECT)? 0:1;
2258 			buf->zenkouho[bun_no2-bun_no-1]->dai_end =
2259 			    (dp[k].sbn[dp[k].sbncnt-1].status_bkwd == WNN_CONNECT_BK)? 0:1;
2260 			/* KURI *//* USO*?*/
2261 		} else if (cnt == 0) {
2262 			/* �֡��פϸ������ 0 �ʤΤǡ�dai_top, dai_end ��
2263 				       ����Ū�� 1 �ˤ��� */
2264 			buf->zenkouho[0]->dai_top = 1;
2265 			buf->zenkouho[bun_no2-bun_no-1]->dai_end = 1;
2266 		}
2267 		if(uniq_level || k < 0){
2268 			insert_dai(buf_m, ZENKOUHO, -1, -1, dp, cnt, uniq_level, fuku, nhinsi, hlist);
2269 		} else{
2270 			insert_dai(buf_m, ZENKOUHO, -1, -1, dp, k, uniq_level, fuku, nhinsi, hlist);
2271 			insert_dai(buf_m, ZENKOUHO, -1, -1, dp + k + 1, cnt - k - 1,
2272 			    uniq_level, fuku, nhinsi, hlist);
2273 		}
2274 		buf->c_zenkouho = 0;
2275 	} else{
2276 		insert_dai(buf_m, ZENKOUHO, -1, -1, dp, cnt, uniq_level, fuku, nhinsi, hlist);
2277 		k = get_c_jikouho_from_zenkouho_dai(buf_m, buf->bun[bun_no]);
2278 		if(k < 0){
2279 			k = 0;	/* Only when the kouho has been removed from dict. */
2280 		}
2281 		buf->c_zenkouho = k;
2282 	}
2283 	buf->zenkouho_bun = bun_no;
2284 	buf->zenkouho_end_bun = bun_no2;
2285 	buf->zenkouho_daip = DAI;
2286 	for(k = 0 ; k < buf->zenkouho_suu; k++){
2287 		/* ������ꥹ�Ȥ���Ƭ�θ�����Ф��Ƥ�ɬ�����ӥåȤ���Ȥ��褦�ˤ���
2288 		           ��ʸ��Ĺ�ǽ����Ѻ�ͥ��� */
2289 		if(k == 0 ||
2290 		    (buf->zenkouho[k]->ima && buf->zenkouho[k]->dic_no != -1)) {
2291 			add_down_bnst(buf_m, bun_no, buf->zenkouho[k]);
2292 		}
2293 		/*
2294 			 * ʸ�῭�Ф�/�̤��Ԥä��弡������ä����ˤϡ��������ʸ�����
2295 			 * �ˤ�ʸ�῭�Ф�/�̤�ξ����Ĥ��Ƥ�����ʸ���ڤ�ؽ��ǻ��Ѥ��롣
2296 			 */
2297 		if (nobi_top) buf->zenkouho[k]->nobi_top = 1;
2298 	}
2299 	x = buf->c_zenkouho;
2300 	return x;
2301 }
2302 
2303 int
jl_zenkouho_dai_hinsi_flag(buf,bun_no,bun_no2,use_maep,uniq_level,hinsi_op)2304 jl_zenkouho_dai_hinsi_flag(buf, bun_no, bun_no2, use_maep, uniq_level, hinsi_op)
2305 register struct wnn_buf *buf;
2306 int bun_no, bun_no2, use_maep, uniq_level, hinsi_op;
2307 {
2308 	int x, hno;
2309 	w_char tmp[64];
2310 
2311 	if(!buf) return(-1);
2312 	buf_wnn_errorno_set = 0;
2313 	if(strncmp(js_get_lang(buf->env), WNN_J_LANG, 5)) {
2314 		return(-1);
2315 	}
2316 	if(hinsi_op == WNN_ZIP)
2317 		_Sstrcpy(tmp, WNN_HINSI_ZIPCODE);
2318 	else if(hinsi_op == WNN_TEL)
2319 		_Sstrcpy(tmp, WNN_HINSI_TELNO);
2320 	else if(hinsi_op == WNN_TANKAN)
2321 		_Sstrcpy(tmp, WNN_HINSI_TANKAN);
2322 	else {
2323 		return(-1);
2324 	}
2325 	if((hno = jl_hinsi_number_e(buf->env, tmp)) == -1) {
2326 		return(-1);
2327 	}
2328 	x = zen_conv_dai1(buf, bun_no, bun_no2, use_maep, uniq_level, 0, 1, &hno);
2329 	return x;
2330 }
2331 
2332 int
jl_zenkouho_dai_with_hinsi_name(buf,bun_no,bun_no2,use_maep,uniq_level,nhinsi,hname)2333 jl_zenkouho_dai_with_hinsi_name(buf, bun_no, bun_no2, use_maep, uniq_level, nhinsi, hname)
2334 register struct wnn_buf *buf;
2335 int bun_no, bun_no2, use_maep, uniq_level, nhinsi;
2336 char **hname;
2337 {
2338 	int x, i, hsize, *hno = NULL;
2339 	w_char tmp[64];
2340 
2341 	if(!buf) return(-1);
2342 	buf_wnn_errorno_set = 0;
2343 	if(nhinsi){
2344 		hsize = abs(nhinsi);
2345 		hno = (int *)malloc(hsize * sizeof(int));
2346 		for(i = 0; i < hsize; i++) {
2347 			_Sstrcpy(tmp, hname[i]);
2348 			if((hno[i] = jl_hinsi_number_e(buf->env, tmp)) == -1) {
2349 				free((char *)hno);
2350 				return(-1);
2351 			}
2352 		}
2353 	}
2354 	x = zen_conv_dai1(buf, bun_no, bun_no2, use_maep, uniq_level, 0, nhinsi, hno);
2355 	if(nhinsi) free((char *)hno);
2356 	return x;
2357 }
2358 
2359 int
jl_set_jikouho(buf,offset)2360 jl_set_jikouho(buf, offset)
2361 register struct wnn_buf *buf;
2362 register int offset;
2363 {
2364 	if(!buf) return(-1);
2365 	buf_wnn_errorno_set = 0;
2366 	if(buf->zenkouho_suu <= 0) {
2367 		return(-1);
2368 	}
2369 	if(buf->zenkouho_daip == DAI){
2370 		return(-1);
2371 	}
2372 	offset = (offset + buf->zenkouho_suu) % buf->zenkouho_suu;
2373 	if(buf->zenkouho_bun+1 < buf->bun_suu && buf->zenkouho_endvect != -1)
2374 		buf->bun[buf->zenkouho_bun+1]->dai_top = buf->zenkouho[offset]->dai_end;
2375 	free_sho((WNN_BUF_MT *)buf, &buf->bun[buf->zenkouho_bun]);
2376 	set_sho(buf->zenkouho[offset], &buf->bun[buf->zenkouho_bun]);
2377 	buf->c_zenkouho = offset;
2378 	return(offset);
2379 }
2380 
2381 
2382 int
jl_set_jikouho_dai(buf,offset)2383 jl_set_jikouho_dai(buf, offset)
2384 register struct wnn_buf *buf;
2385 int offset;
2386 {
2387 	register int st, end, bun, k;
2388 
2389 	if(!buf) return(-1);
2390 	buf_wnn_errorno_set = 0;
2391 	if(buf->zenkouho_suu <= 0) {
2392 		return(-1);
2393 	}
2394 	if(buf->zenkouho_daip == SHO){
2395 		return(-1);
2396 	}
2397 	offset = (offset + buf->zenkouho_dai_suu) % buf->zenkouho_dai_suu;
2398 	if(buf->zenkouho_end_bun < buf->bun_suu && buf->zenkouho_endvect != -1)
2399 		buf->bun[buf->zenkouho_end_bun]->dai_top =
2400 		    buf->zenkouho[buf->zenkouho_dai[offset+1]-1]->dai_end;
2401 	free_bun((WNN_BUF_MT *)buf, buf->zenkouho_bun, buf->zenkouho_end_bun);
2402 	st = buf->zenkouho_dai[offset];
2403 	end = buf->zenkouho_dai[offset + 1];
2404 	make_space_for((WNN_BUF_MT *)buf, BUN, buf->zenkouho_bun,
2405 	    buf->zenkouho_end_bun, end - st);
2406 	for(bun = buf->zenkouho_bun, k = st; k < end;){
2407 		set_sho(buf->zenkouho[k++], &buf->bun[bun++]);
2408 	}
2409 	buf->zenkouho_end_bun = buf->zenkouho_bun + end - st;
2410 	buf->c_zenkouho = offset;
2411 	return(offset);
2412 }
2413 
2414 /*:::DOC_START
2415  *
2416  *    Function Name: do_autolearning
2417  *    Description  : ��ư�ؽ���Ԥ�
2418  *		     js_auto_word_add()��Ƥ�
2419  *    Parameter    :
2420  *         env :      (In) wnn_env��¤�ΤؤΥݥ���
2421  *         type :     (In) �ؽ����륿����(��������/ʸ���ڤ�)
2422  *         yomi :     (In) �ɤ�
2423  *         kanji :    (In) ����
2424  *         hinsi :    (In) �ʻ�
2425  *
2426  *    Return value : 0==SUCCESS, -1==ERROR
2427  *
2428  *    Revision history:
2429  *	15-May-96: js_autolearning_word_add() �����顼�Ǥ� env ��
2430  *			 �ؽ�������ѹ����ʤ�
2431  *
2432  *:::DOC_END
2433  */
2434 static int
do_autolearning(env,type,yomi,kanji,hinsi)2435 do_autolearning(env, type, yomi, kanji, hinsi)
2436 struct wnn_env *env;
2437 int type;
2438 w_char *yomi, *kanji;
2439 int hinsi;
2440 {
2441 	int ret;
2442 
2443 	ret = js_autolearning_word_add(env, type, yomi, kanji, NULL, hinsi, 0);
2444 	return(ret);
2445 }
2446 
2447 
2448 static int
muhenkan_auto_learning(buf,wb)2449 muhenkan_auto_learning(buf, wb)
2450 struct wnn_buf *buf;
2451 register WNN_BUN *wb;
2452 {
2453 	int hinsi;
2454 	w_char yomi[LENGTHYOMI];
2455 	w_char kanji[LENGTHKANJI];
2456 
2457 	wnn_area(wb, yomi, WNN_YOMI, sizeof(yomi) / sizeof(w_char));
2458 	wnn_area(wb, kanji, WNN_KANJI, sizeof(kanji) / sizeof(w_char));
2459 	yomi[wb->jirilen] = (w_char)0;
2460 	kanji[wb->real_kanjilen] = (w_char)0;
2461 	if(wb->entry == WNN_IKEIJI_ENTRY)
2462 		hinsi = wb->hinsi;
2463 	else
2464 		hinsi = wnn_meisi;
2465 	return(do_autolearning(buf->env, WNN_MUHENKAN_LEARNING, yomi, kanji,
2466 	    hinsi));
2467 }
2468 
2469 static int
bunsetsugiri_auto_learning(buf,wb,bun_no,bun_no2)2470 bunsetsugiri_auto_learning(buf, wb, bun_no, bun_no2)
2471 register struct wnn_buf *buf;
2472 register WNN_BUN *wb;
2473 int bun_no, bun_no2;
2474 {
2475 	register WNN_BUN *wb1;
2476 	w_char yomi[LENGTHYOMI];
2477 	w_char kanji[LENGTHKANJI];
2478 	int yomilen, kanjilen, fuzokugolen;
2479 
2480 	wnn_area(wb, yomi, WNN_YOMI, sizeof(yomi) / sizeof(w_char));
2481 	wnn_area(wb, kanji, WNN_KANJI, sizeof(kanji) / sizeof(w_char));
2482 	yomilen = wb->yomilen;
2483 	kanjilen = wb->kanjilen;
2484 	wb1 = buf->bun[bun_no+1];
2485 	wnn_area(wb1, &yomi[yomilen], WNN_YOMI, sizeof(yomi) / sizeof(w_char) - yomilen);
2486 	wnn_area(wb1, &kanji[kanjilen], WNN_KANJI, sizeof(kanji) / sizeof(w_char) - kanjilen);
2487 	yomilen += wb1->yomilen;
2488 	kanjilen += wb1->kanjilen;
2489 	fuzokugolen = wb1->yomilen - wb1->jirilen;
2490 	yomi[yomilen - fuzokugolen] = (w_char)0;
2491 	kanji[kanjilen - fuzokugolen] = (w_char)0;
2492 	return(do_autolearning(buf->env, WNN_BUNSETSUGIRI_LEARNING, yomi, kanji,
2493 	    wb1->hinsi));
2494 }
2495 
2496 static int
rendaku_learning(buf,mode,wb1,bun_no,bun_no2)2497 rendaku_learning(buf, mode, wb1, bun_no, bun_no2)
2498 register struct wnn_buf *buf;
2499 register WNN_BUN *wb1;
2500 int mode, bun_no, bun_no2;
2501 {
2502 	register WNN_BUN *wb;
2503 	w_char yomi[LENGTHYOMI];
2504 	w_char kanji[LENGTHKANJI];
2505 	int yomilen, kanjilen, fuzokugolen;
2506 
2507 	wb = buf->bun[bun_no];
2508 	wnn_area(wb, yomi, WNN_YOMI, sizeof(yomi) / sizeof(w_char));
2509 	wnn_area(wb, kanji, WNN_KANJI, sizeof(kanji) / sizeof(w_char));
2510 	yomilen = wb->yomilen;
2511 	kanjilen = wb->kanjilen;
2512 	wnn_area(wb1, &yomi[yomilen], WNN_YOMI, sizeof(yomi) / sizeof(w_char) - yomilen);
2513 	wnn_area(wb1, &kanji[kanjilen], WNN_KANJI, sizeof(kanji) / sizeof(w_char) - kanjilen);
2514 	yomilen += wb1->yomilen;
2515 	kanjilen += wb1->kanjilen;
2516 	fuzokugolen = wb1->yomilen - wb1->jirilen;
2517 	yomi[yomilen - fuzokugolen] = (w_char)0;
2518 	kanji[kanjilen - fuzokugolen] = (w_char)0;
2519 	if (mode != WNN_DIC_RW) {
2520 		if (js_temporary_word_add(buf->env, yomi, kanji, NULL, wnn_meisi, 0) == -1) {
2521 			if (env_wnn_errorno_eql == WNN_JSERVER_DEAD) {
2522 				jl_disconnect_body(buf->env);
2523 			}
2524 			return(-1);
2525 		}
2526 		return(0);
2527 	}
2528 	return(do_autolearning(buf->env, WNN_BUNSETSUGIRI_LEARNING, yomi, kanji,
2529 	    wnn_meisi));
2530 }
2531 
2532 /*:::DOC_START
2533  *
2534  *    Function Name: jl_update_hindo
2535  *    Description  : ����ʸ�ᤫ�����پ���ʺ��ӥåȡ����١ˤι�����
2536  *		     jlib ��Ƚ�ǤǤ���ؽ�������Ԥ�
2537  *    Parameter    :
2538  *         buf :      (In) �Хåե��ؤΥݥ���
2539  *         bun_no :   (In) ���ꤷ��ʸ�����Ƭʸ���ֹ�
2540  *         bun_no2 :  (In) ���ꤷ��ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
2541  *
2542  *    Return value : 0==SUCCESS, -1==ERROR
2543  *
2544  *    Revision history:
2545  *
2546  *:::DOC_END
2547  */
2548 int
jl_update_hindo(buf,bun_no,bun_no2)2549 jl_update_hindo(buf, bun_no, bun_no2)
2550 register struct wnn_buf *buf;
2551 int bun_no, bun_no2;
2552 {
2553 	register int k;
2554 	register WNN_BUN *wb;
2555 
2556 	if(!buf) return(-1);
2557 	buf_wnn_errorno_set = 0;
2558 	if(bun_no < 0 || !(buf->env)) {
2559 		return(-1);
2560 	}
2561 	if(bun_no2 >= buf->bun_suu || bun_no2 < 0) bun_no2 = buf->bun_suu;
2562 
2563 
2564 	if(
2565        /* ���ӥåȤ���Ȥ��٤�����κ��ӥåȤ���Ȥ� */
2566 	set_ima_off(buf, bun_no, bun_no2, 0) == -1 ||
2567 	    /* jlib ���Ƚ�ǤǤ���ؽ�������Ԥ� */
2568 	optimize_in_lib(buf, bun_no, bun_no2) == -1) {
2569 		if (buf_wnn_errorno_eql == WNN_JSERVER_DEAD) goto ERROR_RET;
2570 	}
2571 
2572 	/* ���ꤷ������κ��ӥåȡ����٤�夲�� */
2573 	for(k = bun_no; k < bun_no2; k++) {
2574 		if(buf->bun[k]->hindo_updated != 1) continue;
2575 		buf->bun[k]->hindo_updated = 2;
2576 		wb = buf->bun[k];
2577 		if(js_hindo_set(buf->env, wb->dic_no, wb->entry,
2578 		    WNN_IMA_ON, WNN_HINDO_INC) == -1){
2579 			if (buf_wnn_errorno_eql == WNN_JSERVER_DEAD) goto ERROR_RET;
2580 		}
2581 	}
2582 
2583 	/* �ؽ�����ư�����ֳ�������ã�����顢��ư�����֤�Ԥ� */
2584 	kakutei_count ++;
2585 	if(buf->env->autosave > 0 && kakutei_count >= buf->env->autosave) {
2586 		jl_dic_save_all_e_body(buf->env);
2587 		kakutei_count = 0;
2588 	}
2589 
2590 	return(0);
2591 
2592 ERROR_RET:
2593 	jl_disconnect_body(buf->env);
2594 	return(-1);
2595 } /* End of jl_update_hindo */
2596 
2597 /*:::DOC_START
2598  *
2599  *    Function Name: jl_optimize_fi
2600  *    Description  : ����ʸ�ᤫ�����پ���ʺ��ӥåȡ����١ˤι����ȡ�
2601  *                   Wnn5 ���ɲä����ؽ������ȣƣɳؽ�������Ԥ�
2602  *    Parameter    :
2603  *         buf :      (In) �Хåե��ؤΥݥ���
2604  *         bun_no :   (In) ���ꤷ��ʸ�����Ƭʸ���ֹ�
2605  *         bun_no2 :  (In) ���ꤷ��ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
2606  *
2607  *    Return value : 0==SUCCESS, -1==ERROR
2608  *
2609  *    Revision history:
2610  *
2611  *:::DOC_END
2612  */
2613 int
jl_optimize_fi(buf,bun_no,bun_no2)2614 jl_optimize_fi(buf, bun_no, bun_no2)
2615 register struct wnn_buf *buf;
2616 int bun_no, bun_no2;
2617 {
2618 	if(!buf) return(-1);
2619 	buf_wnn_errorno_set = 0;
2620 	if(bun_no < 0 || !(buf->env)) {
2621 		return(-1);
2622 	}
2623 	if(strncmp(js_get_lang(buf->env), WNN_J_LANG, 5)) {
2624 		return(jl_update_hindo(buf, bun_no, bun_no2));
2625 	}
2626 	if(bun_no2 >= buf->bun_suu || bun_no2 < 0) bun_no2 = buf->bun_suu;
2627 
2628 
2629 	if(
2630        /* ���ӥåȤ���Ȥ��٤�����ȣƣ���³�ط��κ��ӥåȤ���Ȥ� */
2631 	set_ima_off(buf, bun_no, bun_no2, 1) == -1 ||
2632 	    /* jlib ���Ƚ�ǤǤ���ؽ�������Ԥ� */
2633 	optimize_in_lib(buf, bun_no, bun_no2) == -1 ||
2634 	    /* server ���Ƚ�Ǥ��� Wnn5 �ؽ������ȣƣɳؽ�������Ԥ� */
2635 	optimize_in_server(buf, bun_no, bun_no2) == -1) {
2636 		if (buf_wnn_errorno_eql == WNN_JSERVER_DEAD) goto ERROR_RET;
2637 	}
2638 
2639 	/* �ؽ�����ư�����ֳ�������ã�����顢��ư�����֤�Ԥ� */
2640 	kakutei_count ++;
2641 	if(buf->env->autosave > 0 && kakutei_count >= buf->env->autosave) {
2642 		jl_dic_save_all_e_body(buf->env);
2643 		kakutei_count = 0;
2644 	}
2645 
2646 	return(0);
2647 ERROR_RET:
2648 	jl_disconnect_body(buf->env);
2649 	return(-1);
2650 } /* End of jl_optimize_fi */
2651 
2652 /*:::DOC_START
2653  *
2654  *    Function Name: jl_reset_prev_bun
2655  *    Description  : ������ʸ��������������
2656  *    Parameter    :
2657  *         buf :      (In) �Хåե��ؤΥݥ���
2658  *
2659  *    Return value : 0==SUCCESS, -1==ERROR
2660  *
2661  *    Revision history:
2662  *
2663  *:::DOC_END
2664  */
2665 int
jl_reset_prev_bun(buf)2666 jl_reset_prev_bun(buf)
2667 register struct wnn_buf *buf;
2668 {
2669 	int i;
2670 
2671 	if(!buf) return(-1);
2672 	buf_wnn_errorno_set = 0;
2673 	if(!(buf->env)) {
2674 		return(-1);
2675 	}
2676 
2677 	for(i = 0; i < WNN_PREV_BUN_SUU; i++) buf->prev_bun[i].dic_no = -2;
2678 
2679 	return(0);
2680 } /* End of jl_reset_prev_bun */
2681 
2682 /*:::DOC_START
2683  *
2684  *    Function Name: set_ima_off
2685  *    Description  : �Ѵ��˻��Ѥ���ʤ��ä�����κ��ӥåȤ���Ȥ����ƣ��Ѵ����
2686  *		     ���Ѥ����ƣ���³�ط��κ��ӥåȤ��٤���Ȥ�
2687  *    Parameter    :
2688  *         buf :      (In) �Хåե��ؤΥݥ���
2689  *         bun_no :   (In) ���ꤷ��ʸ�����Ƭʸ���ֹ�
2690  *         bun_no2 :  (In) ���ꤷ��ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
2691  *         fi_flag :  (In) �ƣɳؽ��ʤ��ʤ�������˥ե饰
2692  *
2693  *    Return value : 0==SUCCESS, -1==ERROR
2694  *
2695  *    Revision history:
2696  *
2697  *:::DOC_END
2698  */
2699 static int
set_ima_off(buf,bun_no,bun_no2,fi_flag)2700 set_ima_off(buf, bun_no, bun_no2, fi_flag)
2701 register struct wnn_buf *buf;
2702 int bun_no, bun_no2, fi_flag;
2703 {
2704 	register int k;
2705 	register WNN_BUN *wb;
2706 
2707 	/* ����κ��ӥåȤ���Ȥ� */
2708 	for(k = bun_no; k < bun_no2; k++){
2709 		if(buf->bun[k]->hindo_updated == 1) continue;
2710 		for(wb = buf->down_bnst[k]; wb; wb = wb->down){
2711 			if(wb->bug == 1) break;
2712 			wb->bug = 1;
2713 			if(wb->dic_no != -1){
2714 				if(js_hindo_set(buf->env, wb->dic_no, wb->entry,
2715 				    WNN_IMA_OFF, WNN_HINDO_NOP) == -1) {
2716 					if (buf_wnn_errorno_eql == WNN_JSERVER_DEAD)
2717 						return(-1);
2718 				}
2719 			}
2720 		}
2721 	}
2722 	free_down((WNN_BUF_MT *)buf, bun_no, bun_no2);
2723 
2724 	/* �ƣ���³�ط��κ��ӥåȤ���Ȥ� */
2725 	if(fi_flag) {
2726 		if(js_set_fi_priority(buf->env, &(buf->fi_rb)) == -1) {
2727 			if (buf_wnn_errorno_eql == WNN_JSERVER_DEAD)
2728 				return(-1);
2729 		}
2730 		/* �ƣ���³�ط�������¤�Τν���� */
2731 		buf->fi_rb.num = 0;
2732 	}
2733 
2734 	return(0);
2735 } /* End of set_ima_off */
2736 
2737 /*:::DOC_START
2738  *
2739  *    Function Name: optimize_in_lib
2740  *    Description  : jlib ��ǹԤ��ؽ���������
2741  *    Parameter    :
2742  *         buf :      (In) �Хåե��ؤΥݥ���
2743  *         bun_no :   (In) ���ꤷ��ʸ�����Ƭʸ���ֹ�
2744  *         bun_no2 :  (In) ���ꤷ��ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
2745  *
2746  *    Return value : 0==SUCCESS, -1==ERROR
2747  *
2748  *    Revision history:
2749  *
2750  *:::DOC_END
2751  */
2752 static int
optimize_in_lib(buf,bun_no,bun_no2)2753 optimize_in_lib(buf, bun_no, bun_no2)
2754 register struct wnn_buf *buf;
2755 int bun_no, bun_no2;
2756 {
2757 	register int k;
2758 	register WNN_BUN *wb;
2759 
2760 	for(k = bun_no; k < bun_no2; k++){
2761 		if(buf->bun[k]->hindo_updated == 1) continue;
2762 		buf->bun[k]->hindo_updated = 1;
2763 		wb = buf->bun[k];
2764 
2765 		{
2766 			/* �Ҥ餬�ʳؽ����������ʳؽ����۷����ؽ� */
2767 			if (((wb->dic_no == -1) &&
2768 			    (buf->env->muhenkan_mode != WNN_DIC_RDONLY) &&
2769 			    ((wb->entry == WNN_KATAKANA) || (wb->entry == WNN_HIRAGANA))&&
2770 			    (wb->jirilen >= WNN_KATAKANA_LEARNING_LEN)) ||
2771 			    wb->entry == WNN_IKEIJI_ENTRY) {
2772 				int entry;
2773 
2774 				if ((entry = muhenkan_auto_learning(buf, wb)) == -1) {
2775 					if (buf_wnn_errorno_eql == WNN_JSERVER_DEAD)
2776 						return(-1);
2777 				}
2778 				wb->dic_no = WNN_MUHENKAN_DIC;
2779 				wb->entry = entry;
2780 			}
2781 
2782 			/* ��ʸ��ؽ� */
2783 			if (wb->dai_top && ((k + 1) < bun_no2) &&
2784 			    !buf->bun[k + 1]->dai_top) {
2785 				if (rendaku_learning(buf, buf->env->bunsetsugiri_mode,
2786 				    buf->bun[k + 1], k, k+1) == -1) {
2787 					if (buf_wnn_errorno_eql == WNN_JSERVER_DEAD)
2788 						return(-1);
2789 				}
2790 			} else
2791 				/* Ϣ���ؽ� */
2792 				if ((k > bun_no) && (wb->hinsi == wnn_rendaku) &&
2793 				    (buf->bun[k-1]->yomilen == buf->bun[k-1]->jirilen)) {
2794 					if (rendaku_learning(buf, buf->env->bunsetsugiri_mode, wb, k-1, k)
2795 					    == -1) {
2796 						if (buf_wnn_errorno_eql == WNN_JSERVER_DEAD)
2797 							return(-1);
2798 					}
2799 				}
2800 			else
2801 					/* ��Ƭ��(��)�ؽ� */
2802 					if (((k + 1) < bun_no2) && (wb->hinsi == wnn_settou)) {
2803 						if (rendaku_learning(buf, buf->env->bunsetsugiri_mode,
2804 						    buf->bun[k + 1], k, k+1)
2805 						    == -1) {
2806 							if (buf_wnn_errorno_eql == WNN_JSERVER_DEAD)
2807 								return(-1);
2808 						}
2809 					}
2810 			else
2811 						/* ʸ���ڤ�ؽ� */
2812 						if (wb->nobi_top &&
2813 						    (buf->env->bunsetsugiri_mode != WNN_DIC_RDONLY) &&
2814 						    ((k + 1) < bun_no2) &&
2815 						    (buf->bun[k+1]->hinsi != wnn_rendaku &&
2816 						    buf->bun[k]->hinsi != wnn_settou)) {
2817 							if (bunsetsugiri_auto_learning(buf, wb, k, bun_no2) == -1) {
2818 								if (buf_wnn_errorno_eql == WNN_JSERVER_DEAD)
2819 /* code folded from here */
2820 	return(-1);
2821 /* unfolding */
2822 							}
2823 						}
2824 		}
2825 	}
2826 	return(0);
2827 } /* End of optimize_in_lib */
2828 
2829 /*:::DOC_START
2830  *
2831  *    Function Name: optimize_in_server
2832  *    Description  : jserver ��ǹԤ��ؽ���������
2833  *    Parameter    :
2834  *         buf :     (In) �Хåե��ؤΥݥ���
2835  *         bun_no :  (In) ���ꤷ��ʸ�����Ƭʸ���ֹ�
2836  *         bun_no2 : (In) ���ꤷ��ʸ��κǽ�ʸ���ľ���ʸ���ֹ�
2837  *
2838  *    Return value : 0==SUCCESS, -1==ERROR
2839  *
2840  *    Revision history:
2841  *
2842  *:::DOC_END
2843  */
2844 static int
optimize_in_server(buf,bun_no,bun_no2)2845 optimize_in_server(buf, bun_no, bun_no2)
2846 register struct wnn_buf *buf;
2847 int bun_no, bun_no2;
2848 {
2849 	register int k, j;
2850 	register WNN_BUN *wb;
2851 
2852 	int nkouho, *dic, *entry, *ima, *hindo, *kmoji;
2853 	w_char **kouho, *tmp;
2854 	struct wnn_prev_bun *prev;
2855 
2856 	/* ���ܸ�Τߤ��ݡ��� */
2857 	if(strncmp(js_get_lang(buf->env), WNN_J_LANG, 5)) return(0);
2858 
2859 	/* ������ʸ�����ʬ����������˲ä��� */
2860 	nkouho = bun_no2 - bun_no + WNN_PREV_BUN_SUU;
2861 
2862 	if ( (dic = (int *)malloc(nkouho * sizeof(int))) == NULL )
2863 		return(-1);
2864 
2865 	if ( (entry = (int *)malloc(nkouho * sizeof(int))) == NULL ) {
2866 		free(dic);
2867 		return(-1);
2868 	}
2869 	if ( (ima = (int *)malloc(nkouho * sizeof(int))) == NULL ) {
2870 		free(dic);
2871 		free(entry);
2872 		return(-1);
2873 	}
2874 	if ( (hindo = (int *)malloc(nkouho * sizeof(int))) == NULL ) {
2875 		free(dic);
2876 		free(entry);
2877 		free(ima);
2878 		return(-1);
2879 	}
2880 	if ( (kmoji = (int *)malloc(nkouho * sizeof(int))) == NULL ) {
2881 		free(dic);
2882 		free(entry);
2883 		free(ima);
2884 		free(hindo);
2885 		return(-1);
2886 	}
2887 	if ( (kouho = (w_char **)malloc(nkouho * sizeof(w_char *))) == NULL ) {
2888 		free(dic);
2889 		free(entry);
2890 		free(ima);
2891 		free(hindo);
2892 		free(kmoji);
2893 		return(-1);
2894 	}
2895 	if ( (tmp = (w_char *)malloc(nkouho * sizeof(w_char) * LENGTHKANJI)) == NULL ) {
2896 		free(dic);
2897 		free(entry);
2898 		free(ima);
2899 		free(hindo);
2900 		free(kmoji);
2901 		free(kouho);
2902 		return(-1);
2903 	}
2904 	for(k = 0; k < nkouho; k++) {
2905 		kouho[k] = tmp;
2906 		tmp += LENGTHKANJI;
2907 	}
2908 
2909 	/* ������ʸ���������ʸ����������� */
2910 	prev = buf->prev_bun;
2911 	for(j = 0, k = WNN_PREV_BUN_SUU - 1; j < WNN_PREV_BUN_SUU; j++, k--) {
2912 		dic[j] = prev[k].dic_no;
2913 		entry[j] = prev[k].entry;
2914 		ima[j] = WNN_HINDO_NOP;
2915 		hindo[j] = WNN_HINDO_NOP;
2916 		kmoji[j] = prev[k].real_kanjilen;
2917 		wnn_Strcpy(kouho[j], prev[k].kouho);
2918 	}
2919 
2920 	for(k = WNN_PREV_BUN_SUU; k < nkouho; k++) {
2921 		wb = buf->bun[(k - WNN_PREV_BUN_SUU) + bun_no];
2922 		dic[k] = wb->dic_no;		/* �����ֹ� */
2923 		entry[k] = wb->entry;		/* ����ȥ��ֹ� */
2924 		if(wb->hindo_updated == 1) {
2925 			ima[k] = WNN_IMA_ON;	/* ���ӥåȤ�������ˡ */
2926 			hindo[k] = WNN_HINDO_INC;	/* ���٤�������ˡ */
2927 			wb->hindo_updated = 2;
2928 		} else {
2929 			ima[k] = WNN_HINDO_NOP;	/* ���ӥåȤ�������ˡ */
2930 			hindo[k] = WNN_HINDO_NOP;	/* ���٤�������ˡ */
2931 		}
2932 		kmoji[k] = wb->real_kanjilen;	/* ����ʸ��������°��ʤ���*/
2933 		wnn_area(wb, kouho[k], WNN_KANJI, LENGTHKANJI); /* ����ʸ�������°�줢���*/
2934 	}
2935 
2936 	/* ľ�����국��ʸ���������ʸ��������ʤ��Ȥ��ϡ�
2937 	       ����ʸ���ʬ�Ť�ʸ������õ�����Τ�ľ�����국��ʸ�����
2938 	       ʸ������Ф��Ƥ����褦�ˤ��� */
2939 	for(j = WNN_PREV_BUN_SUU - 1, k = WNN_PREV_BUN_SUU - (bun_no2 - bun_no) - 1;
2940 	    k >= 0; j--, k--) {
2941 		prev[j].dic_no = prev[k].dic_no;
2942 		prev[j].entry = prev[k].entry;
2943 		prev[j].real_kanjilen = prev[k].real_kanjilen;
2944 		wnn_Strcpy(prev[j].kouho, prev[k].kouho);
2945 		prev[j].jirilen = prev[k].jirilen;
2946 		prev[j].hinsi = prev[k].hinsi;
2947 	}
2948 	/* ����γ�������ľ������������������ */
2949 	for(j = 0, k = nkouho - WNN_PREV_BUN_SUU - 1;
2950 	    j < WNN_PREV_BUN_SUU && k >= 0;
2951 	    j++, k--) {
2952 		wb = buf->bun[k + bun_no];
2953 		prev[j].dic_no = wb->dic_no;
2954 		prev[j].entry = wb->entry;
2955 		prev[j].real_kanjilen = wb->real_kanjilen;
2956 		wnn_area(wb, prev[j].kouho, WNN_KANJI, LENGTHKANJI);
2957 		prev[j].jirilen = wb->jirilen;
2958 		prev[j].hinsi = wb->hinsi;
2959 	}
2960 
2961 	/* Wnn5 �ؽ��ܣƣɳؽ� */
2962 	k = js_optimize_fi(buf->env, nkouho, dic, entry, ima, hindo, kmoji, kouho);
2963 
2964 	if(k == -1) {
2965 		if (buf_wnn_errorno_eql == WNN_JSERVER_DEAD) {
2966 			free(dic);
2967 			free(entry);
2968 			free(ima);
2969 			free(hindo);
2970 			free(kmoji);
2971 			free(kouho[0]);
2972 			free(kouho);
2973 			return(-1);
2974 		}
2975 	}
2976 	free(dic);
2977 	free(entry);
2978 	free(ima);
2979 	free(hindo);
2980 	free(kmoji);
2981 	free(kouho[0]);
2982 	free(kouho);
2983 	return(0);
2984 } /* End of optimize_in_server */
2985 
2986 
2987 static w_char *
wnn_area(bp,area,kanjip,arealen)2988 wnn_area(bp, area, kanjip, arealen)
2989 WNN_BUN *bp;
2990 w_char *area;
2991 int kanjip;
2992 int arealen;
2993 {
2994 	register WNN_BUN *bp1;
2995 	register w_char *c, *end;
2996 
2997 	for (bp1 = bp ; bp1 ; bp1 = bp1->next) {
2998 		if (bp1 != bp)
2999 			c = (w_char *)bp1;
3000 			else
3001 			c = bp1->yomi;
3002 		end = (w_char *)&bp1->next;
3003 		for ( ; c < end ; ) {
3004 			if (kanjip <= 0) {
3005 				if (arealen-- <= 0)
3006 					goto out;
3007 				if ((*area++ = *c++) == 0) {
3008 					area--;
3009 					goto out;
3010 				}
3011 			} else {
3012 				if (*c++ == 0)
3013 					kanjip--;
3014 			}
3015 		}
3016 	}
3017 out:
3018 	return(area);
3019 }
3020 
3021 static int
dai_end(buf,bun_no)3022 dai_end(buf, bun_no)
3023 register struct wnn_buf_mt *buf;
3024 register int bun_no;
3025 {
3026 	bun_no++;
3027 	for(;bun_no < buf->orig.bun_suu && !buf->orig.bun[bun_no]->dai_top; bun_no++);
3028 	return(bun_no);
3029 }
3030 
3031 #define dai_end_zenkouho(buf, bun_no) (buf->zenkouho_dai[bun_no + 1])
3032 
3033 
3034 void
jl_get_zenkouho_kanji(buf,zen_num,area,arealen)3035 jl_get_zenkouho_kanji(buf, zen_num, area, arealen)
3036 register struct wnn_buf *buf;
3037 int zen_num;
3038 w_char *area;
3039 int arealen;
3040 {
3041 	register int k, end;
3042 	w_char *ret_area;
3043 
3044 	if(!buf) return;
3045 	buf_wnn_errorno_set = 0;
3046 	/* Ϣ���Ѵ� NTWnn ���ή�� */
3047 	/* Ϣ���Ѵ����⡢wnn_area() ��Ƥ� */
3048 	if(buf->zenkouho_daip==SHO || buf->zenkouho_daip == RENSOU){
3049 		wnn_area(buf->zenkouho[zen_num], area, WNN_KANJI, arealen);
3050 	} else{
3051 		end = dai_end_zenkouho(buf, zen_num);
3052 		for(k = buf->zenkouho_dai[zen_num]; k < end; k++){
3053 			ret_area = wnn_area(buf->zenkouho[k], area, WNN_KANJI, arealen);
3054 			arealen -= ret_area - area;
3055 			area = ret_area;
3056 		}
3057 	}
3058 }
3059 
3060 static int
wnn_get_area_body(buf,bun_no,bun_no2,area,kanjip,arealen)3061 wnn_get_area_body(buf, bun_no, bun_no2, area, kanjip, arealen)
3062 struct wnn_buf_mt *buf;
3063 register int bun_no, bun_no2;
3064 w_char *area;
3065 int kanjip;
3066 int arealen;
3067 {
3068 	register int k;
3069 	w_char *area1 = area;
3070 	w_char *ret_area;
3071 	int x;
3072 
3073 	if(bun_no < 0) {
3074 		return(0);
3075 	}
3076 	if(bun_no2 >= buf->orig.bun_suu || bun_no2 < 0) bun_no2 = buf->orig.bun_suu;
3077 
3078 	for(k = bun_no; k < bun_no2; k++){
3079 		ret_area = wnn_area(buf->orig.bun[k], area, kanjip, arealen);
3080 		arealen -= ret_area - area;
3081 		area = ret_area;
3082 	}
3083 	x = area - area1;
3084 	return x;
3085 }
3086 
3087 int
wnn_get_area(buf,bun_no,bun_no2,area,kanjip,arealen)3088 wnn_get_area(buf, bun_no, bun_no2, area, kanjip, arealen)
3089 struct wnn_buf *buf;
3090 register int bun_no, bun_no2;
3091 w_char *area;
3092 int kanjip;
3093 int arealen;
3094 {
3095 	int x;
3096 
3097 	if(!buf) return(0);
3098 	x = wnn_get_area_body((WNN_BUF_MT *)buf, bun_no, bun_no2, area, kanjip, arealen);
3099 
3100 	return x;
3101 }
3102 
3103 #define JISHO 1
3104 #define HINDO 2
3105 #define FI_JISHO 3	/* (Jul. 7, 1994) */
3106 #define FI_HINDO 4	/* New type for FI-Wnn */
3107 
3108 /*********************************/
3109 static int
jl_dic_add_e_body(env,dic_name,hindo_name,rev,prio,rw,hrw,pwd_dic,pwd_hindo,error_handler,message_handler)3110 jl_dic_add_e_body(env,dic_name,hindo_name,rev, prio,rw, hrw, pwd_dic, pwd_hindo, error_handler, message_handler)
3111 register struct wnn_env_int *env;
3112 char *dic_name;
3113 char *hindo_name;
3114 int prio;
3115 int rw, hrw, rev;
3116 char *pwd_dic, *pwd_hindo;
3117 int  (*error_handler)(), (*message_handler)();
3118 {
3119 	char tmp[256];
3120 	char pwd[WNN_PASSWD_LEN], hpwd[WNN_PASSWD_LEN];
3121 	int fid, hfid = -1;
3122 	register int ret;
3123 
3124 	if(file_exist(env, dic_name) == -1) {
3125 		if (env_wnn_errorno_eql == WNN_JSERVER_DEAD) {
3126 			jl_disconnect_body(env);
3127 			return(-1);
3128 		}
3129 		if((int)error_handler == WNN_NO_CREATE ||
3130 			(rw == WNN_DIC_RDONLY)){
3131 
3132 			snprintf(tmp, sizeof(tmp), "%s \"%s\" %s",
3133 				msg_get(wnn_msg_cat, 200, NULL),
3134 				dic_name,
3135 				msg_get(wnn_msg_cat, 201, NULL));
3136 			/* "����ե����� \"%s\" ��̵���衣", */
3137 			message_out(message_handler, tmp);
3138 
3139 			env_wnn_errorno_set = WNN_NO_EXIST;
3140 			return(-1);
3141 		}
3142 
3143 		snprintf(tmp, sizeof(tmp), "%s \"%s\" %s%s",
3144 			msg_get(wnn_msg_cat, 200, NULL),
3145 			dic_name,
3146 			msg_get(wnn_msg_cat, 201, NULL),
3147 			msg_get(wnn_msg_cat, 202, NULL));
3148 		/* "����ե����� \"%s\" ��̵���衣���?(Y/N)", */
3149 
3150 		if((int)error_handler == WNN_CREATE ||
3151 			call_error_handler(error_handler, tmp, env)){
3152 			if(create_file(env, dic_name,JISHO, rw,
3153 				pwd_dic,
3154 				(hindo_name && *hindo_name)? "": pwd_hindo,
3155 				error_handler, message_handler) == -1) {
3156 				return(-1);
3157 			}
3158 		} else{
3159 			env_wnn_errorno_set = WNN_NO_EXIST;
3160 			return(-1);
3161 		}
3162 	}
3163 
3164 	if((fid = file_read(env, dic_name)) == -1) {
3165 		if_dead_disconnect(env);
3166 		return(-1);
3167 	}
3168 	if(hindo_name && *hindo_name){
3169 		if(file_exist(env, hindo_name) == -1) {
3170 			if(env_wnn_errorno_eql == WNN_JSERVER_DEAD)	{
3171 				jl_disconnect_body(env);
3172 				return(-1);
3173 			}
3174 			if((int)error_handler == WNN_NO_CREATE ||
3175 			    (hrw == WNN_DIC_RDONLY)){
3176 
3177 				snprintf(tmp, sizeof(tmp), "%s \"%s\" %s",
3178 				    msg_get(wnn_msg_cat, 203, NULL),
3179 				    hindo_name,
3180 				    msg_get(wnn_msg_cat, 201, NULL));
3181 				/*
3182 							"���٥ե����� \"%s\" ��̵���衣",
3183 							*/
3184 				message_out(message_handler, tmp);
3185 
3186 				env_wnn_errorno_set = WNN_NO_EXIST;
3187 				return(-1);
3188 			}
3189 
3190 			snprintf(tmp, sizeof(tmp), "%s \"%s\" %s%s",
3191 			    msg_get(wnn_msg_cat, 203, NULL),
3192 			    hindo_name,
3193 			    msg_get(wnn_msg_cat, 201, NULL),
3194 			    msg_get(wnn_msg_cat, 202, NULL));
3195 			/*
3196 					    "���٥ե����� \"%s\" ��̵���衣���?(Y/N)",
3197 					    */
3198 
3199 			if((int)error_handler == WNN_CREATE ||
3200 			    call_error_handler(error_handler, tmp, env)){
3201 				if(create_file(env, hindo_name, HINDO, fid,
3202 				    "", pwd_hindo, error_handler,
3203 				    message_handler) == -1) {
3204 					return(-1);
3205 				}
3206 			} else{
3207 				env_wnn_errorno_set = WNN_NO_EXIST;
3208 				return(-1);
3209 			}
3210 		}
3211 		if((hfid = file_read(env, hindo_name)) == -1){
3212 			if_dead_disconnect(env);
3213 			return(-1);
3214 		}
3215 	}
3216 
3217 	/* (Dec. 3, 1994)
3218 	       ���롼�׼���ξ��� read write���ޡ�������ξ��� read only ��
3219 	       dic_add ��Ԥ� */
3220 	if(rw == WNN_DIC_GROUP) rw = WNN_DIC_RW;
3221 	else if(rw == WNN_DIC_MERGE) rw = WNN_DIC_RDONLY;
3222 
3223 	if(get_pwd(pwd_dic, pwd, env) == -1)return(-1);
3224 	if(get_pwd(pwd_hindo, hpwd, env) == -1)return(-1);
3225 	if((ret = js_dic_add(env, fid, hfid, rev, prio, rw, hrw, pwd, hpwd)) < 0) {
3226 		if(env_wnn_errorno_eql == WNN_JSERVER_DEAD){
3227 			jl_disconnect_body(env);
3228 			return(-1);
3229 		} else if(env_wnn_errorno_eql == WNN_HINDO_NO_MATCH){
3230 			if((int)error_handler == WNN_NO_CREATE){
3231 				return(-1);
3232 			}
3233 
3234 			snprintf(tmp, sizeof(tmp),
3235 			    msg_get(wnn_msg_cat, 204, NULL),
3236 			    hindo_name);
3237 			/*
3238 					    "���٥ե����� \"%s\" �����ꤵ�줿��������٥ե�����ǤϤ���ޤ������ľ���ޤ���?(Y/N)",
3239 					    */
3240 
3241 			if(!((int)error_handler == WNN_CREATE ||
3242 			    call_error_handler(error_handler, tmp, env))){
3243 				return(-1);
3244 			}
3245 			if(file_discard(env, hfid) == -1) {
3246 				if_dead_disconnect(env);
3247 				return(-1);
3248 			}
3249 			if(file_remove(env->orig.js_id, hindo_name, hpwd) == -1) {
3250 				if_dead_disconnect(env);
3251 				return(-1);
3252 			}
3253 			if(create_file(env,hindo_name, HINDO, fid, NULL, pwd_hindo, WNN_CREATE, message_handler) == -1) {
3254 				return(-1);
3255 			}
3256 			if((hfid = file_read(env, hindo_name)) == -1) {
3257 				if_dead_disconnect(env);
3258 				return(-1);
3259 			}
3260 			if((ret = js_dic_add(env, fid, hfid, rev, prio, rw, hrw, pwd, hpwd))< 0) {
3261 				if_dead_disconnect(env);
3262 				return(-1);
3263 			}
3264 		}
3265 	}
3266 	return(ret);
3267 }
3268 
3269 int
jl_dic_add_e(env,dic_name,hindo_name,rev,prio,rw,hrw,pwd_dic,pwd_hindo,error_handler,message_handler)3270 jl_dic_add_e(env,dic_name,hindo_name,rev, prio,rw, hrw, pwd_dic, pwd_hindo, error_handler, message_handler)
3271 register struct wnn_env *env;
3272 char *dic_name;
3273 char *hindo_name;
3274 int prio;
3275 int rw, hrw, rev;
3276 char *pwd_dic, *pwd_hindo;
3277 int  (*error_handler)(), (*message_handler)();
3278 {
3279 	int x;
3280 
3281 	if(!env) return(-1);
3282 
3283 	env_wnn_errorno_set = 0;
3284 	x = jl_dic_add_e_body((WNN_ENV_INT *)env, dic_name, hindo_name, rev, prio,
3285 	    rw, hrw, pwd_dic, pwd_hindo, error_handler,
3286 	    message_handler);
3287 
3288 	return x;
3289 }
3290 
3291 int
jl_dic_add(buf,dic_name,hindo_name,rev,prio,rw,hrw,pwd_dic,pwd_hindo,error_handler,message_handler)3292 jl_dic_add(buf, dic_name, hindo_name, rev, prio, rw, hrw, pwd_dic, pwd_hindo, error_handler, message_handler)
3293 register struct wnn_buf *buf;
3294 char *dic_name;
3295 char *hindo_name;
3296 int prio;
3297 int rw, hrw, rev;
3298 char *pwd_dic, *pwd_hindo;
3299 int  (*error_handler)(), (*message_handler)();
3300 {
3301 	int x;
3302 
3303 	if(!buf || !(buf->env)) return(-1);
3304 
3305 
3306 	buf_wnn_errorno_set = 0;
3307 	x = jl_dic_add_e_body((WNN_ENV_INT *)buf->env, dic_name, hindo_name, rev,
3308 	    prio, rw, hrw, pwd_dic, pwd_hindo, error_handler,
3309 	    message_handler);
3310 
3311 	return x;
3312 }
3313 
3314 /*:::DOC_START
3315  *
3316  *    Function Name: jl_fi_dic_add_e_body
3317  *    Description  : jl_fi_dic_add[_e] �Υ��֥롼����ؿ�
3318  *    Parameter    :
3319  *         env :             (In) �Ķ��ؤΥݥ���
3320  *         dic_name :        (In) �ƣɴط�����ե�����̾
3321  *         hindo_name :      (In) �ƣɴط����٥ե�����̾
3322  *	   suflag :          (In) �����ƥ༭����桼������
3323  *	   rw :              (In) ����������ǽ����Բ�ǽ
3324  *	   hrw :             (In) ���ٹ�������ǽ����Բ�ǽ
3325  *	   pwd_dic :         (In) �ƣɴط�����ե�����Υѥ����
3326  *	   pwd_hindo :       (In) �ƣɴط����٥ե�����Υѥ����
3327  *	   error_handler :   (In) ���顼�ϥ�ɥ��
3328  *	   message_handler : (In) ��å������ϥ�ɥ顼
3329  *
3330  *    Return value : -1==ERROR, else ��Ͽ�����ֹ�
3331  *
3332  *    Revision history:
3333  *
3334  *:::DOC_END
3335  */
3336 static int
jl_fi_dic_add_e_body(env,dic_name,hindo_name,suflag,rw,hrw,pwd_dic,pwd_hindo,error_handler,message_handler)3337 jl_fi_dic_add_e_body(env, dic_name, hindo_name, suflag, rw, hrw, pwd_dic, pwd_hindo, error_handler, message_handler)
3338 register struct wnn_env_int *env;
3339 char *dic_name;
3340 char *hindo_name;
3341 int suflag;
3342 int rw, hrw;
3343 char *pwd_dic, *pwd_hindo;
3344 int  (*error_handler)(), (*message_handler)();
3345 {
3346 	char tmp[256];
3347 	char pwd[WNN_PASSWD_LEN], hpwd[WNN_PASSWD_LEN];
3348 	int fid, hfid = -1;
3349 	register int ret;
3350 
3351 	if(file_exist(env, dic_name) == -1) {
3352 		/* �ƣɴط�����ե����뤬¸�ߤ��ʤ� */
3353 		if (env_wnn_errorno_eql == WNN_JSERVER_DEAD) {
3354 			/* jserver �����Ǥ��� */
3355 			jl_disconnect_body(env);
3356 			return(-1);
3357 		}
3358 		if((int)error_handler == WNN_NO_CREATE) {
3359 
3360 			snprintf(tmp, sizeof(tmp), "%s \"%s\" %s",
3361 			    msg_get(wnn_msg_cat, 200, NULL),
3362 			    dic_name,
3363 			    msg_get(wnn_msg_cat, 201, NULL));
3364 			/*
3365 					    "����ե����� \"%s\" ��̵���衣",
3366 					    */
3367 			message_out(message_handler, tmp);
3368 
3369 			env_wnn_errorno_set = WNN_NO_EXIST;
3370 			return(-1);
3371 		}
3372 
3373 		snprintf(tmp, sizeof(tmp), "%s \"%s\" %s%s",
3374 		    msg_get(wnn_msg_cat, 200, NULL),
3375 		    dic_name,
3376 		    msg_get(wnn_msg_cat, 201, NULL),
3377 		    msg_get(wnn_msg_cat, 202, NULL));
3378 		/*
3379 				"����ե����� \"%s\" ��̵���衣���?(Y/N)",
3380 				*/
3381 
3382 		if((int)error_handler == WNN_CREATE ||
3383 		    call_error_handler(error_handler, tmp, env)){
3384 			/* �ƣɴط�����κ��� */
3385 			if(create_file(env, dic_name, FI_JISHO, -1, /* -1 is dummy */
3386 			pwd_dic,
3387 			    (hindo_name && *hindo_name)? "": pwd_hindo,
3388 			    error_handler, message_handler) == -1) {
3389 				return(-1);
3390 			}
3391 		} else{
3392 			env_wnn_errorno_set = WNN_NO_EXIST;
3393 			return(-1);
3394 		}
3395 	}
3396 	/* �ƣɴط�������ɤ߹��� */
3397 	if((fid = file_read(env, dic_name)) == -1) {
3398 		if_dead_disconnect(env);
3399 		return(-1);
3400 	}
3401 	if(hindo_name && *hindo_name){
3402 		if(file_exist(env, hindo_name) == -1) {
3403 			/* �ƣɴط����٥ե����뤬¸�ߤ��ʤ� */
3404 			if(env_wnn_errorno_eql == WNN_JSERVER_DEAD)	{
3405 				/* jserver �����Ǥ��� */
3406 				jl_disconnect_body(env);
3407 				return(-1);
3408 			}
3409 			if((int)error_handler == WNN_NO_CREATE ||
3410 			    (hrw == WNN_DIC_RDONLY)){
3411 
3412 				snprintf(tmp, sizeof(tmp), "%s \"%s\" %s",
3413 				    msg_get(wnn_msg_cat, 203, NULL),
3414 				    hindo_name,
3415 				    msg_get(wnn_msg_cat, 201, NULL));
3416 				/*
3417 							"���٥ե����� \"%s\" ��̵���衣",
3418 							*/
3419 				message_out(message_handler, tmp);
3420 
3421 				env_wnn_errorno_set = WNN_NO_EXIST;
3422 				return(-1);
3423 			}
3424 
3425 			snprintf(tmp, sizeof(tmp), "%s \"%s\" %s%s",
3426 			    msg_get(wnn_msg_cat, 203, NULL),
3427 			    hindo_name,
3428 			    msg_get(wnn_msg_cat, 201, NULL),
3429 			    msg_get(wnn_msg_cat, 202, NULL));
3430 			/*
3431 					    "���٥ե����� \"%s\" ��̵���衣���?(Y/N)",
3432 					    */
3433 
3434 			if((int)error_handler == WNN_CREATE ||
3435 			    call_error_handler(error_handler, tmp, env)){
3436 				/* �ƣɴط����٥ե�����κ��� */
3437 				if(create_file(env, hindo_name, FI_HINDO, fid,
3438 				    "", pwd_hindo, error_handler,
3439 				    message_handler) == -1) {
3440 					return(-1);
3441 				}
3442 			} else{
3443 				env_wnn_errorno_set = WNN_NO_EXIST;
3444 				return(-1);
3445 			}
3446 		}
3447 		/* �ƣɴط����٥ե�������ɤ߹��� */
3448 		if((hfid = file_read(env, hindo_name)) == -1){
3449 			if_dead_disconnect(env);
3450 			return(-1);
3451 		}
3452 	}
3453 
3454 	/* �ѥ���ɤμ��� */
3455 	if(get_pwd(pwd_dic, pwd, env) == -1)return(-1);
3456 	if(get_pwd(pwd_hindo, hpwd, env) == -1)return(-1);
3457 
3458 	/* �ƣɴط���������٤������������å� */
3459 	if((ret = js_fi_dic_add(env, fid, hfid, suflag, rw, hrw, pwd, hpwd)) < 0) {
3460 		if(env_wnn_errorno_eql == WNN_JSERVER_DEAD){
3461 			/* jserver �����Ǥ��� */
3462 			jl_disconnect_body(env);
3463 			return(-1);
3464 		} else if(env_wnn_errorno_eql == WNN_HINDO_NO_MATCH){
3465 			/* ��������٤���������̵�� */
3466 			if((int)error_handler == WNN_NO_CREATE){
3467 				return(-1);
3468 			}
3469 
3470 			snprintf(tmp, sizeof(tmp),
3471 			    msg_get(wnn_msg_cat, 204, NULL),
3472 			    hindo_name);
3473 			/*
3474 					    "���٥ե����� \"%s\" �����ꤵ�줿��������٥ե�����ǤϤ���ޤ������ľ���ޤ���?(Y/N)",
3475 					    */
3476 
3477 			if(!((int)error_handler == WNN_CREATE ||
3478 			    call_error_handler(error_handler, tmp, env))){
3479 				return(-1);
3480 			}
3481 			/* ���٥ե�����Υ������ */
3482 			if(file_discard(env, hfid) == -1) {
3483 				if_dead_disconnect(env);
3484 				return(-1);
3485 			}
3486 			/* ���٥ե�����Υǥ���������κ�� */
3487 			if(file_remove(env->orig.js_id, hindo_name, hpwd) == -1) {
3488 				if_dead_disconnect(env);
3489 				return(-1);
3490 			}
3491 			/* �ƣɴط����٥ե�����κ��� */
3492 			if(create_file(env,hindo_name, FI_HINDO, fid, NULL, pwd_hindo, WNN_CREATE, message_handler) == -1) {
3493 				return(-1);
3494 			}
3495 			/* �ƣɴط����٥ե�������ɤ߹��� */
3496 			if((hfid = file_read(env, hindo_name)) == -1) {
3497 				if_dead_disconnect(env);
3498 				return(-1);
3499 			}
3500 			/* �ƣɴط���������٤������������å� */
3501 			if((ret = js_fi_dic_add(env, fid, hfid, suflag, rw, hrw, pwd, hpwd))< 0) {
3502 				if_dead_disconnect(env);
3503 				return(-1);
3504 			}
3505 		}
3506 	}
3507 	return(ret);
3508 } /* End of jl_fi_dic_add_e_body */
3509 
3510 /*:::DOC_START
3511  *
3512  *    Function Name: jl_fi_dic_add_e
3513  *    Description  : �Ķ��ˣƣɼ�����ɲä���
3514  *    Parameter    :
3515  *         env :             (In) �Ķ��ؤΥݥ���
3516  *         dic_name :        (In) �ƣɴط�����ե�����̾
3517  *         hindo_name :      (In) �ƣɴط����٥ե�����̾
3518  *	   suflag :          (In) �����ƥ༭����桼������
3519  *	   rw :              (In) ����������ǽ����Բ�ǽ
3520  *	   hrw :             (In) ���ٹ�������ǽ����Բ�ǽ
3521  *	   pwd_dic :         (In) �ƣɴط�����ե�����Υѥ����
3522  *	   pwd_hindo :       (In) �ƣɴط����٥ե�����Υѥ����
3523  *	   error_handler :   (In) ���顼�ϥ�ɥ��
3524  *	   message_handler : (In) ��å������ϥ�ɥ顼
3525  *
3526  *    Return value : -1==ERROR, else ��Ͽ�����ֹ�
3527  *
3528  *    Revision history:
3529  *
3530  *:::DOC_END
3531  */
3532 int
jl_fi_dic_add_e(env,dic_name,hindo_name,suflag,rw,hrw,pwd_dic,pwd_hindo,error_handler,message_handler)3533 jl_fi_dic_add_e(env, dic_name, hindo_name, suflag ,rw, hrw, pwd_dic, pwd_hindo, error_handler, message_handler)
3534 register struct wnn_env *env;
3535 char *dic_name;
3536 char *hindo_name;
3537 int suflag;
3538 int rw, hrw;
3539 char *pwd_dic, *pwd_hindo;
3540 int  (*error_handler)(), (*message_handler)();
3541 {
3542 	int x;
3543 
3544 	if(!env) return(-1);
3545 
3546 	env_wnn_errorno_set = 0;
3547 	/* ���֥롼����ؿ��Υ����� */
3548 	x = jl_fi_dic_add_e_body((WNN_ENV_INT *)env, dic_name, hindo_name, suflag,
3549 	    rw, hrw, pwd_dic, pwd_hindo, error_handler,
3550 	    message_handler);
3551 
3552 	return x;
3553 } /* End of jl_fi_dic_add_e */
3554 
3555 /*:::DOC_START
3556  *
3557  *    Function Name: jl_fi_dic_add
3558  *    Description  : �Хåե��ˣƣɼ�����ɲä���
3559  *    Parameter    :
3560  *         buf :             (In) �Хåե��ؤΥݥ���
3561  *         dic_name :        (In) �ƣɴط�����ե�����̾
3562  *         hindo_name :      (In) �ƣɴط����٥ե�����̾
3563  *	   suflag :          (In) �����ƥ༭����桼������
3564  *	   rw :              (In) ����������ǽ����Բ�ǽ
3565  *	   hrw :             (In) ���ٹ�������ǽ����Բ�ǽ
3566  *	   pwd_dic :         (In) �ƣɴط�����ե�����Υѥ����
3567  *	   pwd_hindo :       (In) �ƣɴط����٥ե�����Υѥ����
3568  *	   error_handler :   (In) ���顼�ϥ�ɥ��
3569  *	   message_handler : (In) ��å������ϥ�ɥ顼
3570  *
3571  *    Return value : -1==ERROR, else ��Ͽ�����ֹ�
3572  *
3573  *    Revision history:
3574  *
3575  *:::DOC_END
3576  */
3577 int
jl_fi_dic_add(buf,dic_name,hindo_name,suflag,rw,hrw,pwd_dic,pwd_hindo,error_handler,message_handler)3578 jl_fi_dic_add(buf, dic_name, hindo_name, suflag, rw, hrw, pwd_dic, pwd_hindo, error_handler, message_handler)
3579 register struct wnn_buf *buf;
3580 char *dic_name;
3581 char *hindo_name;
3582 int suflag;
3583 int rw, hrw;
3584 char *pwd_dic, *pwd_hindo;
3585 int  (*error_handler)(), (*message_handler)();
3586 {
3587 	int x;
3588 
3589 	if(!buf || !(buf->env)) return(-1);
3590 
3591 
3592 	buf_wnn_errorno_set = 0;
3593 	/* ���֥롼����ؿ��Υ����� */
3594 	x = jl_fi_dic_add_e_body((WNN_ENV_INT *)buf->env, dic_name, hindo_name,
3595 	    suflag, rw, hrw, pwd_dic, pwd_hindo, error_handler,
3596 	    message_handler);
3597 
3598 	return x;
3599 } /* End of jl_fi_dic_add */
3600 
3601 static int
jl_dic_delete_e_body(env,dic_no)3602 jl_dic_delete_e_body(env, dic_no)
3603 register struct wnn_env_int *env;
3604 register int dic_no;
3605 {
3606 	WNN_DIC_INFO dic;
3607 
3608 	if(js_dic_info(env,dic_no,&dic) < 0){
3609 		if_dead_disconnect(env);
3610 		return(-1);
3611 	}
3612 	if(js_dic_delete(env, dic_no) < 0) {
3613 		if_dead_disconnect(env);
3614 		return(-1);
3615 	}
3616 	/*	dic Body	*/
3617 	if (file_discard(env,dic.body) < 0) {
3618 		if_dead_disconnect(env);
3619 		return(-1);
3620 	}
3621 	/*	dic hindo	*/
3622 	if(dic.hindo != -1){
3623 		if (file_discard(env,dic.hindo) < 0){
3624 			if_dead_disconnect(env);
3625 			return(-1);
3626 		}
3627 	}
3628 	return(0);
3629 }
3630 
3631 int
jl_dic_delete_e(env,dic_no)3632 jl_dic_delete_e(env, dic_no)
3633 register struct wnn_env *env;
3634 register int dic_no;
3635 {
3636 	int x;
3637 
3638 	if(!env) return(-1);
3639 
3640 	env_wnn_errorno_set = 0;
3641 	x = jl_dic_delete_e_body((WNN_ENV_INT *)env, dic_no);
3642 
3643 	return x;
3644 }
3645 
3646 int
jl_dic_delete(buf,dic_no)3647 jl_dic_delete(buf, dic_no)
3648 register struct wnn_buf *buf;
3649 register int dic_no;
3650 {
3651 	int x;
3652 
3653 	if(!buf || !(buf->env)) return(-1);
3654 
3655 
3656 	buf_wnn_errorno_set = 0;
3657 	x = jl_dic_delete_e_body((WNN_ENV_INT *)buf->env, dic_no);
3658 
3659 	return x;
3660 }
3661 
3662 static int
get_pwd(pwd_dic,pwd,env)3663 get_pwd(pwd_dic, pwd, env)
3664 register char *pwd_dic, *pwd;
3665 ARGS *env;
3666 {
3667 	FILE *fp;
3668 
3669 	if(pwd_dic && *pwd_dic){
3670 		if((fp = fopen(pwd_dic, "r")) == NULL){
3671 			env_wnn_errorno_set = WNN_CANT_OPEN_PASSWD_FILE;
3672 			return(-1);
3673 		}
3674 		fgets(pwd, WNN_PASSWD_LEN, fp);
3675 		fclose(fp);
3676 	} else {
3677 		pwd[0] = 0;
3678 	}
3679 	return(0);
3680 }
3681 
3682 static int
create_pwd_file(env,pwd_file,error_handler,message_handler)3683 create_pwd_file(env, pwd_file, error_handler, message_handler)
3684 register struct wnn_env_int *env;
3685 char *pwd_file;
3686 int  (*error_handler)(), (*message_handler)();
3687 {
3688 	int fid;
3689 	char buf[256];
3690 
3691 	if(pwd_file == NULL || *pwd_file == 0) return(0);
3692 	if(access(pwd_file, F_OK) != -1) return(0);
3693 
3694 	snprintf(buf, sizeof(buf), "%s \"%s\" %s%s",
3695 	    msg_get(wnn_msg_cat, 205, NULL),
3696 	    pwd_file,
3697 	    msg_get(wnn_msg_cat, 201, NULL),
3698 	    msg_get(wnn_msg_cat, 202, NULL));
3699 	/*
3700 		    "password_file \"%s\" ��̵���衣���?(Y/N)",
3701 		    */
3702 
3703 	/* error_handler != WNN_CREATE �Υ����å���ȴ���Ƥ����Τ��ɲ� */
3704 	if((int)error_handler != WNN_CREATE && call_error_handler(error_handler,buf, env) == 0){
3705 		env_wnn_errorno_set = WNN_NO_EXIST;
3706 		return(-1);
3707 	}
3708 #define	MODE_PWD (0000000 | 0000400)
3709 	fid = open(pwd_file, O_WRONLY | O_CREAT | O_TRUNC, MODE_PWD);
3710 	if (fid == -1) {
3711 		env_wnn_errorno_set = WNN_CANT_OPEN_PASSWD_FILE;
3712 		message_out(message_handler, wnn_perror());
3713 		return(-1);
3714 	}
3715 #ifdef SYSVR2
3716 	srand(time(0)+getuid());
3717 	snprintf(buf, sizeof(buf), "%d\n",rand());
3718 #else
3719 	srandom(time(0)+getuid());
3720 	snprintf(buf, sizeof(buf), "%d\n",random());
3721 #endif
3722 	write(fid, buf, strlen(buf));
3723 	close(fid);
3724 	return(0);
3725 }
3726 
3727 
3728 /**	jl_fuzokugo_set	**/
3729 static int
jl_fuzokugo_set_e_body(env,fname)3730 jl_fuzokugo_set_e_body(env,fname)
3731 struct wnn_env_int *env;
3732 char *fname;
3733 {
3734 	register int fid, orgfid;
3735 	int	ret;
3736 
3737 	orgfid = js_fuzokugo_get(env);
3738 	/* If orgfid == -1, it must be
3739 	       because no fuzokugo_file is set to the env
3740 	       */
3741 	if((fid=file_read(env,fname)) == -1) {
3742 		if_dead_disconnect(env);
3743 		return(-1);
3744 	}
3745 	if ((ret = js_fuzokugo_set(env,fid)) < 0) {
3746 		if_dead_disconnect(env);
3747 		return(ret);
3748 	}
3749 	if(fid != orgfid && orgfid != -1){
3750 		js_file_discard(env, orgfid);
3751 	}
3752 	return(ret);
3753 }
3754 
3755 int
jl_fuzokugo_set_e(env,fname)3756 jl_fuzokugo_set_e(env,fname)
3757 struct wnn_env *env;
3758 char *fname;
3759 {
3760 	int x;
3761 	if(!env) return(-1);
3762 
3763 	env_wnn_errorno_set = 0;
3764 	x = jl_fuzokugo_set_e_body((WNN_ENV_INT *)env,fname);
3765 
3766 	return x;
3767 }
3768 
3769 int
jl_fuzokugo_set(buf,fname)3770 jl_fuzokugo_set(buf, fname)
3771 register struct wnn_buf *buf;
3772 char *fname;
3773 {
3774 	int x;
3775 	if(!buf || !(buf->env)) return(-1);
3776 
3777 
3778 	buf_wnn_errorno_set = 0;
3779 	x = jl_fuzokugo_set_e_body((WNN_ENV_INT *)buf->env, fname);
3780 
3781 	return x;
3782 }
3783 
3784 /**	jl_fuzokugo_get	**/
3785 static int
jl_fuzokugo_get_e_body(env,fname,fnamelen)3786 jl_fuzokugo_get_e_body(env, fname, fnamelen)
3787 register struct wnn_env_int *env;
3788 char *fname;
3789 int fnamelen;
3790 {
3791 	WNN_FILE_INFO_STRUCT file;
3792 	int fid;
3793 	char *c;
3794 
3795 	if (!fname || fnamelen <= 0)
3796 		return(-1);
3797 	fname[0] = 0;
3798 	if((fid = js_fuzokugo_get(env)) < 0) {
3799 		if_dead_disconnect(env);
3800 		return(-1);
3801 	}
3802 	if (js_file_info(env,fid,&file) < 0) {
3803 		if_dead_disconnect(env);
3804 		return(-1);
3805 	}
3806 
3807 	c = find_file_name_from_id(env, fid);
3808 	if(c == NULL){
3809 		c = file.name;
3810 	}
3811 	strncpy(fname, c, fnamelen - 1);
3812 	*(fname + fnamelen - 1) = 0;
3813 
3814 	return(fid);
3815 }
3816 
3817 int
jl_fuzokugo_get_e(env,fname,fnamelen)3818 jl_fuzokugo_get_e(env, fname, fnamelen)
3819 register struct wnn_env *env;
3820 char *fname;
3821 int fnamelen;
3822 {
3823 	int x;
3824 
3825 	if(!env) return(-1);
3826 
3827 	env_wnn_errorno_set = 0;
3828 	x = jl_fuzokugo_get_e_body((WNN_ENV_INT *)env, fname, fnamelen);
3829 
3830 	return x;
3831 }
3832 
3833 int
jl_fuzokugo_get(buf,fname,fnamelen)3834 jl_fuzokugo_get(buf, fname, fnamelen)
3835 register struct wnn_buf *buf;
3836 char *fname;
3837 int fnamelen;
3838 {
3839 	int x;
3840 
3841 	if(!buf || !(buf->env)) return(-1);
3842 
3843 
3844 	buf_wnn_errorno_set = 0;
3845 	x = jl_fuzokugo_get_e_body((WNN_ENV_INT *)buf->env, fname, fnamelen);
3846 
3847 	return x;
3848 }
3849 
3850 /**	jl_dic_save	**/
3851 static int
jl_dic_save_e_body(env,dic_no)3852 jl_dic_save_e_body(env,dic_no)
3853 register struct wnn_env_int *env;
3854 int	dic_no;
3855 {
3856 	WNN_DIC_INFO dic;
3857 	WNN_FILE_INFO_STRUCT file;
3858 	char *c;
3859 
3860 	if(js_dic_info(env,dic_no,&dic) < 0) {
3861 		if_dead_disconnect(env);
3862 		return(-1);
3863 	}
3864 	/*	dic Body	*/
3865 
3866 	c = find_file_name_from_id(env, dic.body);
3867 	if(c == NULL){
3868 		if(dic.localf){
3869 			c = dic.fname;
3870 		} else{
3871 
3872 			env_wnn_errorno_set=WNN_FILE_NOT_READ_FROM_CLIENT;
3873 			return(-1);
3874 		}
3875 	}
3876 	if(c[0] != C_LOCAL){
3877 		if (js_file_write(env,dic.body,c) < 0) {
3878 			if (env_wnn_errorno_eql == WNN_JSERVER_DEAD) {
3879 
3880 				jl_disconnect_if_server_dead_body(env);
3881 				return(-1);
3882 			}
3883 		}
3884 	} else{
3885 		if (js_file_receive(env,dic.body,c + 1) < 0) {
3886 			if (env_wnn_errorno_eql == WNN_JSERVER_DEAD) {
3887 
3888 				jl_disconnect_if_server_dead_body(env);
3889 				return(-1);
3890 			}
3891 		}
3892 	}
3893 	/*	dic hindo	*/
3894 	if(dic.hindo != -1){
3895 		if (js_file_info(env,dic.hindo,&file) < 0) {
3896 
3897 			if_dead_disconnect(env);
3898 			return(-1);
3899 		}
3900 		c = find_file_name_from_id(env, file.fid);
3901 		if(c == NULL){
3902 			if(dic.hlocalf){
3903 				c = dic.hfname;
3904 			} else{
3905 
3906 				env_wnn_errorno_set=WNN_FILE_NOT_READ_FROM_CLIENT;
3907 				return(-1);
3908 			}
3909 		}
3910 		if(c[0] != C_LOCAL){
3911 			if (js_file_write(env,dic.hindo,c) < 0) {
3912 
3913 				if_dead_disconnect(env);
3914 				return(-1);
3915 			}
3916 		} else{
3917 			if (js_file_receive(env,dic.hindo,c + 1) < 0) {
3918 
3919 				if_dead_disconnect(env);
3920 				return(-1);
3921 			}
3922 		}
3923 	}
3924 
3925 	return(0);
3926 }
3927 
3928 int
jl_dic_save_e(env,dic_no)3929 jl_dic_save_e(env,dic_no)
3930 register struct wnn_env *env;
3931 int     dic_no;
3932 {
3933 	int x;
3934 
3935 	if(!env) return(-1);
3936 
3937 	env_wnn_errorno_set = 0;
3938 	x = jl_dic_save_e_body((WNN_ENV_INT *)env,dic_no);
3939 
3940 	return x;
3941 }
3942 
3943 int
jl_dic_save(buf,dic_no)3944 jl_dic_save(buf, dic_no)
3945 register struct wnn_buf *buf;
3946 int     dic_no;
3947 {
3948 	int x;
3949 
3950 	if(!buf || !(buf->env)) return(-1);
3951 
3952 
3953 	buf_wnn_errorno_set = 0;
3954 	x = jl_dic_save_e_body((WNN_ENV_INT *)buf->env, dic_no);
3955 
3956 	return x;
3957 }
3958 
3959 static int
jl_dic_save_all_e_body(env)3960 jl_dic_save_all_e_body(env)
3961 struct wnn_env_int *env;
3962 {
3963 	register WNN_DIC_INFO *dic;
3964 	register int k;
3965 	char *c;
3966 	register int cnt;
3967 	register unsigned long dmask = 0;
3968 
3969 	/* �ƥ�ݥ�꼭��ʳ��μ����������� */
3970 	dmask |= WNN_DIC_ALL_MASK & ~WNN_DIC_TEMPORARY_MASK;
3971 
3972 	if((cnt = js_fi_dic_list(env, dmask, &dicrb)) == -1) {
3973 		if_dead_disconnect(env);
3974 		return(-1);
3975 	}
3976 	dic = (WNN_DIC_INFO *)dicrb.buf;
3977 
3978 	for(k = 0 ; k < cnt ; k++, dic++){
3979 		if((c = find_file_name_from_id(env, dic->body)) == NULL){
3980 			if(dic->localf){
3981 				c = dic->fname;
3982 			} else{
3983 				env_wnn_errorno_set=WNN_FILE_NOT_READ_FROM_CLIENT;
3984 			}
3985 		}
3986 		if(c){
3987 			if(c[0] != C_LOCAL){
3988 				if (js_file_write(env,dic->body,c) < 0) {
3989 					if (env_wnn_errorno_eql == WNN_JSERVER_DEAD) {
3990 
3991 						jl_disconnect_if_server_dead_body(env);
3992 						return(-1);
3993 					}
3994 				}
3995 			} else{
3996 				if (js_file_receive(env,dic->body,c + 1) < 0) {
3997 					if (env_wnn_errorno_eql == WNN_JSERVER_DEAD) {
3998 
3999 						jl_disconnect_if_server_dead_body(env);
4000 						return(-1);
4001 					}
4002 				}
4003 			}
4004 		}
4005 		/*	dic hindo	*/
4006 		if(dic->hindo != -1){
4007 			c = find_file_name_from_id(env, dic->hindo);
4008 			if(c == NULL){
4009 				if(dic->hlocalf){
4010 					c = dic->hfname;
4011 				} else{
4012 					env_wnn_errorno_set=WNN_FILE_NOT_READ_FROM_CLIENT;
4013 				}
4014 			}
4015 			if(c){
4016 				if(c[0] != C_LOCAL){
4017 					if (js_file_write(env,dic->hindo,c) < 0) {
4018 						if (env_wnn_errorno_eql == WNN_JSERVER_DEAD) {
4019 
4020 							if_dead_disconnect(env);
4021 							return(-1);
4022 						}
4023 					}
4024 				} else{
4025 					if (js_file_receive(env,dic->hindo,c + 1) < 0) {
4026 						if (env_wnn_errorno_eql == WNN_JSERVER_DEAD) {
4027 
4028 							if_dead_disconnect(env);
4029 							return(-1);
4030 						}
4031 					}
4032 				}
4033 			}
4034 		}
4035 	}
4036 
4037 	if(env_wnn_errorno_eql)
4038 		return(-1);
4039 		else
4040 		return(0);
4041 }
4042 
4043 int
jl_dic_save_all_e(env)4044 jl_dic_save_all_e(env)
4045 struct wnn_env *env;
4046 {
4047 	int x;
4048 
4049 	if(!env) return(-1);
4050 
4051 	env_wnn_errorno_set = 0;
4052 	x = jl_dic_save_all_e_body((WNN_ENV_INT *)env);
4053 
4054 	return x;
4055 }
4056 
4057 int
jl_dic_save_all(buf)4058 jl_dic_save_all(buf)
4059 register struct wnn_buf *buf;
4060 {
4061 	int x;
4062 
4063 	if(!buf || !(buf->env)) return(-1);
4064 
4065 
4066 	buf_wnn_errorno_set = 0;
4067 	x = jl_dic_save_all_e_body((WNN_ENV_INT *)buf->env);
4068 
4069 	return x;
4070 }
4071 
4072 /*
4073  *
4074  * bun manipulate  routines
4075  *
4076  */
4077 
4078 static void
free_sho(buf,wbp)4079 free_sho(buf, wbp)
4080 register struct wnn_buf_mt *buf;
4081 WNN_BUN **wbp;
4082 {
4083 	register WNN_BUN *wb, *wb1;
4084 	wb = *wbp;
4085 
4086 	if(--wb->ref_cnt <= 0){
4087 		for(wb1 = wb; wb;){
4088 			if((wb1 == wb) && (wb->hinsi_list != NULL)) {
4089 				free((char *)(wb->hinsi_list));
4090 				wb->hinsi_list = NULL;
4091 			}
4092 			wb->free_next = buf->orig.free_heap;
4093 			buf->orig.free_heap = wb;
4094 			wb = wb->next;
4095 		}
4096 	}
4097 	*wbp = NULL;
4098 }
4099 
4100 static void
free_zenkouho(buf)4101 free_zenkouho(buf)
4102 register struct wnn_buf_mt *buf;
4103 {
4104 	register int k;
4105 
4106 	for(k = 0 ; k < buf->orig.zenkouho_suu; k++){
4107 		free_sho(buf, &buf->orig.zenkouho[k]);
4108 	}
4109 	buf->orig.zenkouho_suu = 0;
4110 	buf->orig.zenkouho_dai_suu = 0;
4111 	buf->orig.c_zenkouho = -1;
4112 	buf->orig.zenkouho_bun = -1;
4113 	buf->orig.zenkouho_end_bun = -1;
4114 }
4115 
4116 static void
free_bun(buf,bun_no,bun_no2)4117 free_bun(buf, bun_no, bun_no2)
4118 struct wnn_buf_mt *buf;
4119 register int bun_no, bun_no2;
4120 {
4121 	register int k;
4122 
4123 	for(k = bun_no; k < bun_no2; k++){
4124 		free_sho(buf, &buf->orig.bun[k]);
4125 	}
4126 }
4127 
4128 static void
free_down(buf,bun_no,bun_no2)4129 free_down(buf, bun_no, bun_no2)
4130 struct wnn_buf_mt *buf;
4131 int bun_no, bun_no2;
4132 {
4133 	register WNN_BUN **wbp, **wbp1;
4134 	int k;
4135 
4136 	for(k = bun_no; k < bun_no2; k++){
4137 		for(wbp = &buf->orig.down_bnst[k]; *wbp; wbp = wbp1){
4138 			wbp1 = &(*wbp)->down;
4139 			free_sho(buf, wbp);
4140 		}
4141 	}
4142 }
4143 
4144 static
4145 WNN_BUN *
get_new_bun(buf)4146 get_new_bun(buf)
4147 register struct wnn_buf_mt *buf;
4148 {
4149 	register WNN_BUN *wb;
4150 
4151 
4152 	if(buf->orig.free_heap == NULL){
4153 		if(alloc_heap(buf, INCREMENT) == -1)return(NULL);
4154 	}
4155 	wb = buf->orig.free_heap;
4156 	buf->orig.free_heap = wb->free_next;
4157 	wb->free_next = NULL;
4158 	wb->daihyoka = -1;
4159 	return(wb);
4160 }
4161 
4162 static
4163 WNN_BUN *
get_sho(buf,sb,zenp,daip,fuku,nhinsi,hlist)4164 get_sho(buf, sb, zenp, daip, fuku, nhinsi, hlist)
4165 struct wnn_buf_mt *buf;
4166 struct wnn_sho_bunsetsu *sb;
4167 int zenp, daip, fuku, nhinsi, *hlist;
4168 {
4169 	register w_char *c, *end, *s;
4170 	register WNN_BUN *wb;
4171 	WNN_BUN *wb1;
4172 	int where = 1;
4173 	int len;
4174 
4175 	if((wb = get_new_bun(buf)) == NULL) return(NULL);
4176 
4177 	wb->jirilen = sb->jiriend - sb->start + 1;
4178 	wb->dic_no = sb->dic_no;
4179 	wb->entry = sb->entry;
4180 	wb->kangovect = sb->kangovect;
4181 	wb->hinsi = sb->hinsi;
4182 	wb->hindo = sb->hindo;
4183 	wb->ima = sb->ima;
4184 	wb->hindo_updated = 0;
4185 	wb->bug = 0;
4186 	wb->dai_top = 0;
4187 	wb->nobi_top = 0;
4188 	wb->ref_cnt = 1;
4189 	wb->hyoka = sb->hyoka;
4190 	wb->down = NULL;
4191 	wb->from_zenkouho = daip << 1 | zenp;
4192 	len = wnn_Strlen(sb->fuzoku);
4193 	wb->yomilen = wnn_Strlen(sb->yomi) + len;
4194 	wb->real_kanjilen = wnn_Strlen(sb->kanji);
4195 	wb->kanjilen = wb->real_kanjilen + len;
4196 	wb->fukugou = fuku;
4197 	wb->num_hinsi = nhinsi;
4198 	if(nhinsi) {
4199 		int hsize = abs(nhinsi) * sizeof(int);
4200 		if((wb->hinsi_list = (int *)malloc(hsize)) == NULL) return(NULL);
4201 		memcpy(wb->hinsi_list, hlist, hsize);
4202 	} else
4203 		wb->hinsi_list = NULL;
4204 	/*
4205 	    wb->dai_top = (sb->status == WNN_CONNECT)? 0:1;
4206 	��ʸ�����Ƭ�ʳ��ξ�ʸ��˴ؤ��Ƥϡ�status �Ϥ����ø����ͤ����äƤ��롣
4207 	*/
4208 	s = sb->yomi;
4209 
4210 	for(wb1 = wb; ;){
4211 		if(wb1 == wb) c = wb1->yomi;
4212 		else c = (w_char *)wb1;
4213 		end = (w_char *)&wb1->next;
4214 
4215 		for(; c < end;) {
4216 			if((*c++ = *s++) == 0){
4217 				if(where == 1){
4218 					where = 3;
4219 					c--;
4220 					s = sb->fuzoku;
4221 				} else if(where == 3){
4222 					where = 0;
4223 					s = sb->kanji;
4224 				} else if(where == 0){
4225 					where = 4;
4226 					c--;
4227 					s = sb->fuzoku;
4228 				} else{
4229 					goto out;
4230 				}
4231 			}
4232 		}
4233 		wb1->next = get_new_bun(buf);
4234 		wb1 = wb1->next;
4235 	}
4236 out:
4237 	wb1->next = NULL;
4238 	return(wb);
4239 }
4240 
4241 static void
make_space_for(buf,zenp,bun_no,bun_no2,cnt)4242 make_space_for(buf, zenp, bun_no, bun_no2, cnt)
4243 register struct wnn_buf_mt *buf;
4244 int bun_no, bun_no2, zenp;
4245 int cnt;
4246 {
4247 	switch(zenp){
4248 	case BUN:
4249 		make_space_for_bun(buf,bun_no, bun_no2, cnt);
4250 		break;
4251 	case ZENKOUHO:
4252 		make_space_for_zenkouho(buf,bun_no, bun_no2, cnt);
4253 	}
4254 }
4255 
4256 static void
make_space_for_bun(buf,bun_no,bun_no2,cnt)4257 make_space_for_bun(buf, bun_no, bun_no2, cnt)
4258 register struct wnn_buf_mt *buf;
4259 int bun_no, bun_no2;
4260 int cnt;
4261 {
4262 	int newsize;
4263 	register int k;
4264 
4265 	newsize = buf->orig.bun_suu + cnt - (bun_no2 - bun_no);
4266 
4267 #define Realloc(a, b) realloc((char *)(a), (unsigned)(b))
4268 
4269 	if(newsize > buf->orig.msize_bun){
4270 		buf->orig.bun = (WNN_BUN **)Realloc(buf->orig.bun, newsize * sizeof(WNN_BUN *));
4271 		buf->orig.down_bnst = (WNN_BUN **)Realloc(buf->orig.down_bnst, newsize * sizeof(WNN_BUN *));
4272 		buf->orig.msize_bun = newsize;
4273 	}
4274 
4275 
4276 	for(k = buf->orig.bun_suu; k < newsize; k++){
4277 		buf->orig.down_bnst[k] = NULL;
4278 	}
4279 	memcpy((char *)&buf->orig.bun[bun_no + cnt], (char *)&buf->orig.bun[bun_no2],
4280 	    (buf->orig.bun_suu - bun_no2) * sizeof(WNN_BUN *));
4281 	memcpy((char *)&buf->orig.down_bnst[bun_no + cnt], (char *)&buf->orig.down_bnst[bun_no2],
4282 	    (buf->orig.bun_suu - bun_no2) * sizeof(WNN_BUN *));
4283 	if(bun_no2 < bun_no + cnt){
4284 		memset((char *)&buf->orig.down_bnst[bun_no2], 0, (bun_no + cnt - bun_no2) * sizeof(WNN_BUN *));
4285 	}
4286 	buf->orig.bun_suu = newsize;
4287 }
4288 
4289 static void
make_space_for_zenkouho(buf,bun_no,bun_no2,cnt)4290 make_space_for_zenkouho(buf, bun_no, bun_no2, cnt)
4291 struct wnn_buf_mt *buf;
4292 int bun_no, bun_no2;
4293 register int cnt;
4294 {
4295 	register int newsize;
4296 
4297 	newsize = buf->orig.zenkouho_suu + cnt - (bun_no2 - bun_no);
4298 
4299 	if(newsize > buf->orig.msize_zenkouho){
4300 		buf->orig.zenkouho = (WNN_BUN **)Realloc(buf->orig.zenkouho, newsize * sizeof(WNN_BUN *));
4301 		buf->orig.zenkouho_dai = (int *)Realloc(buf->orig.zenkouho_dai, (1 + newsize) * sizeof(int *));
4302 		buf->orig.msize_zenkouho = newsize;
4303 	}
4304 	memcpy((char *)&buf->orig.zenkouho[bun_no + cnt],
4305 	    (char *)&buf->orig.zenkouho[bun_no2],
4306 	    (buf->orig.zenkouho_suu - bun_no2) * sizeof(WNN_BUN *));
4307 	buf->orig.zenkouho_suu = newsize;
4308 }
4309 
4310 
4311 static int
insert_sho(buf,zenp,bun_no,bun_no2,sp,cnt,uniq_level,fuku,nhinsi,hlist)4312 insert_sho(buf, zenp, bun_no, bun_no2, sp, cnt, uniq_level, fuku, nhinsi, hlist)
4313 struct wnn_buf_mt *buf;
4314 int bun_no, bun_no2;
4315 register struct wnn_sho_bunsetsu *sp;
4316 int cnt;
4317 int zenp;			/* daip */
4318 int uniq_level;			/* uniq is only supported when bun_no = -1
4319 				   and zenp == ZENKOUHO */
4320 int fuku, nhinsi, *hlist;
4321 {
4322 	register WNN_BUN **b;
4323 	register int k;
4324 
4325 	if(bun_no == -1){
4326 		bun_no = bun_no2 = (zenp == BUN)? buf->orig.bun_suu: buf->orig.zenkouho_suu;
4327 	}
4328 
4329 	/* It will make too big space when uniq_level > 0, but That's OK! */
4330 	make_space_for(buf, zenp, bun_no, bun_no2, cnt);
4331 
4332 	b = ((zenp == BUN)? buf->orig.bun: buf->orig.zenkouho) + bun_no;
4333 	for(k = bun_no ; k < bun_no + cnt ; k++, sp++){
4334 		/* �ʻ�����Ѵ��κݤϡ�find_same_kouho() ���ơ�
4335 			   ������ꥹ�ȤΥ��֥���ɤ� */
4336 		if(uniq_level && ((k < bun_no + cnt - 2) || nhinsi)){
4337 			if(find_same_kouho(sp, buf->orig.zenkouho, b,uniq_level))continue;
4338 		}
4339 		*b = get_sho(buf, sp, zenp, SHO, fuku, nhinsi, hlist);
4340 		(*b)->dai_top = (sp->status == WNN_CONNECT)? 0:1;
4341 		if(zenp != BUN){
4342 			if(buf->orig.zenkouho_endvect != -1){
4343 				(*b)->dai_end = (sp->status_bkwd == WNN_CONNECT_BK)? 0:1;
4344 			} else{
4345 				(*b)->dai_end = 1;
4346 			}
4347 		}
4348 		b++;
4349 	}
4350 	if(uniq_level && zenp == ZENKOUHO){
4351 		buf->orig.zenkouho_suu = b - buf->orig.zenkouho;
4352 	}
4353 	return(cnt + bun_no);
4354 }
4355 
4356 /* for zenkouho, assume bun_no = bun_no2 = zenkouho_suu */
4357 static int
insert_dai(buf,zenp,bun_no,bun_no2,dp,dcnt,uniq_level,fuku,nhinsi,hlist)4358 insert_dai(buf, zenp, bun_no, bun_no2, dp, dcnt, uniq_level, fuku, nhinsi, hlist)
4359 struct wnn_buf_mt *buf;
4360 int bun_no, bun_no2;
4361 struct wnn_dai_bunsetsu *dp;
4362 int dcnt;
4363 int zenp;
4364 int uniq_level;
4365 int fuku, nhinsi, *hlist;
4366 {
4367 	register WNN_BUN **b, **b0;
4368 	register int k, l, m;
4369 	register int cnt = 0;
4370 	struct wnn_sho_bunsetsu *sp, *sp1;
4371 
4372 	if(bun_no == -1){
4373 		bun_no = bun_no2 = (zenp == BUN)? buf->orig.bun_suu: buf->orig.zenkouho_suu;
4374 	}
4375 
4376 	for(k = 0; k < dcnt ; k++){
4377 		cnt += dp[k].sbncnt;
4378 	}
4379 	make_space_for(buf, zenp, bun_no, bun_no2, cnt);
4380 	/* zenkouho_dai_suu must not be initialized */
4381 
4382 	b = ((zenp == BUN)? buf->orig.bun: buf->orig.zenkouho) + bun_no;
4383 
4384 	for(k = 0, m = buf->orig.zenkouho_dai_suu ; k < dcnt; k++){
4385 		/* �ʻ�����Ѵ��κݤϡ�find_same_kouho_dai() ���ơ�
4386 			   ������ꥹ�ȤΥ��֥���ɤ� */
4387 		if(uniq_level && ((k < dcnt - 2) || nhinsi)){
4388 			if(find_same_kouho_dai(&dp[k], buf, m, uniq_level))
4389 				continue;
4390 		}
4391 		sp = dp[k].sbn;
4392 		if(zenp == ZENKOUHO){
4393 			buf->orig.zenkouho_dai[m++] = b - buf->orig.zenkouho;
4394 		}
4395 		b0 = b;
4396 		sp1 = sp;
4397 		for(l = 0 ; l < dp[k].sbncnt; l++){
4398 			*b = get_sho(buf, sp, zenp, DAI, fuku, nhinsi, hlist);
4399 			if(zenp == ZENKOUHO){
4400 				if (l == dp[k].sbncnt -1){
4401 					if(buf->orig.zenkouho_endvect != -1){
4402 						(*b)->dai_end = (sp->status_bkwd == WNN_CONNECT_BK)? 0:1;
4403 					} else{
4404 						(*b)->dai_end = 0;
4405 					}
4406 				} else{
4407 					(*b)->dai_end = 0;
4408 				}
4409 			}
4410 			b++;
4411 			sp++;
4412 		}
4413 		(*b0)->dai_top = (sp1->status == WNN_CONNECT)? 0:1;
4414 		(*b0)->daihyoka = dp[k].hyoka;
4415 	}
4416 	if(zenp == ZENKOUHO){
4417 		buf->orig.zenkouho_dai[m] = b - buf->orig.zenkouho;
4418 		buf->orig.zenkouho_suu = b - buf->orig.zenkouho;
4419 		buf->orig.zenkouho_dai_suu = m;
4420 	}
4421 	return(cnt + bun_no);
4422 }
4423 
4424 static void
set_sho(b,p)4425 set_sho(b, p)
4426 register WNN_BUN *b;
4427 register WNN_BUN **p;
4428 {
4429 	b->ref_cnt++;
4430 	*p = b;
4431 }
4432 
4433 static void
set_dai(b,p,n)4434 set_dai(b, p, n)
4435 register WNN_BUN **b;
4436 register WNN_BUN **p;
4437 register int n;
4438 {
4439 	for(;n;n--){
4440 		(*b)->ref_cnt++;
4441 		*p++ = *b++;
4442 	}
4443 }
4444 
4445 static int
get_c_jikouho_from_zenkouho(buf,dest)4446 get_c_jikouho_from_zenkouho(buf, dest)
4447 struct wnn_buf_mt *buf;
4448 WNN_BUN *dest;
4449 {
4450 	register int k;
4451 	w_char area[LENGTHKANJI];
4452 	w_char area1[LENGTHKANJI];
4453 	register WNN_BUN *b;
4454 
4455 	wnn_area(dest, area, WNN_KANJI, sizeof(area) / sizeof(w_char));
4456 	for(k = 0; k < buf->orig.zenkouho_suu; k++){
4457 		b = buf->orig.zenkouho[k];
4458 		if(b->entry == dest->entry && b->dic_no == dest->dic_no){
4459 			wnn_area(b, area1, WNN_KANJI, sizeof(area1) / sizeof(w_char));
4460 			if(wnn_Strcmp(area, area1) == 0){
4461 				return(k);
4462 			}
4463 		}
4464 	}
4465 	return(-1);
4466 }
4467 
4468 static int
get_c_jikouho_from_zenkouho_dai(buf,dest)4469 get_c_jikouho_from_zenkouho_dai(buf, dest)
4470 struct wnn_buf_mt *buf;
4471 WNN_BUN *dest;
4472 {
4473 	register int k;
4474 	w_char area[LENGTHKANJI];
4475 	w_char area1[LENGTHKANJI];
4476 	register WNN_BUN *b;
4477 	register int l;
4478 
4479 	wnn_area(dest, area, WNN_KANJI, sizeof(area) / sizeof(w_char));
4480 	for(k = 0; k < buf->orig.zenkouho_dai_suu; k++){
4481 		b = buf->orig.zenkouho[buf->orig.zenkouho_dai[k]];
4482 		for(l = 0 ; l < buf->orig.zenkouho_dai[k + 1]; l++, dest++, b++){
4483 			if(b->entry != dest->entry || b->dic_no != dest->dic_no) break;
4484 			wnn_area(b, area1, WNN_KANJI, sizeof(area1) / sizeof(w_char));
4485 			if(wnn_Strcmp(area, area1) != 0){
4486 				break;
4487 			}
4488 		}
4489 		if(l == buf->orig.zenkouho_dai[k + 1]){
4490 			return(k);
4491 		}
4492 	}
4493 	return(-1);
4494 }
4495 
4496 
4497 static int
get_c_jikouho(sp,cnt,dest)4498 get_c_jikouho(sp, cnt, dest)
4499 struct wnn_sho_bunsetsu *sp;
4500 int cnt;
4501 WNN_BUN *dest;
4502 {
4503 	register int k;
4504 	register int len;
4505 	w_char area[LENGTHKANJI];
4506 
4507 	wnn_area(dest, area, WNN_KANJI, sizeof(area) / sizeof(w_char));
4508 	for(k = 0; k < cnt; k++,sp++){
4509 		if(sp->entry == dest->entry && sp->dic_no == dest->dic_no
4510 		    && sp->kangovect == dest->kangovect){
4511 			if(wnn_Strncmp(area, sp->kanji, len = wnn_Strlen(sp->kanji)) == 0 &&
4512 			    wnn_Strcmp(area + len, sp->fuzoku) == 0){
4513 				return(k);
4514 			}
4515 		}
4516 	}
4517 	return(-1);
4518 }
4519 
4520 static int
get_c_jikouho_dai(dp,cnt,dest,bun_no)4521 get_c_jikouho_dai(dp, cnt, dest, bun_no)
4522 struct wnn_dai_bunsetsu *dp;
4523 int cnt;
4524 WNN_BUN **dest;
4525 int bun_no;
4526 {
4527 	register int k, l;
4528 	register int len;
4529 	w_char area[LENGTHKANJI];
4530 	register struct wnn_sho_bunsetsu *sp;
4531 
4532 	for(k = 0; k < cnt; k++,dp++){
4533 		sp = dp->sbn;
4534 		for(l = 0 ; l < dp->sbncnt; l++, sp++){
4535 			if(sp->entry != (dest[bun_no + l])->entry ||
4536 			    sp->kangovect != (dest[bun_no + l])->kangovect ||
4537 			    sp->dic_no != (dest[bun_no + l])->dic_no){
4538 				break;
4539 			}
4540 			wnn_area(dest[bun_no + l], area, WNN_KANJI, sizeof(area) / sizeof(w_char));
4541 			if(wnn_Strncmp(area, sp->kanji, len = wnn_Strlen(sp->kanji)) != 0 ||
4542 			    wnn_Strcmp(area + len, sp->fuzoku) != 0){
4543 				break;
4544 			}
4545 		}
4546 		if(l == dp->sbncnt) return(k);
4547 	}
4548 	return(-1);
4549 }
4550 
4551 
4552 static int
find_same_kouho(sp,st,end,level)4553 find_same_kouho(sp, st, end, level)
4554 struct wnn_sho_bunsetsu *sp;
4555 register WNN_BUN **st, **end;
4556 int level;
4557 {
4558 	register int len;
4559 	w_char area[LENGTHKANJI];
4560 	register WNN_BUN *b;
4561 
4562 	if(level == WNN_UNIQ){
4563 		for(; st < end; st++){
4564 			b = *st;
4565 			if(sp->hinsi == b->hinsi){
4566 				wnn_area(b, area, WNN_KANJI, sizeof(area) / sizeof(w_char));
4567 				if(wnn_Strncmp(area, sp->kanji, len = wnn_Strlen(sp->kanji)) == 0 &&
4568 				    wnn_Strcmp(area + len, sp->fuzoku) == 0){
4569 					return(1);
4570 				}
4571 			}
4572 		}
4573 	} else{ /* level = WNN_UNIQ_KNJ */
4574 		for(; st < end; st++){
4575 			b = *st;
4576 			wnn_area(b, area, WNN_KANJI, sizeof(area) / sizeof(w_char));
4577 			if(wnn_Strncmp(area, sp->kanji, len = wnn_Strlen(sp->kanji)) == 0 &&
4578 			    wnn_Strcmp(area + len, sp->fuzoku) == 0){
4579 				return(1);
4580 			}
4581 		}
4582 	}
4583 	return(0);
4584 }
4585 
4586 static int
find_same_kouho_dai(dp,buf,top,level)4587 find_same_kouho_dai(dp, buf, top, level)
4588 struct wnn_dai_bunsetsu *dp;
4589 struct wnn_buf_mt *buf;
4590 int top;
4591 int level;
4592 {
4593 	int len;
4594 	register int k, l;
4595 	w_char area[LENGTHKANJI];
4596 	WNN_BUN *b;
4597 	register struct wnn_sho_bunsetsu *sp;
4598 
4599 	for(k = 0 ; k < top ; k++){
4600 		for(l = 0,sp = dp->sbn ; l < dp->sbncnt; l++, sp++){
4601 			b = buf->orig.zenkouho[buf->orig.zenkouho_dai[k] + l];
4602 			if(sp->end - sp->start + 1 != b->yomilen) break;/* From: tsuiki */
4603 			if(level != WNN_UNIQ_KNJ){
4604 				if(sp->hinsi != b->hinsi) break;
4605 			}
4606 			wnn_area(b, area, WNN_KANJI, sizeof(area) / sizeof(w_char));
4607 			if(wnn_Strncmp(area, sp->kanji, len = wnn_Strlen(sp->kanji)) != 0 ||
4608 			    wnn_Strcmp(area + len, sp->fuzoku) != 0){
4609 				break;
4610 			}
4611 		}
4612 		if(l == dp->sbncnt)
4613 			return(1);
4614 	}
4615 	return(0);
4616 }
4617 
4618 int
wnn_cnt_free(buf)4619 wnn_cnt_free(buf)
4620 struct wnn_buf *buf;
4621 {
4622 	register int n;
4623 	register WNN_BUN *b;
4624 
4625 	for(n = 0, b = buf->free_heap;b;n++, b = b->free_next);
4626 	return(n);
4627 }
4628 
4629 static struct wnn_jdata *
jl_word_info_e_body(env,dic_no,entry)4630 jl_word_info_e_body(env, dic_no, entry)
4631 register struct wnn_env_int *env;
4632 int dic_no, entry;
4633 {
4634 	struct wnn_jdata *x;
4635 
4636 	if (js_word_info(env,dic_no, entry, &wordrb) < 0) {
4637 		if_dead_disconnect(env);
4638 		return(NULL);
4639 	}
4640 	x = (struct wnn_jdata *)(wordrb.buf);
4641 	return x;
4642 }
4643 
4644 struct wnn_jdata *
jl_word_info_e(env,dic_no,entry)4645 jl_word_info_e(env, dic_no, entry)
4646 register struct wnn_env *env;
4647 int dic_no, entry;
4648 {
4649 	struct wnn_jdata *x;
4650 
4651 	if(!env) return(NULL);
4652 
4653 	env_wnn_errorno_set = 0;
4654 	x = jl_word_info_e_body((WNN_ENV_INT *)env, dic_no, entry);
4655 
4656 	return x;
4657 }
4658 
4659 struct wnn_jdata *
jl_word_info(buf,dic_no,entry)4660 jl_word_info(buf, dic_no, entry)
4661 register struct wnn_buf *buf;
4662 int dic_no, entry;
4663 {
4664 	struct wnn_jdata *x;
4665 
4666 	if(!buf || !(buf->env)) return(NULL);
4667 
4668 
4669 	buf_wnn_errorno_set = 0;
4670 	x = jl_word_info_e_body((WNN_ENV_INT *)buf->env, dic_no, entry);
4671 
4672 	return x;
4673 }
4674 
4675 /*:::DOC_START
4676  *
4677  *    Function Name: jl_dic_list_e_body
4678  *    Description  : �����������Υ��֥롼����
4679  *    Parameter    :
4680  *         env :     (InOut) �Ķ��ؤΥݥ���
4681  *	   dmask :   (In) ��������ޥ���
4682  *	   dicinfo : (Ont) �ǡ�����������ѹ�¤�ΤؤΥݥ���
4683  *
4684  *    Return value : -1==ERROR, else ��Ͽ�����
4685  *
4686  *    Revision history:
4687  *
4688  *:::DOC_END
4689  */
4690 static int
jl_dic_list_e_body(env,dmask,dicinfo)4691 jl_dic_list_e_body(env, dmask, dicinfo)
4692 struct wnn_env_int *env;
4693 unsigned long dmask;
4694 WNN_DIC_INFO **dicinfo;
4695 {
4696 	WNN_DIC_INFO *info;
4697 	int cnt;
4698 	register int k;
4699 	register char *c;
4700 
4701 	if(dmask == 0)
4702 		cnt = js_dic_list(env, &dicrb);
4703 		else
4704 		cnt = js_fi_dic_list(env, dmask, &dicrb);
4705 
4706 	if (cnt < 0) {
4707 		if_dead_disconnect(env);
4708 		return(-1);
4709 	}
4710 	info = (WNN_DIC_INFO *)(dicrb.buf);
4711 
4712 	/* If the file is loaded from this client, change the file name to the one
4713 	   used in loading it. */
4714 
4715 	for(k = 0 ; k < cnt ; k++){
4716 		c = find_file_name_from_id(env, info[k].body);
4717 		if(c != NULL){
4718 			strncpy(info[k].fname, c, WNN_F_NAMELEN - 1);
4719 			info[k].fname[WNN_F_NAMELEN - 1] = 0;
4720 		}
4721 
4722 		c = find_file_name_from_id(env, info[k].hindo);
4723 		if(c != NULL){
4724 			strncpy(info[k].hfname, c, WNN_F_NAMELEN - 1);
4725 			info[k].hfname[WNN_F_NAMELEN - 1] = 0;
4726 		}
4727 	}
4728 
4729 	*dicinfo = info;
4730 
4731 	return(cnt);
4732 } /* End of jl_dic_list_e_body */
4733 
4734 /*:::DOC_START
4735  *
4736  *    Function Name: jl_dic_list_e
4737  *    Description  : �Ķ�����Ͽ����Ƥ���ף�����������
4738  *    Parameter    :
4739  *         env :     (InOut) �Ķ��ؤΥݥ���
4740  *         dicinfo : (Ont) �ǡ�����������ѹ�¤�ΤؤΥݥ���
4741  *
4742  *    Return value : -1==ERROR, else ��Ͽ�����
4743  *
4744  *    Revision history:
4745  *
4746  *:::DOC_END
4747  */
4748 int
jl_dic_list_e(env,dicinfo)4749 jl_dic_list_e(env, dicinfo)
4750 struct wnn_env *env;
4751 WNN_DIC_INFO **dicinfo;
4752 {
4753 	int x;
4754 
4755 	if(!env) return(-1);
4756 
4757 	env_wnn_errorno_set = 0;
4758 	x = jl_dic_list_e_body((WNN_ENV_INT *)env, 0, dicinfo);
4759 
4760 	return x;
4761 } /* End of jl_dic_list_e */
4762 
4763 /*:::DOC_START
4764  *
4765  *    Function Name: jl_dic_list
4766  *    Description  : �Ķ�����Ͽ����Ƥ���ף�����������
4767  *    Parameter    :
4768  *         buf : (InOut) �Хåե��ؤΥݥ���
4769  *         dip : (Ont) �ǡ�����������ѹ�¤�ΤؤΥݥ���
4770  *
4771  *    Return value : -1==ERROR, else ��Ͽ�����
4772  *
4773  *    Revision history:
4774  *
4775  *:::DOC_END
4776  */
4777 int
jl_dic_list(buf,dip)4778 jl_dic_list(buf, dip)
4779 register struct wnn_buf *buf;
4780 WNN_DIC_INFO **dip;
4781 {
4782 	int x;
4783 
4784 	if(!buf || !(buf->env)) return(-1);
4785 
4786 
4787 	buf_wnn_errorno_set = 0;
4788 	x = jl_dic_list_e_body((WNN_ENV_INT *)buf->env, 0, dip);
4789 
4790 	return x;
4791 } /* End of jl_dic_list */
4792 
4793 /*:::DOC_START
4794  *
4795  *    Function Name: jl_fi_dic_list_e
4796  *    Description  : �Ķ�����Ͽ����Ƥ��뼭����⡢���ꤷ��������
4797  *		     ���������
4798  *    Parameter    :
4799  *         env :     (InOut) �Ķ��ؤΥݥ���
4800  *	   dmask :   (In) ��������ޥ���
4801  *         dicinfo : (Ont) �ǡ�����������ѹ�¤�ΤؤΥݥ���
4802  *
4803  *    Return value : -1==ERROR, else ��Ͽ�����
4804  *
4805  *    Revision history:
4806  *
4807  *:::DOC_END
4808  */
4809 int
jl_fi_dic_list_e(env,dmask,dicinfo)4810 jl_fi_dic_list_e(env, dmask, dicinfo)
4811 struct wnn_env *env;
4812 unsigned long dmask;
4813 WNN_DIC_INFO **dicinfo;
4814 {
4815 	int x;
4816 
4817 	if(!env) return(-1);
4818 
4819 	env_wnn_errorno_set = 0;
4820 	x = jl_dic_list_e_body((WNN_ENV_INT *)env, dmask, dicinfo);
4821 
4822 	return x;
4823 } /* End of jl_fi_dic_list_e */
4824 
4825 /*:::DOC_START
4826  *
4827  *    Function Name: jl_fi_dic_list
4828  *    Description  : �Ķ�����Ͽ����Ƥ��뼭����⡢���ꤷ��������
4829  *                   ���������
4830  *    Parameter    :
4831  *         buf :   (InOut) �Хåե��ؤΥݥ���
4832  *	   dmask : (In) ��������ޥ���
4833  *         dip :   (Ont) �ǡ�����������ѹ�¤�ΤؤΥݥ���
4834  *
4835  *    Return value : -1==ERROR, else ��Ͽ�����
4836  *
4837  *    Revision history:
4838  *
4839  *:::DOC_END
4840  */
4841 int
jl_fi_dic_list(buf,dmask,dip)4842 jl_fi_dic_list(buf, dmask, dip)
4843 register struct wnn_buf *buf;
4844 unsigned long dmask;
4845 WNN_DIC_INFO **dip;
4846 {
4847 	int x;
4848 
4849 	if(!buf || !(buf->env)) return(-1);
4850 
4851 
4852 	buf_wnn_errorno_set = 0;
4853 	x = jl_dic_list_e_body((WNN_ENV_INT *)buf->env, dmask, dip);
4854 
4855 	return x;
4856 } /* End of jl_fi_dic_list */
4857 
4858 /*:::DOC_START
4859  *
4860  *    Function Name: jl_fuzokugo_list_e_body
4861  *    Description  : ��°���������Υ��֥롼����
4862  *    Parameter    :
4863  *         env :     (InOut) �Ķ��ؤΥݥ���
4864  *         curfzk :  (Out) ���߻��ѥե����뼱�̻�
4865  *         fzkinfo : (Out) ��°������������ѹ�¤�ΤؤΥݥ���
4866  *
4867  *    Return value : -1==ERROR, else �ɹ�����°���
4868  *
4869  *    Revision history:
4870  *
4871  *:::DOC_END
4872  */
4873 static int
jl_fuzokugo_list_e_body(env,curfzk,fzkinfo)4874 jl_fuzokugo_list_e_body(env, curfzk, fzkinfo)
4875 struct wnn_env *env;
4876 int *curfzk;
4877 WNN_FZK_INFO **fzkinfo;
4878 {
4879 	int cnt;
4880 
4881 	if((cnt = js_fuzokugo_list(env, curfzk, fzkinfo)) < 0) {
4882 		if_dead_disconnect(env);
4883 		return(-1);
4884 	}
4885 	return(cnt);
4886 } /* End of jl_fuzokugo_list_e_body */
4887 
4888 /*:::DOC_START
4889  *
4890  *    Function Name: jl_fuzokugo_list_e
4891  *    Description  : ���ꤵ�줿�����Ф��ɤ߹��ޤ�Ƥ�������°������
4892  *                   �Ķ��˸������ꤵ��Ƥ������μ��̻Ҥ��֤�
4893  *    Parameter    :
4894  *         env :     (In) �Ķ��ؤΥݥ���
4895  *         curfzk :  (Out) ���߻��ѥե����뼱�̻�
4896  *         fzkinfo : (Out) �ǡ�����������ѹ�¤�ΤؤΥݥ���
4897  *
4898  *    Return value : -1==ERROR, else �ɹ�����°���
4899  *
4900  *    Revision history:
4901  *
4902  *:::DOC_END
4903  */
4904 int
jl_fuzokugo_list_e(env,curfzk,fzkinfo)4905 jl_fuzokugo_list_e(env, curfzk, fzkinfo)
4906 struct wnn_env *env;
4907 int *curfzk;
4908 WNN_FZK_INFO **fzkinfo;
4909 {
4910 	int x;
4911 
4912 	if(!env) return(-1);
4913 
4914 	env_wnn_errorno_set = 0;
4915 	x = jl_fuzokugo_list_e_body((WNN_ENV_INT *)env, curfzk, fzkinfo);
4916 
4917 	return x;
4918 } /* End of jl_fuzokugo_list_e */
4919 
4920 /*:::DOC_START
4921  *
4922  *    Function Name: jl_fuzokugo_list
4923  *    Description  : ���ꤵ�줿�����Ф��ɤ߹��ޤ�Ƥ�������°������
4924  *                   �Ķ��˸������ꤵ��Ƥ������μ��̻Ҥ��֤�
4925  *    Parameter    :
4926  *         buf :    (In) �Хåե��ؤΥݥ���
4927  *         curfzk : (Out) ���߻��ѥե����뼱�̻�
4928  *         fzkp :   (Out) �ǡ�����������ѹ�¤�ΤؤΥݥ���
4929  *
4930  *    Return value : -1==ERROR, else �ɹ�����°���
4931  *
4932  *    Revision history:
4933  *
4934  *:::DOC_END
4935  */
4936 int
jl_fuzokugo_list(buf,curfzk,fzkp)4937 jl_fuzokugo_list(buf, curfzk, fzkp)
4938 register struct wnn_buf *buf;
4939 int *curfzk;
4940 WNN_FZK_INFO **fzkp;
4941 {
4942 	int x;
4943 
4944 	if(!buf || !(buf->env)) return(-1);
4945 
4946 
4947 	buf_wnn_errorno_set = 0;
4948 	x = jl_fuzokugo_list_e_body((WNN_ENV_INT *)buf->env, curfzk, fzkp);
4949 
4950 	return x;
4951 } /* End of jl_fuzokugo_list */
4952 
4953 /*:::DOC_START
4954  *
4955  *    Function Name: jl_free
4956  *    Description  : �Ѵ��ʻ������°������ free ����
4957  *    Parameter    :
4958  *	   ptr : �оݥݥ���
4959  *
4960  *    Return value : 0==SUCCESS, -1==ERROR
4961  *
4962  *    Revision history:
4963  *
4964  *:::DOC_END
4965  */
4966 int
jl_free(ptr)4967 jl_free(ptr)
4968 char *ptr;
4969 {
4970 	free(ptr);
4971 	return(0);
4972 } /* End of jl_free */
4973 
4974 
4975 static int
sort_func_ws(a,b)4976 sort_func_ws(a,b)
4977 register char *a, *b;
4978 {
4979 	int ah, bh, ai, bi, iah, ibh, iai, ibi;
4980 	ah = ((struct wnn_jdata *)a)->hindo;
4981 	bh = ((struct wnn_jdata *)b)->hindo;
4982 	iah = ((struct wnn_jdata *)a)->int_hindo;
4983 	ibh = ((struct wnn_jdata *)b)->int_hindo;
4984 	ai = ((struct wnn_jdata *)a)->ima;
4985 	bi = ((struct wnn_jdata *)b)->ima;
4986 	iai = ((struct wnn_jdata *)a)->int_ima;
4987 	ibi = ((struct wnn_jdata *)b)->int_ima;
4988 
4989 	if(ai == WNN_IMA_OFF && ah == WNN_ENTRY_NO_USE) return(1);
4990 	if(bi == WNN_IMA_OFF && bh == WNN_ENTRY_NO_USE) return(-1);
4991 	if(iai == WNN_IMA_OFF && iah == WNN_ENTRY_NO_USE) return(1);
4992 	if(ibi == WNN_IMA_OFF && ibh == WNN_ENTRY_NO_USE) return(-1);
4993 
4994 	if(ai != bi){
4995 		if(ai < bi) return(1);
4996 		return(-1);
4997 	}
4998 	if(iah >= 0){
4999 		ah += iah;
5000 		bh += ibh;
5001 	}
5002 	if(ah > bh)return(-1);
5003 	if(ah < bh)return(1);
5004 	return(0);
5005 }
5006 
5007 static int
jl_word_search_e_body(env,dic_no,yomi,jdp)5008 jl_word_search_e_body(env,dic_no, yomi, jdp)
5009 register struct wnn_env_int *env;
5010 int dic_no;
5011 w_char *yomi;
5012 struct wnn_jdata **jdp;
5013 {
5014 	register int cnt;
5015 	struct wnn_jdata *jd;
5016 
5017 	if ((cnt = js_word_search(env,dic_no, yomi, &wordrb)) < 0) {
5018 		if_dead_disconnect(env);
5019 		return(-1);
5020 	}
5021 	jd = (struct wnn_jdata *)wordrb.buf;
5022 	qsort((char *)jd,cnt,sizeof(struct wnn_jdata),sort_func_ws);
5023 	*jdp = jd;
5024 	return(cnt);
5025 }
5026 
5027 int
jl_word_search_e(env,dic_no,yomi,jdp)5028 jl_word_search_e(env,dic_no, yomi, jdp)
5029 register struct wnn_env *env;
5030 int dic_no;
5031 w_char *yomi;
5032 struct wnn_jdata **jdp;
5033 {
5034 	int x;
5035 
5036 	if(!env) return(-1);
5037 
5038 	env_wnn_errorno_set = 0;
5039 	x = jl_word_search_e_body((WNN_ENV_INT *)env,dic_no, yomi, jdp);
5040 
5041 	return x;
5042 }
5043 
5044 int
jl_word_search(buf,dic_no,yomi,jdp)5045 jl_word_search(buf, dic_no, yomi, jdp)
5046 register struct wnn_buf *buf;
5047 int dic_no;
5048 w_char *yomi;
5049 struct wnn_jdata **jdp;
5050 {
5051 	int x;
5052 
5053 	if(!buf || !(buf->env)) return(-1);
5054 
5055 
5056 	buf_wnn_errorno_set = 0;
5057 	x = jl_word_search_e_body((WNN_ENV_INT *)buf->env, dic_no, yomi, jdp);
5058 
5059 	return x;
5060 }
5061 
5062 static int
jl_word_search_by_env_e_body(env,yomi,jdp)5063 jl_word_search_by_env_e_body(env, yomi, jdp)
5064 register struct wnn_env_int *env;
5065 struct wnn_jdata **jdp;
5066 w_char *yomi;
5067 {
5068 	register int cnt;
5069 	struct wnn_jdata *jd;
5070 
5071 	if ((cnt = js_word_search_by_env(env, yomi, &wordrb)) < 0) {
5072 		if_dead_disconnect(env);
5073 		return(-1);
5074 	}
5075 	jd = (struct wnn_jdata *)wordrb.buf;
5076 	qsort((char *)jd,cnt,sizeof(struct wnn_jdata),sort_func_ws);
5077 	*jdp = jd;
5078 	return(cnt);
5079 }
5080 
5081 int
jl_word_search_by_env_e(env,yomi,jdp)5082 jl_word_search_by_env_e(env, yomi, jdp)
5083 register struct wnn_env *env;
5084 struct wnn_jdata **jdp;
5085 w_char *yomi;
5086 {
5087 	int x;
5088 
5089 	if(!env) return(-1);
5090 
5091 	env_wnn_errorno_set = 0;
5092 	x = jl_word_search_by_env_e_body((WNN_ENV_INT *)env, yomi, jdp);
5093 
5094 	return x;
5095 }
5096 
5097 int
jl_word_search_by_env(buf,yomi,jdp)5098 jl_word_search_by_env(buf, yomi, jdp)
5099 register struct wnn_buf *buf;
5100 struct wnn_jdata **jdp;
5101 w_char *yomi;
5102 {
5103 	int x;
5104 
5105 	if(!buf || !(buf->env)) return(-1);
5106 
5107 
5108 	buf_wnn_errorno_set = 0;
5109 	x = jl_word_search_by_env_e_body((WNN_ENV_INT *)buf->env, yomi, jdp);
5110 
5111 	return x;
5112 }
5113 
5114 static void
add_down_bnst(buf,k,b)5115 add_down_bnst(buf, k, b)
5116 register struct wnn_buf_mt *buf;
5117 register int k;
5118 register WNN_BUN *b;
5119 {
5120 	if(b->down) return; /* In order to prevent roop! */
5121 	if(b == buf->orig.down_bnst[k]) return; /* In order to prevent roop! */
5122 	/* It occurs when Zenkouho-->Nobi-conv */
5123 	b->down = buf->orig.down_bnst[k];
5124 	buf->orig.down_bnst[k] = b;
5125 	b->ref_cnt ++;
5126 }
5127 
5128 
5129 #define REAL_PARAM(x) (strcmp(x, "-"))
5130 
5131 /** wnnrc ���ƤΥѥ�᡼�������� */
5132 int
jl_set_env_wnnrc(env,wnnrc_n,error_handler,message_handler)5133 jl_set_env_wnnrc(env, wnnrc_n, error_handler, message_handler)
5134 register struct wnn_env *env;
5135 char *wnnrc_n;
5136 int  (*error_handler)(), (*message_handler)();
5137 {
5138 	int level = 0;
5139 	int x;
5140 
5141 	if(!env) return(-1);
5142 
5143 	env_wnn_errorno_set = 0;
5144 	if((int)error_handler ==  WNN_CREATE){
5145 		confirm_state = CREATE_WITHOUT_CONFIRM;
5146 	} else if((int)error_handler ==  WNN_NO_CREATE){
5147 		confirm_state = NO_CREATE;
5148 	} else{
5149 		confirm_state = CONFIRM;
5150 	}
5151 
5152 	x = jl_set_env_wnnrc1_body((WNN_ENV_INT *)env, wnnrc_n, error_handler, message_handler, level, 0);
5153 
5154 	confirm_state = 0;
5155 
5156 	return(x);
5157 }
5158 
5159 static int
jl_set_env_wnnrc1_body(env,wnnrc_n,error_handler,message_handler,level,local)5160 jl_set_env_wnnrc1_body(env, wnnrc_n, error_handler, message_handler, level, local)
5161 register struct wnn_env_int *env;
5162 char *wnnrc_n;
5163 int  (*error_handler)(), (*message_handler)();
5164 int level;
5165 int local;
5166 {
5167 	register int num, rev, prio;
5168 	char s[20][MAXPATHLEN];
5169 	char code[MAXPATHLEN];
5170 	char tmp[MAXPATHLEN];
5171 	int tmplen;
5172 	register FILE *fp;
5173 	unsigned long vmask = 0;
5174 	int *flag;
5175 	struct wnn_henkan_env henv;
5176 	int  (*error_handler1)() = (int (*)())0;
5177 	char *p;
5178 	extern char *getenv();
5179 
5180 	if(!(*wnnrc_n)) return -1;
5181 	if(level > MAXINCLUDE){
5182 
5183 		message_out(message_handler,
5184 		    msg_get(wnn_msg_cat, 206, NULL));
5185 		/*
5186 				    "include �Υ�٥뤬¿�᤮�ޤ���"
5187 				    */
5188 
5189 		return(-1);
5190 	}
5191 	if (!strcmp(wnnrc_n, DEFAULT_RC_NAME)) {
5192 		/*
5193 			 * �ǥե���Ȥ�wnnenvrc��õ���˹Ԥ�
5194 		         */
5195 		if(!(p = getenv("HOME")))
5196 			goto Default_WNVRC;
5197 		tmplen = sizeof(tmp);
5198 		strncpy(tmp, p, tmplen - 1);
5199 		tmp[tmplen - 1] = 0;
5200 		if (strlen(tmp) + strlen(FIWNN_DIR) >= tmplen)
5201 			goto Default_WNVRC;
5202 		strcat(tmp, FIWNN_DIR);
5203 		if (strlen(tmp) + strlen(ENVRCFILE) >= tmplen)
5204 			goto Default_WNVRC;
5205 		strcat(tmp, ENVRCFILE);
5206 
5207 		if ((fp = fopen(tmp, "r")) == NULL) {
5208 Default_WNVRC:
5209 			/*
5210 			 * �桼���Υǥե���ȥե����뤬̵���ä��Τǡ������ƥ�Υǥե���Ȥ�
5211 			 * ���˹Ԥ�
5212 			 */
5213 			snprintf(tmp, sizeof(tmp), "%s/%s%s", ETCDIR, WNN_DEFAULT_LANG, ENVRCFILE);
5214 			/* /etc/wnn7/ja_JP/wnnenvrc */
5215 			if((fp = fopen(tmp, "r")) == NULL) {
5216 				snprintf(tmp, sizeof(tmp), "%s/%s%s", LIBDIR, WNN_DEFAULT_LANG, ENVRCFILE);
5217 				/* /usr/lib/wnn7/ja_JP/wnnenvrc */
5218 				if((fp = fopen(tmp, "r")) == NULL) {
5219 					/*
5220 				 	 * �����ƥ�Υǥե���Ȥ�ʤ��ä��Τǥ��顼�ˤ���
5221 					 */
5222 					message_out(message_handler,
5223 					    msg_get(wnn_msg_cat, 111, NULL));
5224 
5225 					return(-1);
5226 				}
5227 			}
5228 		}
5229 	} else {
5230 		if((fp = fopen(wnnrc_n, "r")) == NULL){
5231 
5232 			/*
5233 				     * ���ꤵ�줿wnnennvrc�������ץ�Ǥ��ʤ�
5234 			             */
5235 			message_out(message_handler,
5236 			    msg_get(wnn_msg_cat, 207, NULL),
5237 			    wnnrc_n);
5238 
5239 			return(-1);
5240 		}
5241 	}
5242 	while(fgets(tmp,sizeof(tmp),fp  ) != NULL){
5243 		num = sscanf(tmp,
5244 		    "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",code,
5245 		    s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9],s[10],
5246 		    s[11],s[12],s[13],s[14],s[15],s[16],s[17],s[18],s[19]) ;
5247 		if (num <= 0) {
5248 			continue;
5249 		}
5250 		if(code[0] == ';'){
5251 			continue;
5252 		}
5253 		switch (code[0]) {
5254 		case 'a':
5255 			if (!strcmp(code, "autosave")) env->orig.autosave = atoi(s[0]);
5256 			break;
5257 		case 'k':
5258 			if (!strcmp(code, "kutouten")) {
5259 				/* ������ */
5260 				if (num < 2) goto _Err_happend;
5261 				vmask |= WNN_ENV_KUTOUTEN_MASK;
5262 				flag = &henv.kutouten_flag;
5263 				goto _set_flag;
5264 			} else if (!strcmp(code, "kakko")) {
5265 				/* ��� */
5266 				if (num < 2) goto _Err_happend;
5267 				vmask |= WNN_ENV_KAKKO_MASK;
5268 				flag = &henv.kakko_flag;
5269 				goto _set_flag;
5270 			} else if (!strcmp(code, "kigou")) {
5271 				/* ���� */
5272 				if (num < 2) goto _Err_happend;
5273 				vmask |= WNN_ENV_KIGOU_MASK;
5274 				flag = &henv.kigou_flag;
5275 				goto _set_flag;
5276 			}
5277 		}
5278 		if (local == 0 || local == REV_LOCAL) {
5279 			switch (code[0]) {
5280 			case 'b':
5281 				if (!strcmp(code, "bunsetsugiri_gakusyuu")) {
5282 AUTO_LEARNING:
5283 					if (local != REV_LOCAL) {
5284 						int dic_no, mode, type;
5285 
5286 						if (num < 6) goto _Err_happend;
5287 						if (!strcmp(code, "muhenkan_gakusyuu")) {
5288 							type = WNN_MUHENKAN_LEARNING;
5289 						} else {
5290 							type = WNN_BUNSETSUGIRI_LEARNING;
5291 						}
5292 						if (((dic_no = js_get_autolearning_dic(env, type)) == -1)
5293 							&& env_wnn_errorno_eql) {
5294 							if (env_wnn_errorno_eql != WNN_JSERVER_DEAD) {
5295 								message_out(message_handler, "%s :%s\n", s[0],
5296 											wnn_perror());
5297 							} else
5298 								message_out(message_handler, "%s\n",
5299 											wnn_perror());
5300 							goto _Err_happend;
5301 						}
5302 						expand_expr_all(s[0], env);
5303 						mode = atoi(s[1]);
5304 						if ((mode > 2) || (mode < 0)) goto _Err_happend;
5305 						if (!REAL_PARAM(s[3])) {
5306 							s[3][0] = '\0';
5307 						} else {
5308 							expand_expr_all(s[3], env);
5309 						}
5310 						rev = 0;
5311 						if (dic_no == WNN_NO_LEARNING) {
5312 							/* �ޤ��������ɤ��Ƥ��ʤ��Τǡ����ɤ��� */
5313 							prio = REAL_PARAM(s[2])? atoi(s[2]) :
5314 								WNN_DIC_PRIO_DEFAULT;
5315 							rev = REAL_PARAM(s[4])? atoi(s[4]) : 0;
5316 							/* ��ư�ؽ��μ���Ͼ���˺�� */
5317 							if (((dic_no = jl_dic_add_e_body(env, s[0], NULL, rev,
5318 															 prio, 0, 0, NULL,
5319 															 NULL,
5320 															 (int (*)())WNN_CREATE,
5321 															 message_handler))
5322 								 == -1) && (env_wnn_errorno_eql != 0)) {
5323 								if (env_wnn_errorno_eql != WNN_JSERVER_DEAD) {
5324 									message_out(message_handler, "%s :%s\n", s[0],
5325 												wnn_perror());
5326 								} else
5327 									message_out(message_handler, "%s\n",
5328 												wnn_perror());
5329 								goto _Err_happend;
5330 							}
5331 							js_set_autolearning_dic(env, type, dic_no);
5332 						}
5333 						if (!js_is_loaded_temporary_dic(env)) {
5334 							/* �ޤ��ƥ�ݥ�꼭�����ɤ��Ƥ��ʤ��Τǡ�
5335 							   ���ɤ��� */
5336 							if ((js_temporary_dic_add(env, rev) == -1) &&
5337 								(env_wnn_errorno_eql != 0)){
5338 								if (env_wnn_errorno_eql == WNN_NOT_SUPPORT_PACKET){
5339 									message_out(message_handler,
5340 												msg_get(wnn_msg_cat, 211,
5341 														"You can not temporary dictionary because server's version is old."));
5342 									continue;
5343 								} else if (env_wnn_errorno_eql !=
5344 										   WNN_JSERVER_DEAD) {
5345 									message_out(message_handler, "%s :%s\n", s[0],
5346 												wnn_perror());
5347 								} else
5348 									message_out(message_handler, "%s\n",
5349 												wnn_perror());
5350 								goto _Err_happend;
5351 							}
5352 						}
5353 						/* �ؽ��Υ⡼�ɤ����ꤹ�� */
5354 						if (type == WNN_MUHENKAN_LEARNING) {
5355 							henv.muhenkan_flag = mode;
5356 							vmask |= WNN_ENV_MUHENKAN_LEARN_MASK;
5357 						} else {
5358 							henv.bunsetsugiri_flag = mode;
5359 							vmask |= WNN_ENV_BUNSETSUGIRI_LEARN_MASK;
5360 						}
5361 					}
5362 				} else if (!strcmp(code, "boin_kabusoku")) {
5363 					/* �����������첻����­ */
5364 					if (num < 2) goto _Err_happend;
5365 					vmask |= WNN_ENV_BOIN_KABUSOKU_MASK;
5366 					flag = &henv.boin_kabusoku_flag;
5367 					goto _set_flag;
5368 				}
5369 				break;
5370 
5371 			case 'c':
5372 				if (!strcmp(code, "confirm")){
5373 					confirm_state = CONFIRM;
5374 				} else if (!strcmp(code, "confirm1")) {
5375 					confirm_state = CONFIRM1;
5376 				} else if (!strcmp(code, "create_without_confirm")) {
5377 					confirm_state = CREATE_WITHOUT_CONFIRM;
5378 				}
5379 				break;
5380 
5381 			case 'f':
5382 				if (!strcmp(code, "fi_hindo_kakuritu")) {
5383 					/* �ף��ƣɴط����پ徺��Ψ�ؿ� */
5384 					int is_wnn;
5385 HINDO_KAKURITU:
5386 					if(!strcmp(code, "hindo_kakuritu")) {
5387 						flag = &henv.freq_func_flag;
5388 						is_wnn = 1;
5389 					} else {
5390 						flag = &henv.fi_freq_func_flag;
5391 						is_wnn = 0;
5392 					}
5393 					switch (s[0][0]) {
5394 					case 'n':
5395 					case 'N':
5396 						if(!strncmp(s[0], "not", 3) ||
5397 						    !strncmp(s[0], "NOT", 3)) {
5398 							/* ���ٳؽ����ʤ� */
5399 							*flag = WNN_HINDO_NOT;
5400 						} else {
5401 							/* ���̳ؽ� */
5402 							*flag = WNN_HINDO_NORMAL;
5403 						}
5404 						break;
5405 					case 'a':
5406 					case 'A':
5407 						/* ɬ�����ٳؽ����� */
5408 						*flag = WNN_HINDO_ALWAYS;
5409 						break;
5410 					case 'h':
5411 					case 'H':
5412 						/* �����Ҥ��ؽ� */
5413 						*flag = WNN_HINDO_HIGH;
5414 						break;
5415 					case 'l':
5416 					case 'L':
5417 						/* ���露��ؽ� */
5418 						*flag = WNN_HINDO_LOW;
5419 						break;
5420 					default:
5421 						goto _Err_happend;
5422 					}
5423 					if(is_wnn) vmask |= WNN_ENV_FREQ_FUNC_MASK;
5424 					else vmask |= WNN_ENV_FI_FREQ_FUNC_MASK;
5425 					break;
5426 				} else if (!strcmp(code, "fukugou_yuusen")) {
5427 					/* ʣ���ͥ���Ѵ� */
5428 					if (num < 2) goto _Err_happend;
5429 					vmask |= WNN_ENV_COMPLEX_CONV_MASK;
5430 					flag = &henv.complex_flag;
5431 					goto _set_flag;
5432 				}
5433 				break;
5434 			case 'g':
5435 				if (!strcmp(code, "giji_number")) {
5436 					/* ���������ν��ɽ����ˡ */
5437 					switch (s[0][0]) {
5438 					case 'k':
5439 					case 'K':
5440 						if(!strcmp(s[0], "kansuuji")||
5441 						    !strcmp(s[0], "KANSUUJI")) {
5442 							henv.numeric_flag = WNN_NUM_KANSUUJI;
5443 						} else if(!strcmp(s[0], "kanold") ||
5444 						    !strcmp(s[0], "KANOLD")) {
5445 							henv.numeric_flag = WNN_NUM_KANOLD;
5446 						} else if(!strcmp(s[0], "kan") ||
5447 						    !strcmp(s[0], "KAN")) {
5448 							henv.numeric_flag = WNN_NUM_KAN;
5449 						}
5450 						break;
5451 					case 'h':
5452 					case 'H':
5453 						if(!strcmp(s[0], "hancan") ||
5454 						    !strcmp(s[0], "HANCAN")) {
5455 							henv.numeric_flag = WNN_NUM_HANCAN;
5456 						} else if(!strcmp(s[0], "han") ||
5457 						    !strcmp(s[0], "HAN")) {
5458 							henv.numeric_flag = WNN_NUM_HAN;
5459 						}
5460 						break;
5461 					case 'z':
5462 					case 'Z':
5463 						if(!strcmp(s[0], "zencan") ||
5464 						    !strcmp(s[0], "ZENCAN")) {
5465 							henv.numeric_flag = WNN_NUM_ZENCAN;
5466 						} else if(!strcmp(s[0], "zen") ||
5467 						    !strcmp(s[0], "ZEN")) {
5468 							henv.numeric_flag = WNN_NUM_ZEN;
5469 						}
5470 						break;
5471 					default:
5472 						goto _Err_happend;
5473 					}
5474 					vmask |= WNN_ENV_NUMERIC_MASK;
5475 				} else if (!strcmp(code, "giji_eisuu")) {
5476 					/* ��������ե��٥åȤν��ɽ����ˡ */
5477 					switch (s[0][0]) {
5478 					case 'h':
5479 					case 'H':
5480 						henv.alphabet_flag = WNN_ALP_HAN;
5481 						break;
5482 					case 'z':
5483 					case 'Z':
5484 						henv.alphabet_flag = WNN_ALP_ZEN;
5485 						break;
5486 					default:
5487 						goto _Err_happend;
5488 					}
5489 					vmask |= WNN_ENV_ALPHABET_MASK;
5490 				} else if (!strcmp(code, "giji_kigou")) {
5491 					/* ��������ν��ɽ����ˡ */
5492 					switch (s[0][0]) {
5493 					case 'h':
5494 					case 'H':
5495 						henv.symbol_flag = WNN_KIG_HAN;
5496 						break;
5497 					case 'j':
5498 					case 'J':
5499 						henv.symbol_flag = WNN_KIG_JIS;
5500 						break;
5501 					case 'a':
5502 					case 'A':
5503 						henv.symbol_flag = WNN_KIG_ASC;
5504 						break;
5505 					default:
5506 						goto _Err_happend;
5507 					}
5508 					vmask |= WNN_ENV_SYMBOL_MASK;
5509 				}
5510 				break;
5511 			case 'h':
5512 				if (!strcmp(code, "hindo_kakuritu")) {
5513 					goto HINDO_KAKURITU;
5514 				} else if (strcmp(code, "hanyou_gakusyu") == 0) {
5515 					/* ���Ѹ�ؽ� */
5516 					if (num < 2) goto _Err_happend;
5517 					vmask |= WNN_ENV_COMMON_LAERN_MASK;
5518 					flag = &henv.common_learn_flag;
5519 					goto _set_flag;
5520 				}
5521 				break;
5522 			case 'm':
5523 				if (!strcmp(code, "muhenkan_gakusyuu")) {
5524 					goto AUTO_LEARNING;
5525 				}
5526 				break;
5527 			case 'n':
5528 				if (strcmp(code, "no_create") == 0){
5529 					confirm_state = NO_CREATE;
5530 				} else if (!strcmp(code, "n_choka")) {
5531 					/* �����������֤��Ķ�� */
5532 					if (num < 2) goto _Err_happend;
5533 					vmask |= WNN_ENV_N_CHOKA_MASK;
5534 					flag = &henv.n_choka_flag;
5535 					goto _set_flag;
5536 				} else if (!strcmp(code, "nihongo_kousei")) {
5537 					/* ���ܸ칻�� */
5538 
5539 					if (strcmp(s[0], "FALSE"))
5540 						break;
5541 
5542 					/* ���Ѥ��ʻ�ꥹ�Ⱥ��� */
5543 					if (js_set_henkan_hinsi_group(env,
5544 						HINSI_NO_GOYOU,
5545 						HINSI_NO_GOYOU_START,
5546 						HINSI_NO_GOYOU_END, False) == -1)
5547 						goto _Err_happend;
5548 
5549 					/* ���ƻ����ʻ�ꥹ�Ⱥ��� */
5550 					if (js_set_henkan_hinsi_group(env,
5551 						HINSI_NO_ATEJI,
5552 						HINSI_NO_ATEJI_START,
5553 						HINSI_NO_ATEJI_END, False) == -1)
5554 						goto _Err_happend;
5555 				}
5556 				break;
5557 			case 'o':
5558 				if (strcmp(code, "okuri_gakusyu") == 0) {
5559 					/* ������ؽ� */
5560 					if (num < 2) goto _Err_happend;
5561 					vmask |= WNN_ENV_OKURI_LEARN_MASK;
5562 					flag = &henv.okuri_learn_flag;
5563 					goto _set_flag;
5564 				} else if (strcmp(code, "okuri_kijun") == 0) {
5565 					/* ��������� */
5566 					switch (s[0][0]) {
5567 					case 'r':
5568 					case 'R':
5569 						/* ��§ */
5570 						henv.okuri_flag = WNN_OKURI_REGULATION;
5571 						break;
5572 					case 'n':
5573 					case 'N':
5574 						/* ����ʤ� */
5575 						henv.okuri_flag = WNN_OKURI_NO;
5576 						break;
5577 					case 'y':
5578 					case 'Y':
5579 						/* ���� */
5580 						henv.okuri_flag = WNN_OKURI_YES;
5581 						break;
5582 					default:
5583 						goto _Err_happend;
5584 					}
5585 					vmask |= WNN_ENV_OKURI_MASK;
5586 				}
5587 				break;
5588 			case 'r':
5589 				if (strcmp(code, "rendaku") == 0) {
5590 					/* Ϣ������ */
5591 					if (num < 2) goto _Err_happend;
5592 					vmask |= WNN_ENV_RENDAKU_MASK;
5593 					flag = &henv.rendaku_flag;
5594 					goto _set_flag;
5595 				}
5596 				break;
5597 			case 's':
5598 				if (!strcmp(code, "setdic")){
5599 					if (local != REV_LOCAL){
5600 						/* dic_add */
5601 						int rdonly, hrdonly;
5602 						expand_expr_all(s[0], env);
5603 						if(num < 3 || !REAL_PARAM(s[1])){
5604 							s[1][0] = 0;
5605 						} else{
5606 							expand_expr_all(s[1], env);
5607 						}
5608 						prio = (num >= 4 && REAL_PARAM(s[2]))? atoi(s[2]) :
5609 							WNN_DIC_PRIO_DEFAULT;
5610 						rdonly = (num >= 5 && REAL_PARAM(s[3]))? atoi(s[3]) : 0;
5611 						hrdonly = (num >= 6 && REAL_PARAM(s[4]))? atoi(s[4]) : 0;
5612 						if(num < 7 || !REAL_PARAM(s[5])) s[5][0] = 0;
5613 						if(num < 8 || !REAL_PARAM(s[6])) s[6][0] = 0;
5614 						rev = (num >= 9 && REAL_PARAM(s[7]))? atoi(s[7]) : 0;
5615 
5616 						switch (confirm_state) {
5617 						case CONFIRM:
5618 						case CONFIRM1:
5619 							error_handler1 = error_handler;
5620 							break;
5621 						case CREATE_WITHOUT_CONFIRM:
5622 							error_handler1 = (int (*)())WNN_CREATE;
5623 							break;
5624 						case NO_CREATE:
5625 							error_handler1 = (int (*)())WNN_NO_CREATE;
5626 							break;
5627 						}
5628 
5629 						if (rev){
5630 							rev_setting(s[0], s[1], prio, rdonly, hrdonly,
5631 										s[5], s[6], rev);
5632 						}else{
5633 							if((jl_dic_add_e_body(env, s[0], s[1], rev, prio, rdonly,
5634 												  hrdonly, s[5], s[6], error_handler1,
5635 												  message_handler) == -1)
5636 							   && (env_wnn_errorno_eql != 0)) {
5637 								if (env_wnn_errorno_eql != WNN_JSERVER_DEAD)
5638 									message_out(message_handler, "%s (%s) :%s\n",
5639 												s[0], s[1], wnn_perror());
5640 								else
5641 									message_out(message_handler, "%s\n",
5642 												wnn_perror());
5643 								goto _Err_happend;
5644 							}
5645 						}
5646 					}
5647 					break;
5648 				} else if (!strcmp(code, "setfuzokugo") ||
5649 				    !strcmp(code, "setgrammar")) {
5650 					/* fuzokugo_set */
5651 					expand_expr_all(s[0], env);
5652 					if(jl_fuzokugo_set_e_body(env,s[0]) == -1){
5653 						if (env_wnn_errorno_eql != WNN_JSERVER_DEAD)
5654 							message_out(message_handler, "%s :%s\n", s[0],
5655 							    wnn_perror());
5656 							else
5657 							message_out(message_handler, "%s\n",
5658 							    wnn_perror());
5659 						goto _Err_happend;
5660 					}
5661 					break;
5662 				} else if (!strcmp(code, "setparam")){
5663 					struct wnn_param para;
5664 					/* setparam --- set parameter */
5665 					change_ascii_to_int(s[0], &para.n);
5666 					change_ascii_to_int(s[1], &para.nsho);
5667 					change_ascii_to_int(s[2], &para.p1);
5668 					change_ascii_to_int(s[3], &para.p2);
5669 					change_ascii_to_int(s[4], &para.p3);
5670 					change_ascii_to_int(s[5], &para.p4);
5671 					change_ascii_to_int(s[6], &para.p5);
5672 					change_ascii_to_int(s[7], &para.p6);
5673 					change_ascii_to_int(s[8], &para.p7);
5674 					change_ascii_to_int(s[9], &para.p8);
5675 					change_ascii_to_int(s[10], &para.p9);
5676 					change_ascii_to_int(s[11], &para.p10);
5677 					change_ascii_to_int(s[12], &para.p11);
5678 					change_ascii_to_int(s[13], &para.p12);
5679 					change_ascii_to_int(s[14], &para.p13);
5680 					change_ascii_to_int(s[15], &para.p14);
5681 					change_ascii_to_int(s[16], &para.p15);
5682 
5683 					if (js_param_set(env,&para) < 0) {
5684 						fclose(fp);
5685 
5686 						message_out(message_handler,
5687 						    msg_get(wnn_msg_cat, 208, NULL), wnnrc_n);
5688 						/*
5689 									 * "�ե����� \"%s\" �ǴĶ�������ˡ����顼��ȯ������
5690 									 * ����ˡ��������ߤ��ޤ���\n",
5691 									 */
5692 
5693 						if_dead_disconnect(env);
5694 						return(-1);
5695 					}
5696 					break;
5697 				} else if (!strcmp(code, "saisyu_siyou")) {
5698 					/* �ǽ����Ѻ�ͥ�� */
5699 					if (num < 2) goto _Err_happend;
5700 					vmask |= WNN_ENV_LAST_IS_FIRST_MASK;
5701 					flag = &henv.last_is_first_flag;
5702 					goto _set_flag;
5703 				} else if (!strcmp(code, "settou_gakusyu")) {
5704 					/* ��Ƭ��ؽ� */
5705 					if (num < 2) goto _Err_happend;
5706 					vmask |= WNN_ENV_PREFIX_LEARN_MASK;
5707 					flag = &henv.prefix_learn_flag;
5708 					goto _set_flag;
5709 				} else if (!strcmp(code, "settou_kouho")) {
5710 					/* ��Ƭ����� */
5711 					switch (s[0][0]) {
5712 					case 'h':
5713 					case 'H':
5714 						/* �Ҥ餬�ʡʤ���*/
5715 						vmask |= WNN_ENV_PREFIX_MASK;
5716 						henv.prefix_flag = WNN_KANA_KOUHO;
5717 						break;
5718 					case 'k':
5719 					case 'K':
5720 						/* �����ʸ��*/
5721 						vmask |= WNN_ENV_PREFIX_MASK;
5722 						henv.prefix_flag = WNN_KANJI_KOUHO;
5723 						break;
5724 					default:
5725 						break;
5726 					}
5727 					break;
5728 				} else if (strcmp(code, "setubi_gakusyu") == 0) {
5729 					/* ������ؽ� */
5730 					if (num < 2) goto _Err_happend;
5731 					vmask |= WNN_ENV_SUFFIX_LEARN_MASK;
5732 					flag = &henv.suffix_learn_flag;
5733 					goto _set_flag;
5734 					/*
5735 						 * (Jul. 12, 1994)
5736 						 * �ƣɴط������ƥ༭��ȣƣɴط��桼�����������
5737 						 */
5738 				} else if (strcmp(code, "set_fi_system_dic") == 0) {
5739 					if (local != REV_LOCAL){
5740 						char nul = 0;
5741 						int hrdonly;
5742 						/* �ե�����̾�� @, ~ ��Ÿ������ */
5743 						expand_expr_all(s[0], env);
5744 						if(num < 3 || !REAL_PARAM(s[1])){
5745 							s[1][0] = 0;
5746 						} else{
5747 							expand_expr_all(s[1], env);
5748 						}
5749 						/* �ƣɴط����٤� R_ONLY or R/W ���� */
5750 						hrdonly = (num >= 4 && REAL_PARAM(s[2]))? atoi(s[2]) : WNN_DIC_RDONLY;
5751 						/* �ƣɴط����٤Υѥ���ɥե����� */
5752 						if(num < 5 || !REAL_PARAM(s[3])) s[3][0] = 0;
5753 
5754 						switch (confirm_state) {
5755 						case CONFIRM:
5756 						case CONFIRM1:
5757 							error_handler1 = error_handler;
5758 							break;
5759 						case CREATE_WITHOUT_CONFIRM:
5760 							error_handler1 = (int (*)())WNN_CREATE;
5761 							break;
5762 						case NO_CREATE:
5763 							error_handler1 = (int (*)())WNN_NO_CREATE;
5764 							break;
5765 						}
5766 
5767 						if((jl_fi_dic_add_e_body(env, s[0], s[1],
5768 												 WNN_FI_SYSTEM_DICT,
5769 												 WNN_DIC_RDONLY,
5770 												 hrdonly, &nul, s[3],
5771 												 error_handler1, message_handler)
5772 							== -1) && (env_wnn_errorno_eql != 0)) {
5773 							if (env_wnn_errorno_eql != WNN_JSERVER_DEAD)
5774 								message_out(message_handler, "%s (%s) :%s\n",
5775 											s[0], s[1], wnn_perror());
5776 							else
5777 								message_out(message_handler, "%s\n",
5778 											wnn_perror());
5779 							goto _Err_happend;
5780 						}
5781 					}
5782 				} else if (!strcmp(code, "set_fi_user_dic")) {
5783 					if (local != REV_LOCAL){
5784 						int rdonly;
5785 						/* �ե�����̾�� @, ~ ��Ÿ������ */
5786 						expand_expr_all(s[0], env);
5787 						/* �ƣɴط������ R_ONLY or R/W ���� */
5788 						rdonly = (num >= 3 && REAL_PARAM(s[1]))? atoi(s[1]) : WNN_DIC_RDONLY;
5789 						/* �ƣɴط�����Υѥ���ɥե����� */
5790 						if(num < 4 || !REAL_PARAM(s[2])) s[2][0] = 0;
5791 
5792 						switch (confirm_state) {
5793 						case CONFIRM:
5794 						case CONFIRM1:
5795 							error_handler1 = error_handler;
5796 							break;
5797 						case CREATE_WITHOUT_CONFIRM:
5798 							error_handler1 = (int (*)())WNN_CREATE;
5799 							break;
5800 						case NO_CREATE:
5801 							error_handler1 = (int (*)())WNN_NO_CREATE;
5802 							break;
5803 						}
5804 
5805 						if((jl_fi_dic_add_e_body(env, s[0], NULL, WNN_FI_USER_DICT,
5806 												 rdonly, WNN_DIC_RDONLY, s[2], NULL,
5807 												 error_handler1, message_handler)
5808 							== -1) && (env_wnn_errorno_eql != 0)) {
5809 							if (env_wnn_errorno_eql != WNN_JSERVER_DEAD)
5810 								message_out(message_handler, "%s (%s) :%s\n",
5811 											s[0], s[1], wnn_perror());
5812 							else
5813 								message_out(message_handler, "%s\n",
5814 											wnn_perror());
5815 							goto _Err_happend;
5816 						}
5817 						henv.fi_relation_learn_flag = rdonly;
5818 						vmask |= WNN_ENV_FI_RELATION_LEARN_MASK;
5819 					}
5820 				} else if (!strcmp(code, "shiin_choka")) {
5821 					/* �����������Ҳ�Ķ�� */
5822 					if (num < 2) goto _Err_happend;
5823 					vmask |= WNN_ENV_SHIIN_CHOKA_MASK;
5824 					flag = &henv.shiin_choka_flag;
5825 					goto _set_flag;
5826 				}
5827 				break;
5828 			case 'u':
5829 				if (!strcmp(code, "use_hinsi") ||
5830 				    !strcmp(code, "unuse_hinsi")) {
5831 					/* �Ѵ����ѡ��Ի����ʻ� */
5832 					int ii, *hlist, nhinsi = num - 1;
5833 					w_char whname[64];
5834 					if(nhinsi) {
5835 						if(!(hlist = (int *)malloc(nhinsi * sizeof(int))))
5836 							goto _Err_happend;
5837 						for(ii = 0; ii < nhinsi; ii++) {
5838 							_Sstrcpy(whname, s[ii]);
5839 							if((hlist[ii] =
5840 							    jl_hinsi_number_e_body(env, whname)) == -1) {
5841 								free((char *)hlist);
5842 								goto _Err_happend;
5843 							}
5844 						}
5845 						if(strcmp(code, "unuse_hinsi") == 0) nhinsi *= -1;
5846 						if(js_set_henkan_hinsi(env, 1, nhinsi, hlist) < 0) {
5847 							free((char *)hlist);
5848 							goto _Err_happend;
5849 						}
5850 						free((char *)hlist);
5851 					}
5852 				}
5853 				break;
5854 			case 'y':
5855 				if (strcmp(code, "yuragi") == 0) {
5856 					/* Ĺ�����ɤ����� */
5857 					if (num < 2) goto _Err_happend;
5858 					vmask |= WNN_ENV_YURAGI_MASK;
5859 					flag = &henv.yuragi_flag;
5860 					goto _set_flag;
5861 				} else if (strcmp(code, "yosoku_use") == 0) {
5862 					/* ����ͽ¬�����Ի��� */
5863 					if (num < 2) goto _Err_happend;
5864 					vmask |= WNN_ENV_YOSOKU_USE_MASK;
5865 					flag = &henv.yosoku_use_flag;
5866 					goto _set_flag;
5867 				} else if (strcmp(code, "yosoku_learn") == 0) {
5868 					/* ����ͽ¬�ؽ� */
5869 					if (num < 2) goto _Err_happend;
5870 					vmask |= WNN_ENV_YOSOKU_LEARN_MASK;
5871 					flag = &henv.yosoku_learn_flag;
5872 					goto _set_flag;
5873 				} else if (strcmp(code, "yosoku_max_disp") == 0) {
5874 					/* ����ͽ¬����ɽ���� */
5875 					if (num < 2) goto _Err_happend;
5876 					if (atoi(s[0]) <= 0 || atoi(s[0]) > 10) goto _Err_happend;
5877 					vmask |= WNN_ENV_YOSOKU_MAX_DISP_MASK;
5878 					henv.yosoku_max_disp = atoi(s[0]);
5879 				} else if (strcmp(code, "yosoku_last_is_first") == 0) {
5880 					/* ����ͽ¬�ǽ�����ͥ�� */
5881 					if (num < 2) goto _Err_happend;
5882 					vmask |= WNN_ENV_YOSOKU_LAST_IS_FIRST_MASK;
5883 					flag = &henv.yosoku_last_is_first_flag;
5884 					goto _set_flag;
5885 				} else if (strcmp(code, "yosoku_realtime") == 0) {
5886 					/* ����ͽ¬�ꥢ�륿���� */
5887 					if (num < 2) goto _Err_happend;
5888 					vmask |= WNN_ENV_YOSOKU_REALTIME_MASK;
5889 					flag = &henv.yosoku_realtime_flag;
5890 					goto _set_flag;
5891 				}
5892 				break;
5893 			}
5894 			continue;
5895 _set_flag:
5896 			switch (s[0][0]) {
5897 			case 't':
5898 			case 'T':
5899 				*flag = True;
5900 				break;
5901 			case 'f':
5902 			case 'F':
5903 				*flag = False;
5904 				break;
5905 			default:
5906 				goto _Err_happend;
5907 			}
5908 		}
5909 	}
5910 	if(jl_rensou_unuse_hinsi_set(env) == -1) {
5911 		message_out(message_handler, msg_get(wnn_msg_cat, 103, NULL));
5912 		message_out(message_handler, msg_get(wnn_msg_cat, 212, NULL));
5913 		fclose(fp);
5914 		return(-1);
5915 	}
5916 	if(vmask) {
5917 		if(js_set_henkan_env(env, vmask, &henv) < 0) goto _Err_happend;
5918 	}
5919 	fclose(fp);
5920 	return(0);
5921 
5922 _Err_happend:
5923 
5924 	message_out(message_handler, "%s set Error!!\n", code);
5925 	message_out(message_handler,
5926 	    msg_get(wnn_msg_cat, 208, NULL),
5927 	    wnnrc_n);
5928 	/*
5929 			 * "�ե����� \"%s\" �ǴĶ�������ˡ����顼��ȯ����������ˡ�
5930 			 * �������ߤ��ޤ���\n",
5931 			 */
5932 
5933 	fclose(fp);
5934 	return(-1);
5935 }
5936 int
jl_set_env_wnnrc1(env,wnnrc_n,error_handler,message_handler,level)5937 jl_set_env_wnnrc1(env, wnnrc_n, error_handler, message_handler, level)
5938 register struct wnn_env *env;
5939 char *wnnrc_n;
5940 int  (*error_handler)(), (*message_handler)();
5941 int level;
5942 {
5943 	int x;
5944 
5945 	if(!env) return(-1);
5946 
5947 	env_wnn_errorno_set = 0;
5948 	x = jl_set_env_wnnrc1_body((WNN_ENV_INT *)env, wnnrc_n, error_handler, message_handler, level, 0);
5949 
5950 	return x;
5951 }
5952 
5953 int
jl_set_env_wnnrc_reverce(env,wnnrc_n,error_handler,message_handler,level)5954 jl_set_env_wnnrc_reverce(env, wnnrc_n, error_handler, message_handler, level)
5955 register struct wnn_env *env;
5956 char *wnnrc_n;
5957 int  (*error_handler)(), (*message_handler)();
5958 int level;
5959 {
5960 	int x;
5961 
5962 	if(!env) return(-1);
5963 
5964 	env_wnn_errorno_set = 0;
5965 	x = jl_set_env_wnnrc1_body((WNN_ENV_INT *)env, wnnrc_n, error_handler, message_handler, level, REV_LOCAL);
5966 
5967 	return x;
5968 }
5969 
5970 static int
expand_expr_all(s,env)5971 expand_expr_all(s, env)
5972 struct wnn_env_int *env;
5973 register char *s;
5974 {
5975 	register char *c;
5976 
5977 	for(c = s; *c; c++){
5978 		if(*c == '~' || *c == '@'){
5979 			if(expand_expr(c, env) == -1) return(-1);
5980 		}
5981 	}
5982 	return(0);
5983 }
5984 
5985 /* copy of js.c */
5986 static	char *
getlogname()5987 getlogname()
5988 {
5989 	extern struct passwd *getpwuid();
5990 	struct passwd *pw;
5991 
5992 	pw = getpwuid(getuid());
5993 	endpwent();
5994 	if (pw == NULL)
5995 		return NULL;
5996 	return pw->pw_name;
5997 }
5998 
5999 
6000 static int
expand_expr(s,env)6001 expand_expr(s, env)
6002 struct wnn_env_int *env;
6003 /**	~user��@HOME��@LIBDIR @ENV @USR @ETCDIR @VARDIR @SHAREDIR ��Ÿ��(â����ʸ�������Ƭ�Τ�)��
6004    �Ǥ��ʤ�����-1��
6005    �֤ꡢ���ξ��s����Ȥ��塹�Ȥ��Τޤ�ޡ�s��Ĺ����256�Ȳ��ꤷ�Ƥ롣*/
6006 register char	*s;
6007 {
6008 	char	*p, *s1;
6009 	char	tmp[MAXPATHLEN];
6010 	char    buf[MAXPATHLEN];
6011 	int	noerr, expandsuc;
6012 	struct	passwd	*u;
6013 	extern char *getenv();
6014 	extern struct	passwd	*getpwnam();
6015 
6016 	if(*s != '~' && *s != '@') return(0);
6017 	if((int)strlen(s) >= MAXPATHLEN) return(-1);
6018 
6019 	s1 = s;
6020 	if(NULL != (p = strchr(++s1, '/'))){
6021 		strcpy(tmp, p);
6022 		*p = '\0';
6023 	} else *tmp = '\0';
6024 	/* �����ޤǤϽ�����s����Ƭ��s1�ģ�ʸ���ܡ�p�ĺǽ��'/'�Τ��ä��Ȥ���
6025 	    �ʤ����ǰ�ö�ڤ�ˡ�tmp�Ĥ���ʸ�Υ��ԡ���*/
6026 
6027 	if(*s == '~'){
6028 		if(*s1){
6029 			u = getpwnam(s1);
6030 			endpwent();
6031 			noerr = expandsuc =
6032 			    (NULL != u &&
6033 			    (int)strlen(p = u -> pw_dir) + (int)strlen(tmp) <
6034 			    MAXPATHLEN );
6035 
6036 		} else {
6037 			noerr = expandsuc =
6038 			    (NULL != (p = getenv("HOME")) &&
6039 			    (int)strlen(p) + (int)strlen(tmp) < MAXPATHLEN);
6040 		}
6041 
6042 	} else { /* then, *s must be '@' */
6043 		if(!strcmp(s1, "HOME")){
6044 			noerr = expandsuc =
6045 			    (NULL != (p = getenv("HOME")) &&
6046 			    (int)strlen(p) + (int)strlen(tmp) < MAXPATHLEN);
6047 		} else if(!strcmp(s1, "WNN_DIC_DIR")){
6048 			noerr = expandsuc =
6049 			    (NULL != (p = getenv("HOME")) &&
6050 			    (int)strlen(p) + (int)strlen(tmp) < MAXPATHLEN);
6051 			if (expandsuc) {
6052 				strcpy(buf, p);
6053 				if (strlen(buf) + strlen("/") < sizeof(buf)) {
6054 					strcat(buf, "/");
6055 					p = getenv("WNN_DIC_DIR");
6056 					if (!p)
6057 						p = "Wnn";
6058 					if (strlen(buf) + strlen(p) < sizeof(buf)) {
6059 						strcat(buf, p);
6060 						p = buf;
6061 					} else
6062 						noerr = expandsuc = 0;
6063 				} else
6064 					noerr = expandsuc = 0;
6065 			}
6066 		} else if (!strcmp(s1, "LIBDIR")){
6067 			noerr = expandsuc =
6068 			    ((int)strlen(p= LIBDIR)+ (int)strlen(tmp) < MAXPATHLEN);
6069 		} else if (!strcmp(s1, "ENV")){  /* Added */
6070 			noerr = expandsuc =
6071 			    (NULL != (p = env_name(env)) &&
6072 			    (int)strlen(p)+ (int)strlen(tmp) < MAXPATHLEN);
6073 		} else if (!strcmp(s1, "USR")){
6074 			noerr = expandsuc =
6075 			    (NULL != (p = getlogname()) &&
6076 			    (int)strlen(p)+ (int)strlen(tmp) < MAXPATHLEN);
6077 		} else if (!strcmp(s1, "ETCDIR")){
6078 			noerr = expandsuc =
6079 			    ((int)strlen(p= ETCDIR)+ (int)strlen(tmp) < MAXPATHLEN);
6080 		} else if (!strcmp(s1, "VARDIR")){
6081 			noerr = expandsuc =
6082 			    ((int)strlen(p= VARDIR)+ (int)strlen(tmp) < MAXPATHLEN);
6083 		} else if (!strcmp(s1, "SHAREDIR")){
6084 			noerr = expandsuc =
6085 			    ((int)strlen(p= SHAREDIR)+ (int)strlen(tmp) < MAXPATHLEN);
6086 		} else { /* @HOME, @LIBDIR @ENV @ETCDIR @VARDIR @SHAREDIR igai ha kaenai */
6087 			noerr = 1;
6088 			expandsuc = 0;
6089 		}
6090 	}
6091 
6092 	if(expandsuc) strcpy(s, p);
6093 	strcat(s, tmp);
6094 	return(noerr ? 0 : -1);
6095 }
6096 
6097 static int
change_ascii_to_int(st,dp)6098 change_ascii_to_int(st,dp)
6099 register char *st;
6100 int *dp;
6101 {
6102 	register int total,flag;
6103 
6104 	total = 0;
6105 	flag = 0;
6106 	while(*st != NULL){
6107 		if (isdigit(*st)){
6108 			total = total * 10 + (*st - '0');
6109 		} else if (*st == '+') {
6110 			if (flag != 0) {
6111 				return(-1);
6112 			}
6113 			flag = 1;
6114 		} else if (*st == '-') {
6115 			if (flag != 0) {
6116 				return(-1);
6117 			}
6118 			flag = -1;
6119 		} else {
6120 			return(-1);
6121 		}
6122 		st++;
6123 	}
6124 	if (flag == 0){
6125 		flag = 1;
6126 	}
6127 	*dp = total * flag;
6128 	return(1);
6129 }
6130 
6131 static int
file_exist(env,n)6132 file_exist(env, n)
6133 struct wnn_env_int *env;
6134 char *n;
6135 {
6136 	if(n[0] == C_LOCAL){
6137 		return(access(n + 1, 4));
6138 	} else{
6139 		return(js_access(env,n,4));
6140 	}
6141 }
6142 
6143 static int
create_file(env,n,d,fid,pwd_dic,pwd_hindo,error_handler,message_handler)6144 create_file(env,n, d, fid, pwd_dic, pwd_hindo, error_handler, message_handler)
6145 register struct wnn_env_int *env;
6146 char *n;
6147 int d;
6148 int fid;
6149 char *pwd_dic, *pwd_hindo;
6150 int  (*error_handler)(), (*message_handler)();
6151 {
6152 	char pwd[WNN_PASSWD_LEN], hpwd[WNN_PASSWD_LEN];
6153 	int rev_dict_type;
6154 	int x;	/* result for creating file	(Jul. 7, 1994) */
6155 
6156 	if(
6157        make_dir_rec1(env, n, error_handler, message_handler) == -1){
6158 		env_wnn_errorno_set = WNN_MKDIR_FAIL;
6159 		return(-1);
6160 	}
6161 	if(d == HINDO || d == FI_HINDO){
6162 		/*
6163 			 * (Jul. 7, 1994)
6164 			 * �ƣɴط����٤κ����������ɲ�
6165 			 */
6166 		if(create_pwd_file(env, pwd_hindo, error_handler, message_handler) == -1)return(-1);
6167 		if(get_pwd(pwd_hindo, hpwd, env) == -1)return(-1);
6168 		if(n[0] == C_LOCAL){
6169 			/*
6170 				     * (Jul. 7, 1994)
6171 				     * ���饤�����¦�����٥ե�������������
6172 				     */
6173 			if(d == HINDO)
6174 				x = js_hindo_file_create_client(env, fid, n + 1, NULL, hpwd);
6175 				else
6176 				x = js_fi_hindo_file_create_client(env, fid, n + 1, NULL, hpwd);
6177 
6178 			if(x == -1){
6179 				message_out(message_handler, wnn_perror());
6180 				if_dead_disconnect(env);
6181 				return(-1);
6182 			} else{
6183 
6184 				message_out(message_handler,
6185 				    "%s \"%s\" %s",
6186 				    msg_get(wnn_msg_cat, 203, NULL),
6187 				    n,
6188 				    msg_get(wnn_msg_cat, 209, NULL));
6189 				/*
6190 							    "���٥ե����� \"%s\" ����ޤ�����",
6191 							    */
6192 
6193 				chown(n + 1, getuid(), -1); /* H.T. */
6194 				return(0);
6195 			}
6196 		} else{
6197 			/*
6198 			             * (Jul. 7, 1994)
6199 			             * ������¦�����٥ե�������������
6200 			             */
6201 			if(d == HINDO)
6202 				x = js_hindo_file_create(env, fid, n, NULL, hpwd);
6203 				else
6204 				x = js_fi_hindo_file_create(env, fid, n, NULL, hpwd);
6205 
6206 			if(x == -1){
6207 				message_out(message_handler, wnn_perror());
6208 				if_dead_disconnect(env);
6209 				return(-1);
6210 			} else{
6211 
6212 				message_out(message_handler,
6213 				    "%s \"%s\" %s",
6214 				    msg_get(wnn_msg_cat, 203, NULL),
6215 				    n,
6216 				    msg_get(wnn_msg_cat, 209, NULL));
6217 				/*
6218 							    "���٥ե����� \"%s\" ����ޤ�����",
6219 							    */
6220 
6221 				return(0);
6222 			}
6223 		}
6224 	} else {
6225 		if(create_pwd_file(env, pwd_hindo, error_handler, message_handler) == -1)return(-1);
6226 		if(get_pwd(pwd_hindo, hpwd, env) == -1)return(-1);
6227 		if(create_pwd_file(env, pwd_dic, error_handler, message_handler) == -1)return(-1);
6228 		if(get_pwd(pwd_dic, pwd, env) == -1)return(-1);
6229 
6230 		/*
6231 			 * (Jul. 7, 1994)
6232 			 * �ƣɴط�����κ����������ɲ�
6233 			 */
6234 		if(d == JISHO) {
6235 			/* (Dec. 3, 1994)
6236 				       dic_add ���� rw �ե饰�ˤ�ꡢ���롼�׼����ޡ��������
6237 				       ������Ԥ��褦�ˤ��� */
6238 			{
6239 				if(fid == WNN_DIC_GROUP)
6240 					rev_dict_type = WNN_GROUP_DICT;
6241 				else if(fid == WNN_DIC_MERGE)
6242 					rev_dict_type = WNN_MERGE_DICT;
6243 					else
6244 					rev_dict_type = WNN_REV_DICT;
6245 			}
6246 		} else
6247 			rev_dict_type = WNN_FI_USER_DICT;
6248 
6249 		if(n[0] == C_LOCAL){
6250 			if(js_dic_file_create_client(env, n + 1, rev_dict_type,
6251 			    NULL, pwd, hpwd) == -1){
6252 				message_out(message_handler, wnn_perror());
6253 				if_dead_disconnect(env);
6254 				return(-1);
6255 			} else{
6256 
6257 				message_out(message_handler,
6258 				    "%s \"%s\" %s",
6259 				    msg_get(wnn_msg_cat, 200, NULL),
6260 				    n,
6261 				    msg_get(wnn_msg_cat, 209, NULL));
6262 				/*
6263 							    "����ե����� \"%s\" ����ޤ�����",
6264 							    */
6265 
6266 				chown(n + 1, getuid(), -1);
6267 				return(0);
6268 			}
6269 		} else{
6270 			if(js_dic_file_create(env, n, rev_dict_type, NULL, pwd, hpwd)== -1){
6271 				message_out(message_handler, wnn_perror());
6272 				if_dead_disconnect(env);
6273 				return(-1);
6274 			} else{
6275 
6276 				message_out(message_handler,
6277 				    "%s \"%s\" %s",
6278 				    msg_get(wnn_msg_cat, 200, NULL),
6279 				    n,
6280 				    msg_get(wnn_msg_cat, 209, NULL));
6281 				/*
6282 							    "����ե����� \"%s\" ����ޤ�����",
6283 							    */
6284 
6285 				return(0);
6286 			}
6287 		}
6288 	}
6289 }
6290 
6291 static int
make_dir_rec1(env,path,error_handler,message_handler)6292 make_dir_rec1(env, path, error_handler, message_handler)
6293 struct wnn_env_int *env;
6294 register char *path;
6295 int  (*error_handler)(), (*message_handler)();
6296 {
6297 	char gomi[MAXPATHLEN];
6298 	register char *c;
6299 
6300 	for(c = path;*c;c++){
6301 		if(*c == '/'){
6302 			if (c - path > sizeof(gomi) - 1)
6303 				return(-1);
6304 			strncpy(gomi,path,c - path);
6305 			gomi[c - path] = 0;
6306 			if(make_dir1(env, gomi, error_handler, message_handler) == -1){
6307 				return(-1);
6308 			}
6309 		}
6310 	}
6311 	return(0);
6312 }
6313 
6314 static int
make_dir1(env,dirname,error_handler,message_handler)6315 make_dir1(env, dirname, error_handler, message_handler)
6316 register struct wnn_env_int *env;
6317 register char *dirname;
6318 int  (*error_handler)(), (*message_handler)();
6319 {
6320 	char gomi[128];
6321 	if(dirname[0] == C_LOCAL){
6322 		if(*(dirname + 1) == 0) return(0);
6323 		if(access(dirname + 1 , 0) == 0){ /* check for existence */
6324 			return(0); /* dir already exists */
6325 
6326 		}
6327 	} else{
6328 		if(*dirname == 0) return(0);
6329 		if(js_access(env, dirname , 0) == 0){ /* check for existence */
6330 			return(0); /* dir already exists */
6331 
6332 		}
6333 	}
6334 	if((int)error_handler != WNN_CREATE){
6335 
6336 		snprintf(gomi, sizeof(gomi), "%s \"%s\" %s%s",
6337 		    msg_get(wnn_msg_cat, 210, NULL),
6338 		    dirname,
6339 		    msg_get(wnn_msg_cat, 201, NULL),
6340 		    msg_get(wnn_msg_cat, 202, NULL));
6341 		/*
6342 				"directry \"%s\" ��̵���衣���?(Y/N)",
6343 				*/
6344 
6345 		if(call_error_handler(error_handler,gomi, env) == 0){
6346 			env_wnn_errorno_set = WNN_MKDIR_FAIL;
6347 			return(-1);
6348 		}
6349 	}
6350 	if(dirname[0] == C_LOCAL){  /* Create Directory */
6351 #define	MODE (0000000 | 0000700)
6352 		uid_t euid;
6353 		int ret;
6354 
6355 		euid = geteuid();
6356 		seteuid(getuid());
6357 		ret = mkdir(dirname + 1 , MODE );
6358 		seteuid(euid);
6359 		if (ret != 0 ) {
6360 			env_wnn_errorno_set=WNN_MKDIR_FAIL;
6361 			return(-1);
6362 		}
6363 	} else{
6364 		if(js_mkdir(env, dirname)){
6365 			if_dead_disconnect(env);
6366 			return(-1);
6367 		}
6368 	}
6369 	return(0);
6370 }
6371 
6372 
6373 static  int
6374 call_error_handler(error_handler, c, env)
6375 int (*error_handler)();
6376 char *c;
6377 ARGS *env;
6378 {
6379 	register int x;
6380 	x = error_handler(c);
6381 	if(confirm_state == CONFIRM1){
6382 		if(x) confirm_state = CREATE_WITHOUT_CONFIRM;
6383 		else confirm_state = NO_CREATE;
6384 	}
6385 	return(x);
6386 }
6387 
6388 static void
6389 message_out(message_handler, format, s1, s2, s3, s4, s5, s6, s7, s8)
6390 int (*message_handler)();
6391 char *format;
6392 char *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8;
6393 {
6394 	char buf[256];
6395 
6396 	if(message_handler){
6397 		snprintf(buf, sizeof(buf), format, s1, s2, s3, s4, s5, s6, s7, s8);
6398 		(*message_handler)(buf);
6399 	}
6400 }
6401 
6402 static int
jl_yomi_len_body(buf,bun_no,bun_no2)6403 jl_yomi_len_body(buf, bun_no, bun_no2)
6404 struct wnn_buf_mt *buf;
6405 register int bun_no, bun_no2;
6406 {
6407 	register int len = 0;
6408 
6409 	if(bun_no2 >= buf->orig.bun_suu || bun_no2 < 0)
6410 		bun_no2 = buf->orig.bun_suu;
6411 	for(;bun_no < bun_no2;bun_no++){
6412 		len += buf->orig.bun[bun_no]->yomilen;
6413 	}
6414 	return(len);
6415 }
6416 
6417 int
jl_yomi_len(buf,bun_no,bun_no2)6418 jl_yomi_len(buf, bun_no, bun_no2)
6419 struct wnn_buf *buf;
6420 register int bun_no, bun_no2;
6421 {
6422 	int x;
6423 
6424 	if(!buf) return(0);
6425 
6426 	buf_wnn_errorno_set = 0;
6427 	x = jl_yomi_len_body((WNN_BUF_MT *)buf, bun_no, bun_no2);
6428 
6429 	return x;
6430 }
6431 
6432 int
jl_kanji_len(buf,bun_no,bun_no2)6433 jl_kanji_len(buf, bun_no, bun_no2)
6434 struct wnn_buf *buf;
6435 register int bun_no, bun_no2;
6436 {
6437 	register int len = 0;
6438 
6439 	if(!buf) return(0);
6440 
6441 	buf_wnn_errorno_set = 0;
6442 	if(bun_no < 0) {
6443 
6444 		return(0);
6445 	}
6446 	if(bun_no2 >= buf->bun_suu || bun_no2 < 0)
6447 		bun_no2 = buf->bun_suu;
6448 	for(;bun_no < bun_no2;bun_no++){
6449 		len += buf->bun[bun_no]->kanjilen;
6450 	}
6451 
6452 	return(len);
6453 }
6454 
6455 int wnn_word_use_initial_hindo = 0;
6456 
6457 static int
jl_word_use_e_body(env,dic_no,entry)6458 jl_word_use_e_body(env, dic_no, entry)
6459 register struct wnn_env_int *env;
6460 int dic_no, entry;
6461 {
6462 	register struct wnn_jdata *jd;
6463 
6464 	if(js_word_info(env,dic_no,entry, &env_rb) == -1) {
6465 		if_dead_disconnect(env);
6466 		return(-1);
6467 	}
6468 	jd = (struct wnn_jdata *)(env_rb.buf);
6469 	if(jd->hindo != -1){
6470 		if(js_hindo_set(env, dic_no, entry,WNN_IMA_OFF, WNN_ENTRY_NO_USE) == -1) {
6471 			if_dead_disconnect(env);
6472 			return(-1);
6473 		}
6474 	} else{
6475 		if(js_hindo_set(env, dic_no, entry,
6476 		    (wnn_word_use_initial_hindo & 0x80) ?
6477 		    WNN_IMA_ON : WNN_IMA_OFF ,
6478 		    wnn_word_use_initial_hindo & 0x7f) == -1) {
6479 			if_dead_disconnect(env);
6480 			return(-1);
6481 		}
6482 	}
6483 	return(0);
6484 }
6485 
6486 int
jl_word_use_e(env,dic_no,entry)6487 jl_word_use_e(env, dic_no, entry)
6488 register struct wnn_env *env;
6489 int dic_no, entry;
6490 {
6491 	int x;
6492 
6493 	if(!env) return(-1);
6494 
6495 	env_wnn_errorno_set = 0;
6496 	x = jl_word_use_e_body((WNN_ENV_INT *)env, dic_no, entry);
6497 
6498 	return x;
6499 }
6500 
6501 int
jl_word_use(buf,dic_no,entry)6502 jl_word_use(buf, dic_no, entry)
6503 register struct wnn_buf *buf;
6504 int dic_no, entry;
6505 {
6506 	int x;
6507 
6508 	if(!buf || !(buf->env)) return(-1);
6509 
6510 
6511 	buf_wnn_errorno_set = 0;
6512 	x = jl_word_use_e_body((WNN_ENV_INT *)buf->env, dic_no, entry);
6513 
6514 	return x;
6515 }
6516 
6517 void
jl_env_set(buf,env)6518 jl_env_set(buf, env)
6519 register struct wnn_env *env;
6520 register struct wnn_buf *buf;
6521 {
6522 	if(!buf) return;
6523 
6524 	buf_wnn_errorno_set = 0;
6525 	buf->env = env;
6526 
6527 }
6528 
6529 
6530 struct wnn_env *
jl_env_get(buf)6531 jl_env_get(buf)
6532 register struct wnn_buf *buf;
6533 {
6534 	struct wnn_env *x;
6535 
6536 	if(!buf) return(NULL);
6537 
6538 	buf_wnn_errorno_set = 0;
6539 	x = buf->env;
6540 
6541 	return x;
6542 }
6543 
6544 static int
jl_param_set_e_body(env,para)6545 jl_param_set_e_body(env, para)
6546 register struct wnn_env_int *env;
6547 struct wnn_param *para;
6548 {
6549 	register int x;
6550 
6551 	if((x = js_param_set(env, para)) == -1) {
6552 		if_dead_disconnect(env);
6553 		return(-1);
6554 	}
6555 	return (x);
6556 }
6557 
6558 int
jl_param_set_e(env,para)6559 jl_param_set_e(env, para)
6560 register struct wnn_env *env;
6561 struct wnn_param *para;
6562 {
6563 	int x;
6564 
6565 	if(!env) return(-1);
6566 
6567 	env_wnn_errorno_set = 0;
6568 	x = jl_param_set_e_body((WNN_ENV_INT *)env, para);
6569 
6570 	return x;
6571 }
6572 
6573 int
jl_param_set(buf,para)6574 jl_param_set(buf, para)
6575 register struct wnn_buf *buf;
6576 struct wnn_param *para;
6577 {
6578 	int x;
6579 
6580 	if(!buf || !(buf->env)) return(-1);
6581 
6582 
6583 	buf_wnn_errorno_set = 0;
6584 	x = jl_param_set_e_body((WNN_ENV_INT *)buf->env, para);
6585 
6586 	return x;
6587 }
6588 
6589 static int
jl_set_henkan_env_e_body(env,valuemask,henv)6590 jl_set_henkan_env_e_body(env, valuemask, henv)
6591 register struct wnn_env_int *env;
6592 unsigned long valuemask;
6593 struct wnn_henkan_env *henv;
6594 {
6595 	register int x;
6596 
6597 	if((x = js_set_henkan_env(env, valuemask, henv)) == -1) {
6598 		if_dead_disconnect(env);
6599 		return(-1);
6600 	}
6601 	return (x);
6602 }
6603 
6604 int
jl_set_henkan_env_e(env,valuemask,henv)6605 jl_set_henkan_env_e(env, valuemask, henv)
6606 register struct wnn_env *env;
6607 unsigned long valuemask;
6608 struct wnn_henkan_env *henv;
6609 {
6610 	int x;
6611 
6612 	if(!env) return(-1);
6613 
6614 	env_wnn_errorno_set = 0;
6615 	x = jl_set_henkan_env_e_body((WNN_ENV_INT *)env, valuemask, henv);
6616 
6617 	return x;
6618 }
6619 
6620 int
jl_set_henkan_env(buf,valuemask,henv)6621 jl_set_henkan_env(buf, valuemask, henv)
6622 register struct wnn_buf *buf;
6623 unsigned long valuemask;
6624 struct wnn_henkan_env *henv;
6625 {
6626 	int x;
6627 
6628 	if(!buf || !(buf->env)) return(-1);
6629 
6630 
6631 	buf_wnn_errorno_set = 0;
6632 	x = jl_set_henkan_env_e_body((WNN_ENV_INT *)buf->env, valuemask, henv);
6633 
6634 	return x;
6635 }
6636 
6637 static int
jl_set_henkan_hinsi_e_body(env,mode,nhinsi,hname)6638 jl_set_henkan_hinsi_e_body(env, mode, nhinsi, hname)
6639 register struct wnn_env_int *env;
6640 int mode, nhinsi;
6641 char **hname;
6642 {
6643 	int x, i, hsize, *hno = NULL;
6644 	w_char tmp[32];
6645 
6646 	if(nhinsi) {
6647 		hsize = abs(nhinsi);
6648 		hno = (int *)malloc(hsize * sizeof(int));
6649 		for(i = 0; i < hsize; i++) {
6650 			_Sstrcpy(tmp, hname[i]);
6651 			if((hno[i] = jl_hinsi_number_e_body(env, tmp)) == -1) {
6652 				free((char *)hno);
6653 				return(-1);
6654 			}
6655 		}
6656 	}
6657 
6658 	if((x = js_set_henkan_hinsi(env, mode, nhinsi, hno)) == -1) {
6659 		if_dead_disconnect(env);
6660 		if(nhinsi) free((char *)hno);
6661 		return(-1);
6662 	}
6663 	if(nhinsi) free((char *)hno);
6664 	return (x);
6665 }
6666 
6667 int
jl_set_henkan_hinsi_e(env,mode,nhinsi,hname)6668 jl_set_henkan_hinsi_e(env, mode, nhinsi, hname)
6669 register struct wnn_env *env;
6670 int mode, nhinsi;
6671 char **hname;
6672 {
6673 	int x;
6674 
6675 	if(!env) return(-1);
6676 
6677 	env_wnn_errorno_set = 0;
6678 	x = jl_set_henkan_hinsi_e_body((WNN_ENV_INT *)env, mode, nhinsi, hname);
6679 
6680 	return x;
6681 }
6682 
6683 int
jl_set_henkan_hinsi(buf,mode,nhinsi,hname)6684 jl_set_henkan_hinsi(buf, mode, nhinsi, hname)
6685 register struct wnn_buf *buf;
6686 int mode, nhinsi;
6687 char **hname;
6688 {
6689 	int x;
6690 
6691 	if(!buf || !(buf->env)) return(-1);
6692 
6693 
6694 	buf_wnn_errorno_set = 0;
6695 	x = jl_set_henkan_hinsi_e_body((WNN_ENV_INT *)buf->env, mode, nhinsi, hname);
6696 
6697 	return x;
6698 }
6699 
6700 static int
jl_param_get_e_body(env,para)6701 jl_param_get_e_body(env, para)
6702 struct wnn_env_int *env;
6703 struct wnn_param *para;
6704 {
6705 	register int x;
6706 
6707 	if((x = js_param_get(env, para)) == -1) {
6708 		if_dead_disconnect(env);
6709 		return(-1);
6710 	}
6711 	return (x);
6712 }
6713 
6714 int
jl_param_get_e(env,para)6715 jl_param_get_e(env, para)
6716 struct wnn_env *env;
6717 struct wnn_param *para;
6718 {
6719 	int x;
6720 
6721 	if(!env) return(-1);
6722 
6723 	env_wnn_errorno_set = 0;
6724 	x = jl_param_get_e_body((WNN_ENV_INT *)env, para);
6725 
6726 	return x;
6727 }
6728 
6729 int
jl_param_get(buf,para)6730 jl_param_get(buf, para)
6731 register struct wnn_buf *buf;
6732 struct wnn_param *para;
6733 {
6734 	int x;
6735 
6736 	if(!buf || !(buf->env)) return(-1);
6737 
6738 
6739 	buf_wnn_errorno_set = 0;
6740 	x = jl_param_get_e_body((WNN_ENV_INT *)buf->env, para);
6741 
6742 	return x;
6743 }
6744 
6745 /*:::DOC_START
6746  *
6747  *    Function Name: jl_get_henkan_env_e_body
6748  *    Description  : ����������Ѵ��Ķ������륵�֥롼����
6749  *    Parameter    :
6750  *         env :   (In) �Ķ��ؤΥݥ���
6751  *         henv :  (Out) �Ѵ��Ķ���������ѹ�¤�ΤؤΥݥ���
6752  *	   local : (In) �Ѵ��Ķ��������оݥե饰
6753  *	  		��0 == jserver, else client��
6754  *
6755  *    Return value : 0==SUCCESS, -1==ERROR
6756  *
6757  *    Revision history:
6758  *
6759  *:::DOC_END
6760  */
6761 static int
jl_get_henkan_env_e_body(env,henv,local)6762 jl_get_henkan_env_e_body(env, henv, local)
6763 struct wnn_env_int *env;
6764 struct wnn_henkan_env *henv;
6765 int local;
6766 {
6767 	register int x;
6768 
6769 	if ((local && ((x = js_get_henkan_env_local(env, henv)) == -1)) ||
6770 	    (!local && ((x = js_get_henkan_env(env, henv)) == -1))) {
6771 		if_dead_disconnect(env);
6772 		return(-1);
6773 	}
6774 	return (x);
6775 }
6776 
6777 /*:::DOC_START
6778  *
6779  *    Function Name: jl_get_henkan_env_e
6780  *    Description  : ����������Ѵ��Ķ�������
6781  *    Parameter    :
6782  *         env :  (In) �Ķ��ؤΥݥ���
6783  *	   henv : (Out) �Ѵ��Ķ���������ѹ�¤�ΤؤΥݥ���
6784  *
6785  *    Return value : 0==SUCCESS, -1==ERROR
6786  *
6787  *    Revision history:
6788  *
6789  *:::DOC_END
6790  */
6791 int
jl_get_henkan_env_e(env,henv)6792 jl_get_henkan_env_e(env, henv)
6793 struct wnn_env *env;
6794 struct wnn_henkan_env *henv;
6795 {
6796 	int x;
6797 
6798 	if(!env) return(-1);
6799 
6800 	env_wnn_errorno_set = 0;
6801 	x = jl_get_henkan_env_e_body((WNN_ENV_INT *)env, henv, 0);
6802 
6803 	return x;
6804 } /* End of jl_get_henkan_env_e */
6805 
6806 /*:::DOC_START
6807  *
6808  *    Function Name: jl_get_henkan_env
6809  *    Description  : ����������Ѵ��Ķ�������
6810  *    Parameter    :
6811  *         buf :  (In) �Хåե��ؤΥݥ���
6812  *         henv : (Out) �Ѵ��Ķ���������ѹ�¤�ΤؤΥݥ���
6813  *
6814  *    Return value : 0==SUCCESS, -1==ERROR
6815  *
6816  *    Revision history:
6817  *
6818  *:::DOC_END
6819  */
6820 int
jl_get_henkan_env(buf,henv)6821 jl_get_henkan_env(buf, henv)
6822 register struct wnn_buf *buf;
6823 struct wnn_henkan_env *henv;
6824 {
6825 	int x;
6826 
6827 	if(!buf || !(buf->env)) return(-1);
6828 
6829 
6830 	buf_wnn_errorno_set = 0;
6831 	x = jl_get_henkan_env_e_body((WNN_ENV_INT *)buf->env, henv, 0);
6832 
6833 	return x;
6834 } /* End of jl_get_henkan_env */
6835 
6836 /*:::DOC_START
6837  *
6838  *    Function Name: jl_get_henkan_env_local_e
6839  *    Description  : �Ѵ��Ķ����⡤�饤�֥��ˤ����Τ���
6840  *                   ����������̡�����
6841  *    Parameter    :
6842  *         env :      (In) �Ķ��ؤΥݥ���
6843  *         henv :     (Out) �Ѵ��Ķ��ι�¤�ΤؤΥݥ���
6844  *
6845  *    Return value : 0==SUCCESS,-1==ERROR
6846  *
6847  *    Revision history:
6848  *
6849  *:::DOC_END
6850  */
6851 int
jl_get_henkan_env_local_e(env,henv)6852 jl_get_henkan_env_local_e(env, henv)
6853 struct wnn_env *env;
6854 struct wnn_henkan_env *henv;
6855 {
6856 	int x;
6857 
6858 	if(!env) return(-1);
6859 
6860 	env_wnn_errorno_set = 0;
6861 	x = jl_get_henkan_env_e_body((WNN_ENV_INT *)env, henv, 1);
6862 
6863 	return x;
6864 }
6865 
6866 /*:::DOC_START
6867  *
6868  *    Function Name: jl_get_henkan_env_local
6869  *    Description  : �Ѵ��Ķ����⡤�饤�֥��ˤ����Τ���
6870  *                   ����������̡�����
6871  *    Parameter    :
6872  *         buf :      (In) �Хåե��ؤΥݥ���
6873  *         henv :     (Out) �Ѵ��Ķ��ι�¤�ΤؤΥݥ���
6874  *
6875  *    Return value : 0==SUCCESS,-1==ERROR
6876  *
6877  *    Revision history:
6878  *
6879  *:::DOC_END
6880  */
6881 int
jl_get_henkan_env_local(buf,henv)6882 jl_get_henkan_env_local(buf, henv)
6883 register struct wnn_buf *buf;
6884 struct wnn_henkan_env *henv;
6885 {
6886 	int x;
6887 
6888 	if(!buf || !(buf->env)) return(-1);
6889 
6890 
6891 	buf_wnn_errorno_set = 0;
6892 	x = jl_get_henkan_env_e_body((WNN_ENV_INT *)buf->env, henv, 1);
6893 
6894 	return x;
6895 }
6896 
6897 /*:::DOC_START
6898  *
6899  *    Function Name: jl_get_henkan_hinsi_e_body
6900  *    Description  : �Ѵ��ˡʻ��ѡ��Ի��ѡˤ����ʻ췲�����륵�֥롼����
6901  *    Parameter    :
6902  *         env :    (In) �Ķ��ؤΥݥ���
6903  *         nhinsi : (Out) �����ʻ������ == �Ի���, �� ���ѡ�
6904  *         hlist :  (Out) �����ʻ�ꥹ�ȤؤΥݥ���
6905  *
6906  *    Return value : 0==SUCCESS, -1==ERROR
6907  *
6908  *    Revision history:
6909  *
6910  *:::DOC_END
6911  */
6912 static int
jl_get_henkan_hinsi_e_body(env,nhinsi,hlist)6913 jl_get_henkan_hinsi_e_body(env, nhinsi, hlist)
6914 struct wnn_env_int *env;
6915 int *nhinsi, **hlist;
6916 {
6917 	register int x;
6918 
6919 	if((x = js_get_henkan_hinsi(env, nhinsi, hlist)) == -1) {
6920 		if_dead_disconnect(env);
6921 		return(-1);
6922 	}
6923 	return (x);
6924 } /* End of jl_get_henkan_hinsi_e_body */
6925 
6926 /*:::DOC_START
6927  *
6928  *    Function Name: jl_get_henkan_hinsi_e
6929  *    Description  : �Ѵ��ˡʻ��ѡ��Ի��ѡˤ����ʻ췲������
6930  *    Parameter    :
6931  *         env :    (In) �Ķ��ؤΥݥ���
6932  *         nhinsi : (Out) �����ʻ������ == �Ի���, �� ���ѡ�
6933  *         hlist :  (Out) �����ʻ�ꥹ�ȤؤΥݥ���
6934  *
6935  *    Return value : 0==SUCCESS, -1==ERROR
6936  *
6937  *    Revision history:
6938  *
6939  *:::DOC_END
6940  */
6941 int
jl_get_henkan_hinsi_e(env,nhinsi,hlist)6942 jl_get_henkan_hinsi_e(env, nhinsi, hlist)
6943 struct wnn_env *env;
6944 int *nhinsi, **hlist;
6945 {
6946 	int x;
6947 
6948 	if(!env) return(-1);
6949 
6950 	env_wnn_errorno_set = 0;
6951 	x = jl_get_henkan_hinsi_e_body((WNN_ENV_INT *)env, nhinsi, hlist);
6952 
6953 	return x;
6954 } /* End of jl_get_henkan_hinsi_e */
6955 
6956 /*:::DOC_START
6957  *
6958  *    Function Name: jl_get_henkan_hinsi
6959  *    Description  : �Ѵ��ˡʻ��ѡ��Ի��ѡˤ����ʻ췲������
6960  *    Parameter    :
6961  *         env :    (In) �Хåե��ؤΥݥ���
6962  *         nhinsi : (Out) �����ʻ������ == �Ի���, �� ���ѡ�
6963  *         hlist :  (Out) �����ʻ�ꥹ�ȤؤΥݥ���
6964  *
6965  *    Return value : 0==SUCCESS, -1==ERROR
6966  *
6967  *    Revision history:
6968  *
6969  *:::DOC_END
6970  */
6971 int
jl_get_henkan_hinsi(buf,nhinsi,hlist)6972 jl_get_henkan_hinsi(buf, nhinsi, hlist)
6973 register struct wnn_buf *buf;
6974 int *nhinsi, **hlist;
6975 {
6976 	int x;
6977 
6978 	if(!buf || !(buf->env)) return(-1);
6979 
6980 
6981 	buf_wnn_errorno_set = 0;
6982 	x = jl_get_henkan_hinsi_e_body((WNN_ENV_INT *)buf->env, nhinsi, hlist);
6983 
6984 	return x;
6985 } /* End of jl_get_henkan_hinsi */
6986 
6987 static int
jl_dic_use_e_body(env,dic_no,flag)6988 jl_dic_use_e_body(env, dic_no, flag)
6989 struct wnn_env_int *env;
6990 int	dic_no,flag;
6991 {
6992 	register int x;
6993 
6994 	if((x = js_dic_use(env, dic_no, flag)) == -1) {
6995 		if_dead_disconnect(env);
6996 		return(-1);
6997 	}
6998 	return (x);
6999 }
7000 
7001 int
jl_dic_use_e(env,dic_no,flag)7002 jl_dic_use_e(env, dic_no, flag)
7003 struct wnn_env *env;
7004 int     dic_no,flag;
7005 {
7006 	int x;
7007 
7008 	if(!env) return(-1);
7009 
7010 	env_wnn_errorno_set = 0;
7011 	x = jl_dic_use_e_body((WNN_ENV_INT *)env, dic_no, flag);
7012 
7013 	return x;
7014 }
7015 
7016 int
jl_dic_use(buf,dic_no,flag)7017 jl_dic_use(buf, dic_no, flag)
7018 register struct wnn_buf *buf;
7019 int     dic_no,flag;
7020 {
7021 	int x;
7022 
7023 	if(!buf || !(buf->env)) return(-1);
7024 
7025 
7026 	buf_wnn_errorno_set = 0;
7027 	x = jl_dic_use_e_body((WNN_ENV_INT *)buf->env, dic_no, flag);
7028 
7029 	return x;
7030 }
7031 
7032 static int
jl_word_add_e_body(env,dic_no,yomi,kanji,comment,hinsi,init_hindo)7033 jl_word_add_e_body(env, dic_no, yomi, kanji, comment, hinsi, init_hindo)
7034 struct wnn_env_int *env;
7035 int	dic_no;
7036 w_char	*yomi,*kanji,*comment;
7037 int	hinsi,init_hindo;
7038 {
7039 	register int x;
7040 
7041 	if((x = js_word_add(env, dic_no, yomi, kanji, comment, hinsi, init_hindo)) == -1) {
7042 		if_dead_disconnect(env);
7043 		return(-1);
7044 	}
7045 	return (x);
7046 }
7047 
7048 int
jl_word_add_e(env,dic_no,yomi,kanji,comment,hinsi,init_hindo)7049 jl_word_add_e(env, dic_no, yomi, kanji, comment, hinsi, init_hindo)
7050 struct wnn_env *env;
7051 int     dic_no;
7052 w_char  *yomi,*kanji,*comment;
7053 int     hinsi,init_hindo;
7054 {
7055 	int x;
7056 
7057 	if(!env) return(-1);
7058 
7059 	env_wnn_errorno_set = 0;
7060 	x = jl_word_add_e_body((WNN_ENV_INT *)env, dic_no, yomi, kanji, comment, hinsi, init_hindo);
7061 
7062 	return x;
7063 }
7064 
7065 int
jl_word_add(buf,dic_no,yomi,kanji,comment,hinsi,init_hindo)7066 jl_word_add(buf, dic_no, yomi, kanji, comment, hinsi, init_hindo)
7067 register struct wnn_buf *buf;
7068 int     dic_no;
7069 w_char  *yomi,*kanji,*comment;
7070 int     hinsi,init_hindo;
7071 {
7072 	int x;
7073 
7074 	if(!buf || !(buf->env)) return(-1);
7075 
7076 
7077 	buf_wnn_errorno_set = 0;
7078 	x = jl_word_add_e_body((WNN_ENV_INT *)buf->env, dic_no, yomi, kanji,
7079 	    comment, hinsi, init_hindo);
7080 
7081 	return x;
7082 }
7083 
7084 static int
jl_word_delete_e_body(env,dic_no,entry)7085 jl_word_delete_e_body(env, dic_no, entry)
7086 struct wnn_env_int *env;
7087 int	dic_no;
7088 int	entry;
7089 {
7090 	register int x;
7091 
7092 	if((x = js_word_delete(env, dic_no, entry)) == -1) {
7093 		if_dead_disconnect(env);
7094 		return(-1);
7095 	}
7096 	return (x);
7097 }
7098 
7099 int
jl_word_delete_e(env,dic_no,entry)7100 jl_word_delete_e(env, dic_no, entry)
7101 struct wnn_env *env;
7102 int     dic_no;
7103 int     entry;
7104 {
7105 	int x;
7106 
7107 	if(!env) return(-1);
7108 
7109 	env_wnn_errorno_set = 0;
7110 	x = jl_word_delete_e_body((WNN_ENV_INT *)env, dic_no, entry);
7111 
7112 	return x;
7113 }
7114 
7115 int
jl_word_delete(buf,dic_no,entry)7116 jl_word_delete(buf, dic_no, entry)
7117 register struct wnn_buf *buf;
7118 int     dic_no;
7119 int     entry;
7120 {
7121 	int x;
7122 
7123 	if(!buf || !(buf->env)) return(-1);
7124 
7125 
7126 	buf_wnn_errorno_set = 0;
7127 	x = jl_word_delete_e_body((WNN_ENV_INT *)buf->env, dic_no, entry);
7128 
7129 	return x;
7130 }
7131 
7132 static int
file_read(env,fname)7133 file_read(env, fname)
7134 struct wnn_env_int *env;
7135 char *fname;
7136 {
7137 	register int fid;
7138 	if(fname[0] == C_LOCAL){
7139 		fid = js_file_send(env, fname + 1);
7140 	} else{
7141 		fid = js_file_read(env, fname);
7142 	}
7143 	if(fid >= 0){
7144 		add_file_to_env(env, fid, fname);
7145 	}
7146 	return(fid);
7147 }
7148 
7149 static int
file_remove(server,fname,pwd)7150 file_remove(server, fname, pwd)
7151 register WNN_JSERVER_ID *server;
7152 char *fname;
7153 char *pwd;
7154 {
7155 	if(fname[0] == C_LOCAL){
7156 		return(js_file_remove_client(server, fname + 1, pwd));
7157 	} else{
7158 		return(js_file_remove(server, fname, pwd));
7159 	}
7160 }
7161 
7162 
7163 static int
file_discard(env,fid)7164 file_discard(env, fid)
7165 register struct wnn_env_int *env;
7166 register int fid;
7167 {
7168 	delete_file_from_env(env, fid);
7169 	return(js_file_discard(env, fid));
7170 }
7171 
7172 static int
jl_hinsi_number_e_body(env,name)7173 jl_hinsi_number_e_body(env, name)
7174 register struct wnn_env_int *env;
7175 w_char *name;
7176 {
7177 	register int x;
7178 
7179 	if((x = js_hinsi_number(env->orig.js_id, name)) == -1) {
7180 		if_dead_disconnect(env);
7181 		return(-1);
7182 	}
7183 	return (x);
7184 }
7185 
7186 int
jl_hinsi_number_e(env,name)7187 jl_hinsi_number_e(env, name)
7188 register struct wnn_env *env;
7189 w_char *name;
7190 {
7191 	int x;
7192 
7193 	if(!env) return(-1);
7194 
7195 	env_wnn_errorno_set = 0;
7196 	x = jl_hinsi_number_e_body((WNN_ENV_INT *)env, name);
7197 
7198 	return x;
7199 }
7200 
7201 int
jl_hinsi_number(buf,name)7202 jl_hinsi_number(buf, name)
7203 register struct wnn_buf *buf;
7204 w_char *name;
7205 {
7206 	int x;
7207 
7208 	if(!buf || !(buf->env)) return(-1);
7209 
7210 
7211 	buf_wnn_errorno_set = 0;
7212 	x = jl_hinsi_number_e_body((WNN_ENV_INT *)buf->env, name);
7213 
7214 	return x;
7215 }
7216 
jl_hinsi_name_e_body(env,no)7217 static w_char *jl_hinsi_name_e_body(env, no)
7218 register struct wnn_env_int *env;
7219 register int no;
7220 {
7221 	w_char *x;
7222 
7223 	if(js_hinsi_name(env->orig.js_id, no, &env_rb) == -1) {
7224 		if_dead_disconnect(env);
7225 		return(NULL);
7226 	}
7227 	x = (w_char *)(env_rb.buf);
7228 	return x;
7229 }
7230 
jl_hinsi_name_e(env,no)7231 w_char *jl_hinsi_name_e(env, no)
7232 register struct wnn_env *env;
7233 register int no;
7234 {
7235 	w_char *x;
7236 
7237 	if(!env) return(NULL);
7238 
7239 	env_wnn_errorno_set = 0;
7240 	x = jl_hinsi_name_e_body((WNN_ENV_INT *)env, no);
7241 
7242 	return x;
7243 }
7244 
7245 w_char *
jl_hinsi_name(buf,no)7246 jl_hinsi_name(buf, no)
7247 register struct wnn_buf *buf;
7248 register int no;
7249 {
7250 	w_char *x;
7251 
7252 	if(!buf || !(buf->env)) return(NULL);
7253 
7254 
7255 	buf_wnn_errorno_set = 0;
7256 	x = jl_hinsi_name_e_body((WNN_ENV_INT *)buf->env, no);
7257 
7258 	return x;
7259 }
7260 
7261 static int
jl_hinsi_list_e_body(env,dic_no,name,area)7262 jl_hinsi_list_e_body(env, dic_no, name, area)
7263 register struct wnn_env_int *env;
7264 int dic_no;
7265 w_char *name;
7266 w_char ***area;
7267 {
7268 	int x;
7269 
7270 	if((x = js_hinsi_list(env, dic_no, name, &env_rb)) == -1) {
7271 		if_dead_disconnect(env);
7272 		return(-1);
7273 	}
7274 	*area = (w_char **)(env_rb.buf);
7275 	return(x);
7276 }
7277 
7278 int
jl_hinsi_list_e(env,dic_no,name,area)7279 jl_hinsi_list_e(env, dic_no, name, area)
7280 register struct wnn_env *env;
7281 int dic_no;
7282 w_char *name;
7283 w_char ***area;
7284 {
7285 	int x;
7286 
7287 	if(!env) return(-1);
7288 
7289 	env_wnn_errorno_set = 0;
7290 	x = jl_hinsi_list_e_body((WNN_ENV_INT *)env, dic_no, name, area);
7291 
7292 	return x;
7293 }
7294 
7295 int
jl_hinsi_list(buf,dic_no,name,area)7296 jl_hinsi_list(buf, dic_no, name, area)
7297 register struct wnn_buf *buf;
7298 int dic_no;
7299 w_char *name;
7300 w_char ***area;
7301 {
7302 	int x;
7303 
7304 	if(!buf || !(buf->env)) return(-1);
7305 
7306 
7307 	buf_wnn_errorno_set = 0;
7308 	x = jl_hinsi_list_e_body((WNN_ENV_INT *)buf->env, dic_no, name, area);
7309 
7310 	return x;
7311 }
7312 
7313 static int
jl_hinsi_dicts_e_body(env,no,area)7314 jl_hinsi_dicts_e_body(env, no, area)
7315 register struct wnn_env_int *env;
7316 int no;
7317 int **area;
7318 {
7319 	int x;
7320 
7321 	if((x = js_hinsi_dicts(env, no, &env_rb)) == -1) {
7322 		if_dead_disconnect(env);
7323 		return(-1);
7324 	}
7325 	*area = (int *)(env_rb.buf);
7326 	return(x);
7327 }
7328 
7329 int
jl_hinsi_dicts_e(env,no,area)7330 jl_hinsi_dicts_e(env, no, area)
7331 register struct wnn_env *env;
7332 int no;
7333 int **area;
7334 {
7335 	int x;
7336 
7337 	if(!env) return(-1);
7338 
7339 	env_wnn_errorno_set = 0;
7340 	x = jl_hinsi_dicts_e_body((WNN_ENV_INT *)env, no, area);
7341 
7342 	return x;
7343 }
7344 
7345 int
jl_hinsi_dicts(buf,no,area)7346 jl_hinsi_dicts(buf, no, area)
7347 register struct wnn_buf *buf;
7348 int no;
7349 int **area;
7350 {
7351 	int x;
7352 
7353 	if(!buf || !(buf->env)) return(-1);
7354 
7355 
7356 	buf_wnn_errorno_set = 0;
7357 	x = jl_hinsi_dicts_e_body((WNN_ENV_INT *)buf->env, no, area);
7358 
7359 	return x;
7360 }
7361 
7362 static int
jl_word_comment_set_e_body(env,dic_no,entry,comment)7363 jl_word_comment_set_e_body(env, dic_no, entry, comment)
7364 register struct wnn_env_int *env;
7365 int	dic_no,entry;
7366 w_char *comment;
7367 {
7368 	register int x;
7369 
7370 	if((x = js_word_comment_set(env, dic_no, entry, comment)) == -1) {
7371 		if_dead_disconnect(env);
7372 		return(-1);
7373 	}
7374 	return (x);
7375 }
7376 
7377 int
jl_word_comment_set_e(env,dic_no,entry,comment)7378 jl_word_comment_set_e(env, dic_no, entry, comment)
7379 register struct wnn_env *env;
7380 int     dic_no,entry;
7381 w_char *comment;
7382 {
7383 	int x;
7384 
7385 	if(!env) return(-1);
7386 
7387 	env_wnn_errorno_set = 0;
7388 	x = jl_word_comment_set_e_body((WNN_ENV_INT *)env, dic_no, entry, comment);
7389 
7390 	return x;
7391 }
7392 
7393 int
jl_word_comment_set(buf,dic_no,entry,comment)7394 jl_word_comment_set(buf, dic_no, entry, comment)
7395 register struct wnn_buf *buf;
7396 int     dic_no,entry;
7397 w_char *comment;
7398 {
7399 	int x;
7400 
7401 	if(!buf || !(buf->env)) return(-1);
7402 
7403 
7404 	buf_wnn_errorno_set = 0;
7405 	x = jl_word_comment_set_e_body((WNN_ENV_INT *)buf->env, dic_no, entry,
7406 	    comment);
7407 
7408 	return x;
7409 }
7410 
7411 static int
jl_dic_comment_set_e_body(env,dic_no,comment)7412 jl_dic_comment_set_e_body(env, dic_no, comment)
7413 register struct wnn_env_int *env;
7414 int dic_no;
7415 w_char *comment;
7416 {
7417 	register int x;
7418 	WNN_DIC_INFO dic;
7419 	WNN_FILE_INFO_STRUCT file;
7420 
7421 	if(js_dic_info(env,dic_no,&dic) < 0) {
7422 		if_dead_disconnect(env);
7423 		return(-1);
7424 	}
7425 	/*	dic Body	*/
7426 	if (js_file_info(env,dic.body,&file) < 0) {
7427 		if_dead_disconnect(env);
7428 		return(-1);
7429 	}
7430 	if((x = js_file_comment_set(env, file.fid, comment)) == -1) {
7431 		if_dead_disconnect(env);
7432 		return(-1);
7433 	}
7434 	return (x);
7435 }
7436 
7437 int
jl_dic_comment_set_e(env,dic_no,comment)7438 jl_dic_comment_set_e(env, dic_no, comment)
7439 register struct wnn_env *env;
7440 int dic_no;
7441 w_char *comment;
7442 {
7443 	int x;
7444 
7445 	if(!env) return(-1);
7446 
7447 	env_wnn_errorno_set = 0;
7448 	x = jl_dic_comment_set_e_body((WNN_ENV_INT *)env, dic_no, comment);
7449 
7450 	return x;
7451 }
7452 
7453 int
jl_dic_comment_set(buf,dic_no,comment)7454 jl_dic_comment_set(buf, dic_no, comment)
7455 register struct wnn_buf *buf;
7456 int dic_no;
7457 w_char *comment;
7458 {
7459 	int x;
7460 
7461 	if(!buf || !(buf->env)) return(-1);
7462 
7463 
7464 	buf_wnn_errorno_set = 0;
7465 	x = jl_dic_comment_set_e_body((WNN_ENV_INT *)buf->env, dic_no, comment);
7466 
7467 	return x;
7468 }
7469 
7470 
7471 int
jl_bun_suu(buf)7472 jl_bun_suu(buf)
7473 register struct wnn_buf *buf;
7474 {
7475 	int x;
7476 
7477 	if(!buf) return(0);
7478 
7479 	x = buf->bun_suu;
7480 
7481 	return x;
7482 }
7483 
7484 int
jl_zenkouho_suu(buf)7485 jl_zenkouho_suu(buf)
7486 register struct wnn_buf *buf;
7487 {
7488 	int x;
7489 
7490 	if(!buf) return(0);
7491 
7492 	/* Ϣ���Ѵ�  NTWnn ���ή�� */
7493 	/* Ϣ���Ѵ��ϡ�buf->zenkouho_suu ��Ȥ� */
7494 	if(buf->zenkouho_daip && buf->zenkouho_daip != RENSOU)
7495 		x = buf->zenkouho_dai_suu;
7496 		else
7497 		x = buf->zenkouho_suu;
7498 
7499 	return x;
7500 }
7501 
7502 int
jl_zenkouho_bun(buf)7503 jl_zenkouho_bun(buf)
7504 register struct wnn_buf *buf;
7505 {
7506 	int x;
7507 
7508 	if(!buf) return(0);
7509 
7510 	x = buf->zenkouho_bun;
7511 
7512 	return x;
7513 }
7514 
7515 int
jl_c_zenkouho(buf)7516 jl_c_zenkouho(buf)
7517 register struct wnn_buf *buf;
7518 {
7519 	int x;
7520 
7521 	if(!buf) return(0);
7522 
7523 	x = buf->c_zenkouho;
7524 
7525 	return x;
7526 }
7527 
7528 int
jl_zenkouho_daip(buf)7529 jl_zenkouho_daip(buf)
7530 register struct wnn_buf *buf;
7531 {
7532 	int x;
7533 
7534 	if(!buf) return(0);
7535 
7536 	x = buf->zenkouho_daip;
7537 
7538 	return x;
7539 }
7540 
7541 int
jl_dai_top(buf,k)7542 jl_dai_top(buf, k)
7543 register struct wnn_buf *buf;
7544 int	k;
7545 {
7546 	int x;
7547 
7548 	if(!buf) return(0);
7549 
7550 	x = buf->bun[k]->dai_top;
7551 
7552 	return x;
7553 }
7554 
7555 int
jl_jiri_len(buf,k)7556 jl_jiri_len(buf, k)
7557 register struct wnn_buf *buf;
7558 int	k;
7559 {
7560 	int x;
7561 
7562 	if(!buf) return(0);
7563 
7564 	x = buf->bun[k]->jirilen;
7565 
7566 	return x;
7567 }
7568 
7569 struct wnn_env *
jl_env(buf)7570 jl_env(buf)
7571 register struct wnn_buf *buf;
7572 {
7573 	struct wnn_env *x;
7574 
7575 	if(!buf) return(NULL);
7576 
7577 	x = buf->env;
7578 
7579 	return x;
7580 }
7581 
7582 int
jl_get_wnn_errorno_env(env)7583 jl_get_wnn_errorno_env(env)
7584 register struct wnn_env *env;
7585 {
7586 	int x;
7587 
7588 	if(!env) return(-1);
7589 
7590 	x = env_wnn_errorno_eql;
7591 
7592 	return x;
7593 }
7594 
7595 int
jl_get_wnn_errorno_buf(buf)7596 jl_get_wnn_errorno_buf(buf)
7597 register struct wnn_buf *buf;
7598 {
7599 	int x;
7600 
7601 	if(!buf) return(-1);
7602 
7603 	x = buf_wnn_errorno_eql;
7604 
7605 	return x;
7606 }
7607 
7608 struct wnn_jdata *
jl_inspect(buf,bun_no)7609 jl_inspect(buf, bun_no)
7610 register struct wnn_buf *buf;
7611 int bun_no;
7612 {
7613 	struct wnn_jdata *x;
7614 
7615 	if(!buf || !(buf->env)) return(NULL);
7616 
7617 
7618 	buf_wnn_errorno_set = 0;
7619 	x = jl_word_info_e_body((WNN_ENV_INT *)buf->env, buf->bun[bun_no]->dic_no,
7620 	    buf->bun[bun_no]->entry);
7621 
7622 	return x;
7623 }
7624 
7625 int
jl_env_sticky_e(env)7626 jl_env_sticky_e(env)
7627 register struct wnn_env *env;
7628 {
7629 	int x;
7630 
7631 	if(!env) return(-1);
7632 
7633 	env_wnn_errorno_set = 0;
7634 	x = js_env_sticky(env);
7635 
7636 	return x;
7637 }
7638 
7639 int
jl_env_sticky(buf)7640 jl_env_sticky(buf)
7641 register struct wnn_buf *buf;
7642 {
7643 	int x;
7644 
7645 	if(!buf || !(buf->env)) return(-1);
7646 
7647 
7648 	buf_wnn_errorno_set = 0;
7649 	if((x = jl_env_sticky_e((WNN_ENV_INT *)buf->env)) == -1)
7650 
7651 		return x;
7652 }
7653 
7654 int
jl_env_un_sticky_e(env)7655 jl_env_un_sticky_e(env)
7656 register struct wnn_env *env;
7657 {
7658 	int x;
7659 
7660 	if(!env) return(-1);
7661 
7662 	x = js_env_un_sticky(env);
7663 
7664 	return x;
7665 }
7666 
7667 int
jl_env_un_sticky(buf)7668 jl_env_un_sticky(buf)
7669 register struct wnn_buf *buf;
7670 {
7671 	int x;
7672 
7673 	if(!buf || !(buf->env)) return(-1);
7674 
7675 
7676 	buf_wnn_errorno_set = 0;
7677 	if((x = jl_env_un_sticky_e((WNN_ENV_INT *)buf->env)) == -1)
7678 
7679 		return x;
7680 }
7681 
7682 char *
jl_get_lang(buf)7683 jl_get_lang(buf)
7684 register struct wnn_buf *buf;
7685 {
7686 	char *x;
7687 
7688 	if(!buf || !(buf->env)) return(NULL);
7689 
7690 
7691 	buf_wnn_errorno_set = 0;
7692 	x = js_get_lang((WNN_ENV_INT *)buf->env);
7693 
7694 
7695 	return x;
7696 }
7697 
7698 static int
wnn_set_area_body(buf,bun_no,area,kanjip)7699 wnn_set_area_body(buf, bun_no, area, kanjip)
7700 struct wnn_buf_mt *buf;
7701 register int bun_no;
7702 w_char *area;
7703 int kanjip;
7704 {
7705 	register WNN_BUN *wb, *wb1;
7706 	w_char *c, *end, *area1 = area;
7707 	int len;
7708 
7709 	if ((kanjip != WNN_KANJI ) || (bun_no < 0) ||
7710 	    !(wb = buf->orig.bun[bun_no])) {
7711 		return(0);
7712 	}
7713 
7714 	for(wb1 = wb; ;){
7715 		if(wb1 != wb) c = (w_char *)wb1;
7716 		else c = wb1->yomi;
7717 		end = (w_char *)&wb1->next;
7718 		for(;c < end;){
7719 			if(!kanjip){
7720 				if((*c++ = *area++) == 0){
7721 					area--;
7722 					goto out;
7723 				}
7724 			} else{
7725 				if(*c++ == 0) kanjip--;
7726 			}
7727 		}
7728 		if (!*end) {
7729 			wb1->next = get_new_bun(buf);
7730 		}
7731 		wb1 = wb1->next;
7732 	}
7733 out:
7734 	wb1->next = NULL; 	/* 95/6/13 waya */
7735 	len = area - area1;
7736 	wb->kanjilen = wb->real_kanjilen = len;
7737 	wb->jirilen = wb->yomilen;
7738 	return 0;
7739 }
7740 
7741 int
wnn_set_area(buf,bun_no,area,kanjip)7742 wnn_set_area(buf, bun_no, area, kanjip)
7743 struct wnn_buf *buf;
7744 register int bun_no;
7745 w_char *area;
7746 int kanjip;
7747 {
7748 	int x;
7749 
7750 	if(!buf) return(0);
7751 
7752 	x = wnn_set_area_body((WNN_BUF_MT *)buf, bun_no, area, kanjip);
7753 
7754 	return x;
7755 }
7756 
7757 /* --------------- for ikeiji ---------- */
7758 extern int js_ikeiji_with_data();
7759 int jl_zenikeiji_dai_with_hinsi_name();
7760 
7761 /*:::DOC_START
7762  *
7763  *    Function Name: jl_zenikeiji_dai
7764  *    Description  :
7765  *         do ikeiji-henkan with some conditions
7766  *
7767  *    Parameter    :
7768  *         buf :      (InOut) kanji buffer
7769  *         bun_no :     (In) staring bun no.
7770  *         bun_no2 :     (In) ending bun no. (exclusive)
7771  *         use_maep :     (In)  connective info.
7772  *         uniq_level :     (In) unique level
7773  *
7774  *    Return value : no. of dai-bunsetsu
7775  *
7776  *    Revision history:
7777  *         20-Dec-94: initial release
7778  *
7779  *:::DOC_END
7780  */
7781 int
jl_zenikeiji_dai(buf,bun_no,bun_no2,use_maep,uniq_level)7782 jl_zenikeiji_dai(buf, bun_no, bun_no2, use_maep, uniq_level)
7783 register struct wnn_buf *buf;
7784 int bun_no, bun_no2, use_maep, uniq_level;
7785 {
7786 	int nhinsi = 1;
7787 	char hname[32];
7788 	char * p_hname = &hname[0];
7789 	int x;
7790 	strcpy(hname, "�۷���");
7791 	x = jl_zenikeiji_dai_with_hinsi_name(buf, bun_no, bun_no2, use_maep, uniq_level, nhinsi, &p_hname );
7792 	return x;
7793 }
7794 
7795 /*:::DOC_START
7796  *
7797  *    Function Name: zen_conv_dai_ikeiji1
7798  *    Description  :
7799  *         do ikeiji-henkan with some conditions
7800  *
7801  *    Parameter    :
7802  *         buf :      (InOut) kanji buffer
7803  *         bun_no :     (In) staring bun no.
7804  *         bun_no2 :     (In) ending bun no. (exclusive)
7805  *         use_maep :     (In)  connective info.
7806  *         uniq_level :     (In) unique level
7807  *         fuku :     (In) fukugou-go
7808  *         nhinsi :     (In) no. of hinsi
7809  *         hlist :     (In) hinsi-list
7810  *
7811  *    Return value : no. of dai-bunsetsu
7812  *
7813  *    Revision history:
7814  *         20-Dec-94: initial release
7815  *
7816  *:::DOC_END
7817  */
7818 static int
zen_conv_dai_ikeiji1(buf,bun_no,bun_no2,use_maep,uniq_level,fuku,nhinsi,hlist)7819 zen_conv_dai_ikeiji1(buf, bun_no, bun_no2, use_maep, uniq_level, fuku, nhinsi, hlist)
7820 register struct wnn_buf *buf;
7821 int bun_no, bun_no2, use_maep, uniq_level, fuku, nhinsi, *hlist;
7822 {
7823 	register struct wnn_buf_mt *buf_m = (WNN_BUF_MT *)buf;
7824 	int cnt;
7825 	w_char yomi[LENGTHBUNSETSU], yomi1[LENGTHBUNSETSU];
7826 	struct wnn_dai_bunsetsu *dp;
7827 	int tmp;
7828 	register int k;
7829 	int x;
7830 	int nobi_top;
7831 	w_char yomi_orig[LENGTHBUNSETSU];
7832 
7833 	if(bun_no2 > (tmp = dai_end(buf_m, bun_no)) ||
7834 	    bun_no2 < 0) bun_no2 = tmp;
7835 	jl_get_kanji_body(buf_m, bun_no, bun_no2, yomi, sizeof(yomi) / sizeof(w_char));
7836 	jl_get_yomi_body(buf_m, bun_no, bun_no2, yomi_orig, sizeof(yomi_orig) / sizeof(w_char));
7837 
7838 	if(bun_no == buf->zenkouho_bun && buf->zenkouho_daip == IKEIJI){
7839 		x = buf->c_zenkouho;
7840 		return x;
7841 	}
7842 	if (use_maep & WNN_USE_MAE && bun_no > 0) {
7843 		dumbhinsi = buf->bun[bun_no - 1]->hinsi;
7844 		jl_get_yomi_body(buf_m, bun_no - 1, bun_no, yomi1, sizeof(yomi1) / sizeof(w_char));
7845 		mae_fzk = yomi1 + buf->bun[bun_no - 1]->jirilen;
7846 	} else {
7847 		dumbhinsi = WNN_BUN_SENTOU;
7848 		mae_fzk = (w_char *)0;
7849 	}
7850 	if(use_maep & WNN_USE_ATO && bun_no2 < buf->bun_suu){
7851 		syuutanv = buf->bun[bun_no2]->kangovect;
7852 		syuutanv1 = WNN_VECT_KANZEN;
7853 		buf->zenkouho_endvect = syuutanv;
7854 	} else{
7855 		syuutanv = WNN_VECT_KANZEN;
7856 		syuutanv1 = WNN_VECT_NO;
7857 		if(bun_no2 < buf->bun_suu){
7858 			buf->bun[bun_no2]->dai_top = 1;
7859 		}
7860 		buf->zenkouho_endvect = -1;
7861 	}
7862 	if(!(buf->env)) return(-1);
7863 
7864 	if(fuku == 0 && nhinsi == 0) {
7865 		/* ?? error for this henkan */
7866 #if 0
7867 		if(buf->bun[bun_no]->fukugou == 0 && buf->bun[bun_no]->num_hinsi == 0) {
7868 			if((cnt = js_kanzen_dai(buf->env, yomi, dumbhinsi, mae_fzk,
7869 			    syuutanv, syuutanv1, &buf_rb)) < 0){
7870 				if_dead_disconnect_b(buf_m);
7871 
7872 				return(-1);
7873 			}
7874 		} else {
7875 			if((cnt = js_ikeiji_with_data(buf->env, buf->bun[bun_no]->fukugou,
7876 			    buf->bun[bun_no]->num_hinsi, buf->bun[bun_no]->hinsi_list,
7877 			    WNN_IKEIJI_DAI, yomi, dumbhinsi, mae_fzk, syuutanv,
7878 			    syuutanv1, WNN_VECT_BUNSETSU,
7879 			    /* need fugokugo-len, hinsi, etc */ buf->bun[bun_no], yomi_orig,
7880 			    &buf_rb)) < 0) {
7881 				if_dead_disconnect_b(buf_m);
7882 
7883 				return(-1);
7884 			}
7885 		}
7886 #else
7887 		if_dead_disconnect_b(buf_m);
7888 
7889 		return(-1);
7890 #endif /* 0 */
7891 	} else {
7892 		if((cnt = js_ikeiji_with_data(buf->env, fuku, nhinsi, hlist,
7893 		    WNN_IKEIJI_DAI, yomi, dumbhinsi, mae_fzk, syuutanv,
7894 		    syuutanv1, WNN_VECT_BUNSETSU,
7895 		    /* need fugokugo-len, hinsi, etc */ buf->bun[bun_no], yomi_orig,
7896 		    &buf_rb)) < 0) {
7897 			if_dead_disconnect_b(buf_m);
7898 
7899 			return(-1);
7900 		}
7901 	}
7902 
7903 	dp = (struct wnn_dai_bunsetsu *)buf_rb.buf;
7904 
7905 	free_zenkouho(buf_m);
7906 	/* Wander if it is OK, that is, only when all the
7907 			 * zenkouho's are got from zenkouho_dai, we need not move
7908 			 * the current dai-bunsetsu to the top of zenkouho's
7909 			 */
7910 	for(k = bun_no; k < bun_no2; k++){
7911 		if(buf->bun[k]->from_zenkouho != ZENKOUHO_IKEIJI_DAI)break;
7912 	}
7913 	nobi_top = buf->bun[k]->nobi_top;
7914 	if(k != bun_no2){		/* move the current to the top. */
7915 		make_space_for(buf_m, ZENKOUHO, buf->zenkouho_suu, buf->zenkouho_suu,
7916 		    bun_no2 - bun_no);
7917 		set_dai(&buf->bun[bun_no], &buf->zenkouho[0], bun_no2 - bun_no);
7918 		buf->zenkouho_dai[0] = 0;
7919 		buf->zenkouho_dai[1] = bun_no2 - bun_no;
7920 		buf->zenkouho_dai_suu = 1;
7921 		buf->zenkouho_suu = bun_no2 - bun_no;
7922 		k = get_c_jikouho_dai(dp, cnt, buf->bun, bun_no);
7923 		if(k >= 0){
7924 			buf->zenkouho[0]->dai_top =
7925 			    (dp[k].sbn->status == WNN_CONNECT)? 0:1;
7926 			buf->zenkouho[bun_no2-bun_no-1]->dai_end =
7927 			    (dp[k].sbn[dp[k].sbncnt-1].status_bkwd == WNN_CONNECT_BK)? 0:1;
7928 			/* KURI *//* USO*?*/
7929 		} else if (cnt == 0) {
7930 			/* �֡��פϸ������ 0 �ʤΤǡ�dai_top, dai_end ��
7931 			               ����Ū�� 1 �ˤ��� */
7932 			buf->zenkouho[0]->dai_top = 1;
7933 			buf->zenkouho[bun_no2-bun_no-1]->dai_end = 1;
7934 		}
7935 		if(uniq_level || k < 0){
7936 			insert_dai_or_ikeiji(buf_m, ZENKOUHO, -1, -1, dp, cnt, uniq_level, 0, 0, NULL, IKEIJI);
7937 		} else{
7938 			insert_dai_or_ikeiji(buf_m, ZENKOUHO, -1, -1, dp, k, uniq_level, 0, 0, NULL, IKEIJI);
7939 			insert_dai_or_ikeiji(buf_m, ZENKOUHO, -1, -1, dp + k + 1, cnt - k - 1,
7940 			    uniq_level, 0, 0, NULL, IKEIJI);
7941 		}
7942 		buf->c_zenkouho = 0;
7943 	} else{
7944 		insert_dai_or_ikeiji(buf_m, ZENKOUHO, -1, -1, dp, cnt, uniq_level, 0, 0, NULL, IKEIJI);
7945 		k = get_c_jikouho_from_zenkouho_dai(buf_m, buf->bun[bun_no]);
7946 		if(k < 0){
7947 			k = 0;	/* Only when the kouho has been removed from dict. */
7948 		}
7949 		buf->c_zenkouho = k;
7950 	}
7951 	buf->zenkouho_bun = bun_no;
7952 	buf->zenkouho_end_bun = bun_no2;
7953 	buf->zenkouho_daip = IKEIJI;
7954 	for(k = 0 ; k < buf->zenkouho_suu; k++){
7955 		if(buf->zenkouho[k]->ima && buf->zenkouho[k]->dic_no != -1){
7956 			add_down_bnst(buf_m, bun_no, buf->zenkouho[k]);
7957 		}
7958 		/*
7959 			 * ʸ�῭�Ф�/�̤��Ԥä��弡������ä����ˤϡ��������ʸ�����
7960 			 * �ˤ�ʸ�῭�Ф�/�̤�ξ����Ĥ��Ƥ�����ʸ���ڤ�ؽ��ǻ��Ѥ��롣
7961 			 */
7962 		if (nobi_top) buf->zenkouho[k]->nobi_top = 1;
7963 	}
7964 	x = buf->c_zenkouho;
7965 
7966 	return x;
7967 }
7968 
7969 /*:::DOC_START
7970  *
7971  *    Function Name: jl_zenikeiji_dai_with_hinsi_name
7972  *    Description  :
7973  *         do ikeiji-henkan with some conditions
7974  *
7975  *    Parameter    :
7976  *         buf :      (InOut) kanji buffer
7977  *         bun_no :     (In) staring bun no.
7978  *         bun_no2 :     (In) ending bun no. (exclusive)
7979  *         use_maep :     (In)  connective info.
7980  *         uniq_level :     (In) unique level
7981  *         nhinsi :     (In) no. of hinsi-name
7982  *         hname :     (In) hinsi name-list
7983  *
7984  *    Return value : no. of dai-bunsetsu
7985  *
7986  *    Revision history:
7987  *         20-Dec-94: initial release
7988  *
7989  *:::DOC_END
7990  */
7991 int
jl_zenikeiji_dai_with_hinsi_name(buf,bun_no,bun_no2,use_maep,uniq_level,nhinsi,hname)7992 jl_zenikeiji_dai_with_hinsi_name(buf, bun_no, bun_no2, use_maep, uniq_level, nhinsi, hname)
7993 register struct wnn_buf *buf;
7994 int bun_no, bun_no2, use_maep, uniq_level, nhinsi;
7995 char **hname;
7996 {
7997 	int x, i, hsize, *hno = NULL;
7998 	w_char tmp[64];
7999 
8000 	if(!buf) return(-1);
8001 
8002 	buf_wnn_errorno_set = 0;
8003 	/*    if(strncmp(js_get_lang(buf->env), WNN_J_LANG, 5) || nhinsi == 0) {
8004 
8005 	        return(-1);
8006 		} */
8007 	if(nhinsi){
8008 		hsize = abs(nhinsi);
8009 		hno = (int *)malloc(hsize * sizeof(int));
8010 		for(i = 0; i < hsize; i++) {
8011 			_Sstrcpy(tmp, hname[i]);
8012 			if((hno[i] = jl_hinsi_number_e(buf->env, tmp)) == -1) {
8013 				free((char *)hno);
8014 
8015 				return(-1);
8016 			}
8017 		}
8018 	}
8019 	x = zen_conv_dai_ikeiji1(buf, bun_no, bun_no2, use_maep, uniq_level, 0, nhinsi, hno);
8020 	if(nhinsi) free((char *)hno);
8021 
8022 	return x;
8023 }
8024 /* end of jl_zenikeiji_dai_with_hinsi_name */
8025 
8026 /*:::DOC_START
8027  *
8028  *    Function Name: insert_dai_or_ikeiji
8029  *    Description  :
8030  *         insert dai-bunsetsu in to kanji-buffer
8031  *
8032  *    Parameter    :
8033  *         buf :      (InOut) kanji buffer
8034  *         zenp :     (In) zen-kouho type.
8035  *         bun_no :     (In) staring bun no.
8036  *         bun_no2 :     (In) ending bun no. (exclusive)
8037  *         dp :     (In)  dai-bunsetsu
8038  *         dcnt :     (In)  no. of dai-bunsetsu
8039  *         uniq_level :     (In) unique level
8040  *         fuku :     (In)  fukugou-go
8041  *         nhinsi :     (In)  no. of hinsi
8042  *         hlist :     (In)  hinsi list
8043  *         daip :     (In)  henkan type
8044  *
8045  *    Return value : no. of dai-bunsetsu
8046  *
8047  *    Revision history:
8048  *         20-Dec-94: initial release
8049  *
8050  *:::DOC_END
8051  */
8052 /* from insert_dai */
8053 /* for zenkouho, assume bun_no = bun_no2 = zenkouho_suu */
8054 static int
insert_dai_or_ikeiji(buf,zenp,bun_no,bun_no2,dp,dcnt,uniq_level,fuku,nhinsi,hlist,daip)8055 insert_dai_or_ikeiji(buf, zenp, bun_no, bun_no2, dp, dcnt, uniq_level, fuku, nhinsi, hlist, daip)
8056 struct wnn_buf_mt *buf;
8057 int bun_no, bun_no2;
8058 struct wnn_dai_bunsetsu *dp;
8059 int dcnt;
8060 int zenp;
8061 int uniq_level;
8062 int fuku, nhinsi, *hlist;
8063 int daip;
8064 {
8065 	register WNN_BUN **b, **b0;
8066 	register int k, l, m;
8067 	register int cnt = 0;
8068 	struct wnn_sho_bunsetsu *sp, *sp1;
8069 
8070 	if(bun_no == -1){
8071 		bun_no = bun_no2 = (zenp == BUN)? buf->orig.bun_suu: buf->orig.zenkouho_suu;
8072 	}
8073 
8074 	for(k = 0; k < dcnt ; k++){
8075 		cnt += dp[k].sbncnt;
8076 	}
8077 	make_space_for(buf, zenp, bun_no, bun_no2, cnt);
8078 	/* zenkouho_dai_suu must not be initialized */
8079 
8080 	b = ((zenp == BUN)? buf->orig.bun: buf->orig.zenkouho) + bun_no;
8081 
8082 	for(k = 0, m = buf->orig.zenkouho_dai_suu ; k < dcnt; k++){
8083 		/* �۷����Ѵ��κݤϡ�find_same_kouho_dai() ���ơ�
8084 			   ������ꥹ�ȤΥ��֥���ɤ� */
8085 		if(uniq_level){
8086 			if(find_same_kouho_dai(&dp[k], buf, m, uniq_level))
8087 				continue;
8088 		}
8089 		sp = dp[k].sbn;
8090 		if(zenp == ZENKOUHO){
8091 			buf->orig.zenkouho_dai[m++] = b - buf->orig.zenkouho;
8092 		}
8093 		b0 = b;
8094 		sp1 = sp;
8095 		for(l = 0 ; l < dp[k].sbncnt; l++){
8096 			*b = get_sho(buf, sp, zenp, daip, fuku, nhinsi, hlist);
8097 			if(zenp == ZENKOUHO){
8098 				if (l == dp[k].sbncnt -1){
8099 					if(buf->orig.zenkouho_endvect != -1){
8100 						(*b)->dai_end = (sp->status_bkwd == WNN_CONNECT_BK)? 0:1;
8101 					} else{
8102 						(*b)->dai_end = 0;
8103 					}
8104 				} else{
8105 					(*b)->dai_end = 0;
8106 				}
8107 			}
8108 			b++;
8109 			sp++;
8110 		}
8111 		(*b0)->dai_top = (sp1->status == WNN_CONNECT)? 0:1;
8112 		(*b0)->daihyoka = dp[k].hyoka;
8113 	}
8114 	if(zenp == ZENKOUHO){
8115 		buf->orig.zenkouho_dai[m] = b - buf->orig.zenkouho;
8116 		buf->orig.zenkouho_suu = b - buf->orig.zenkouho;
8117 		buf->orig.zenkouho_dai_suu = m;
8118 	}
8119 	return(cnt + bun_no);
8120 }
8121 
8122 
8123 /*:::DOC_START
8124  *
8125  *    Function Name: jl_set_ikeiji_dai
8126  *    Description  :
8127  *         set current kouho
8128  *
8129  *    Parameter    :
8130  *         buf :      (InOut) kanji buffer
8131  *         offset :     (In) target bun no.
8132  *
8133  *    Return value : current bun no.
8134  *
8135  *    Revision history:
8136  *         20-Dec-94: initial release
8137  *
8138  *:::DOC_END
8139  */
8140 /* ?? need, identical jl_set_jikouho_dai */
8141 int
jl_set_ikeiji_dai(buf,offset)8142 jl_set_ikeiji_dai(buf, offset)
8143 register struct wnn_buf *buf;
8144 int offset;
8145 {
8146 	register int st, end, bun, k;
8147 
8148 	if(!buf) return(-1);
8149 
8150 	buf_wnn_errorno_set = 0;
8151 	if(buf->zenkouho_suu <= 0) {
8152 
8153 		return(-1);
8154 	}
8155 	if(buf->zenkouho_daip == SHO){
8156 
8157 		return(-1);
8158 	}
8159 	offset = (offset + buf->zenkouho_dai_suu) % buf->zenkouho_dai_suu;
8160 	if(buf->zenkouho_end_bun < buf->bun_suu && buf->zenkouho_endvect != -1)
8161 		buf->bun[buf->zenkouho_end_bun]->dai_top =
8162 		    buf->zenkouho[buf->zenkouho_dai[offset+1]-1]->dai_end;
8163 	free_bun((WNN_BUF_MT *)buf, buf->zenkouho_bun, buf->zenkouho_end_bun);
8164 	st = buf->zenkouho_dai[offset];
8165 	end = buf->zenkouho_dai[offset + 1];
8166 	make_space_for((WNN_BUF_MT *)buf, BUN, buf->zenkouho_bun,
8167 	    buf->zenkouho_end_bun, end - st);
8168 	for(bun = buf->zenkouho_bun, k = st; k < end;){
8169 		set_sho(buf->zenkouho[k++], &buf->bun[bun++]);
8170 	}
8171 	buf->zenkouho_end_bun = buf->zenkouho_bun + end - st;
8172 	buf->c_zenkouho = offset;
8173 	return(offset);
8174 }
8175 
8176 /*:::DOC_START
8177  *
8178  *    Function Name: jl_yosoku_init
8179  *    Description  : ������ͽ¬��ͽ¬����������
8180  *    Parameter    :
8181  *         buf :       (InOut) �Хåե��ؤΥݥ���
8182  *
8183  *    Return value : -1==ERROR  0�����ェλ
8184  *
8185  *    Revision history:
8186  *
8187  *:::DOC_END
8188  */
8189 int
jl_yosoku_init(buf)8190 jl_yosoku_init(buf)
8191 struct wnn_buf *buf;
8192 {
8193 	if(!buf || !(buf->env)) return -1;
8194 	buf_wnn_errorno_set = 0;
8195 
8196 	/* ͽ¬���������� */
8197 	if (js_yosoku_init(buf->env) < 0)
8198 		return -1;
8199 
8200 	/* ����ͽ¬����ϥ��饤����ȹ�¤���������˽���������Τ�
8201 	   ����Ū�ʽ���������ס����ӥꥻ�åȤʤɤν�����Ԥ����ϰʲ���
8202 	   API ��Ƥ� */
8203 /*
8204 	 ͽ¬�������ϻ��־�������
8205 	if (js_yosoku_init_time_keydata(buf->env) < 0)
8206 		return -1;
8207 
8208 	ͽ¬�������ϻ��֤˴�Ϣ�����ѿ�������
8209 	if (js_yosoku_init_inputinfo(buf->env) < 0)
8210 		return -1;
8211 */
8212 
8213 	return 0;
8214 }
8215 
8216 /*:::DOC_START
8217  *
8218  *    Function Name: jl_yosoku_set_param
8219  *    Description  : ������ͽ¬�ϴĶ�����������
8220  *    Parameter    :
8221  *         buf                : (InOut) �Хåե��ؤΥݥ���
8222  *         learn_flag         : (In)    ͽ¬�ؽ�����(=1)  ���ʤ�(=0)
8223  *         max_disp           : (In)    ͽ¬�������ɽ���� (1��10)
8224  *         last_is_first_flag : (In)    �ǽ�����ͥ�褹��(=1) ���ʤ�(=0)
8225  *
8226  *    Return value : -1==ERROR  0�����ェλ
8227  *
8228  *    Revision history:
8229  *
8230  *:::DOC_END
8231  */
8232 int
jl_yosoku_set_param(buf,learn_flag,max_disp,last_is_first_flag)8233 jl_yosoku_set_param(buf, learn_flag, max_disp, last_is_first_flag)
8234 struct wnn_buf *buf;
8235 int learn_flag;
8236 int max_disp;
8237 int last_is_first_flag;
8238 {
8239 	if(!buf || !(buf->env)) return -1;
8240 	buf_wnn_errorno_set = 0;
8241 
8242 	/* ͽ¬���������� */
8243 	if (js_yosoku_set_param(buf->env, learn_flag, max_disp,
8244 							last_is_first_flag) < 0)
8245 		return -1;
8246 
8247 	return 0;
8248 }
8249 
8250 /*:::DOC_START
8251  *
8252  *    Function Name: jl_yosoku_free
8253  *    Description  : ������ͽ¬��ͽ¬������λ����
8254  *    Parameter    :
8255  *         buf :       (InOut) �Хåե��ؤΥݥ���
8256  *
8257  *    Return value : -1==ERROR  0�����ェλ
8258  *
8259  *    Revision history:
8260  *
8261  *:::DOC_END
8262  */
8263 int
jl_yosoku_free(buf)8264 jl_yosoku_free(buf)
8265 struct wnn_buf *buf;
8266 {
8267 	if(!buf || !(buf->env)) return -1;
8268 	buf_wnn_errorno_set = 0;
8269 
8270 	/* ͽ¬���䤬�Ĥä��ޤޤǤ���в������� */
8271 	js_yosoku_kouho_free();
8272 
8273 	/* ͽ¬������λ */
8274 	if (js_yosoku_free(buf->env) < 0)
8275 		return -1;
8276 
8277 	return 0;
8278 }
8279 
8280 /*:::DOC_START
8281  *
8282  *    Function Name: jl_yosoku_yosoku
8283  *    Description  : ������ͽ¬��ͽ¬����
8284  *    Parameter    :
8285  *         buf :       (InOut) �Хåե��ؤΥݥ���
8286  *         str :       (In) ͽ¬ʸ����
8287  *
8288  *    Return value : -1==ERROR  0�����ェλ
8289  *
8290  *    Revision history:
8291  *
8292  *:::DOC_END
8293  */
8294 int
jl_yosoku_yosoku(buf,str)8295 jl_yosoku_yosoku(buf, str)
8296 struct wnn_buf *buf;
8297 char *str;
8298 {
8299 	if(!buf || !(buf->env)) return -1;
8300 	buf_wnn_errorno_set = 0;
8301 
8302 	if (js_yosoku_yosoku(buf->env, str) < 0)
8303 		return -1;
8304 
8305 	return 0;
8306 }
8307 
8308 /*:::DOC_START
8309  *
8310  *    Function Name: jl_yosoku_toroku
8311  *    Description  : ������ͽ¬����Ͽ����
8312  *    Parameter    :
8313  *         buf :       (InOut) �Хåե��ؤΥݥ���
8314  *         keybuf :    (In) ��Ͽʸ����
8315  *         selectpos : (In) �������
8316  *
8317  *    Return value : -1==ERROR  0�����ェλ
8318  *
8319  *    Revision history:
8320  *
8321  *:::DOC_END
8322  */
8323 int
jl_yosoku_toroku(buf,keybuf,keylen)8324 jl_yosoku_toroku(buf, keybuf, keylen)
8325 struct wnn_buf *buf;
8326 w_char *keybuf;
8327 short keylen;
8328 {
8329 	int bun_num, tmp_num;
8330 	struct wnn_yosoku_bunsetsu *yk_bunsetsu;
8331 	int i, j, ret, bunlen = 0;
8332 	w_char yomi[LENGTHYOMI];
8333 	w_char kanji[LENGTHKANJI];
8334 	char tmpyomikanji[LENGTHYOMI * 2 + 1];
8335 
8336 	if(!buf || !(buf->env)) return -1;
8337 	buf_wnn_errorno_set = 0;
8338 
8339 	/* ʸ��� */
8340 	bun_num = buf->bun_suu;
8341 
8342 	if (bun_num == 0) { /* �ɤߤΤޤ޳���(mode=1 insert_mode) �ξ�� */
8343 		yk_bunsetsu = (struct wnn_yosoku_bunsetsu *)calloc(sizeof(struct wnn_yosoku_bunsetsu), sizeof(char));
8344 		if (yk_bunsetsu == NULL) {
8345 			buf_wnn_errorno_set = WNN_ALLOC_FAIL;
8346 			return -1;
8347 		}
8348 		yk_bunsetsu[0].hinsi = 0;
8349 		memset(yomi, 0x0, sizeof(yomi));
8350 		wnn_Strncpy(yomi, keybuf, (int)keylen);
8351 		_sStrcpy(yk_bunsetsu[0].yomi, yomi);
8352 		_sStrcpy(yk_bunsetsu[0].kanji, yomi);
8353 		yk_bunsetsu[0].jirilen = strlen(yk_bunsetsu[0].yomi);
8354 		yk_bunsetsu[0].real_kanjilen = strlen(yk_bunsetsu[0].kanji);
8355 		bun_num = 1;
8356 	} else { /* �Ѵ������(ʸ���������)��� */
8357 		/* ��ʸ��ǥ������ */
8358 		tmp_num = bun_num;
8359 		for(i = 0; i < tmp_num; i++) {
8360 			if (buf->bun[i]->dai_top != 1)
8361 				bun_num--;
8362 		}
8363 		yk_bunsetsu = (struct wnn_yosoku_bunsetsu *)calloc(bun_num * sizeof(struct wnn_yosoku_bunsetsu), sizeof(char));
8364 		if (yk_bunsetsu == NULL) {
8365 			buf_wnn_errorno_set = WNN_ALLOC_FAIL;
8366 			return -1;
8367 		}
8368 		/* ��ʸ��ñ�̤� yk_bunsetsu ��������� */
8369 		for(i = 0, j = 0; j < tmp_num; i++,j++) {
8370 			if (buf->bun[j]->dai_top == 0) {
8371 				while (j < tmp_num && buf->bun[j]->dai_top == 0) {
8372 					wnn_area(buf->bun[j], yomi, WNN_YOMI, sizeof(yomi) / sizeof(w_char));
8373 					_sStrcpy(tmpyomikanji, yomi);
8374 					strcat(yk_bunsetsu[i-1].yomi, tmpyomikanji);
8375 					wnn_area(buf->bun[j], kanji, WNN_KANJI, sizeof(kanji) / sizeof(w_char));
8376 					_sStrcpy(tmpyomikanji, kanji);
8377 					strcat(yk_bunsetsu[i-1].kanji, tmpyomikanji);
8378 					j++;
8379 				}
8380 				yk_bunsetsu[i-1].jirilen = strlen(yk_bunsetsu[i-1].yomi);
8381 				yk_bunsetsu[i-1].real_kanjilen = strlen(yk_bunsetsu[i-1].kanji);
8382 				j--; i--;
8383 			} else {
8384 				yk_bunsetsu[i].hinsi = buf->bun[j]->hinsi;
8385 				wnn_area(buf->bun[j], yomi, WNN_YOMI, sizeof(yomi) / sizeof(w_char));
8386 				_sStrcpy(yk_bunsetsu[i].yomi, yomi);
8387 				wnn_area(buf->bun[j], kanji, WNN_KANJI, sizeof(kanji) / sizeof(w_char));
8388 				_sStrcpy(yk_bunsetsu[i].kanji, kanji);
8389 				if (buf->bun[j]->jirilen != buf->bun[j]->yomilen) {
8390 					/* ��Ω�����°��ι����ξ���ñ��˼�Ω��� wchar->char
8391                        �ȸ��ʤ��ƣ��� */
8392 					yk_bunsetsu[i].jirilen = buf->bun[j]->jirilen;
8393 					yk_bunsetsu[i].jirilen = yk_bunsetsu[i].jirilen * 2;
8394 				} else {
8395 					/* ��Ω����ɤ�Ĺ�Ǥ����,jililen ���ɤߤμ¥�������Ȥ� */
8396 					yk_bunsetsu[i].jirilen = strlen(yk_bunsetsu[i].yomi);
8397 				}
8398 				if (buf->bun[j]->real_kanjilen != buf->bun[j]->kanjilen) {
8399 					/* ��Ω�����°��ι����ξ���ñ��˴�����ʬĹ��
8400                        wchar->char �ȸ��ʤ��ƣ��� */
8401 					yk_bunsetsu[i].real_kanjilen = buf->bun[j]->real_kanjilen;
8402 					yk_bunsetsu[i].real_kanjilen = yk_bunsetsu[i].real_kanjilen * 2;
8403 				} else {
8404 					/* ������ʬĹ�����Ĺ�Ǥ���С�real_kanjilen �ϼ¥Х���
8405                        ���Ȥ��� */
8406 					yk_bunsetsu[i].real_kanjilen = strlen(yk_bunsetsu[i].kanji);
8407 				}
8408 			}
8409 		}
8410 
8411 		/* ��Ͽʸ���Ĺ����ꡢkeylen ��Ĺ���Ȥ��ϡ�ʸ��Ĺ�ѹ��ˤ�ä�
8412 		   ʸ��ˤʤäƤʤ�ʸ�������̾��¸�ߤ����礬���롣*/
8413 		for(j = 0; j < tmp_num; j++) {
8414 			bunlen += buf->bun[j]->kanjilen;}
8415 		if (bunlen < keylen) {
8416 			yk_bunsetsu = (struct wnn_yosoku_bunsetsu *)realloc(yk_bunsetsu, (bun_num + 1) * sizeof(struct wnn_yosoku_bunsetsu));
8417 			if (yk_bunsetsu == NULL) {
8418 				buf_wnn_errorno_set = WNN_ALLOC_FAIL;
8419 				return -1;
8420 			}
8421 			yk_bunsetsu[bun_num].hinsi = 0;
8422 			memset(yomi, 0x0, sizeof(yomi));
8423 			wnn_Strncpy(yomi, keybuf + bunlen, (int)(keylen - bunlen));
8424 			_sStrcpy(yk_bunsetsu[bun_num].yomi, yomi);
8425 			_sStrcpy(yk_bunsetsu[bun_num].kanji, yomi);
8426 			yk_bunsetsu[bun_num].jirilen = strlen(yk_bunsetsu[bun_num].yomi);
8427 			yk_bunsetsu[bun_num].real_kanjilen = strlen(yk_bunsetsu[bun_num].kanji);
8428 			bun_num++;
8429 		}
8430 
8431 	}
8432 
8433 	ret = js_yosoku_toroku(buf->env, bun_num, yk_bunsetsu);
8434 
8435 	free(yk_bunsetsu);
8436 	if (ret < 0)
8437 		return -1;
8438 	return 0;
8439 }
8440 
8441 /*:::DOC_START
8442  *
8443  *    Function Name: jl_yosoku_selected_cand
8444  *    Description  : ������ͽ¬��ͽ¬�����������
8445  *    Parameter    :
8446  *         buf :       (InOut) �Хåե��ؤΥݥ���
8447  *         selectpos :    (In) ����ꥹ���������
8448  *
8449  *    Return value : -1==ERROR  0�����ェλ
8450  *
8451  *    Revision history:
8452  *
8453  *:::DOC_END
8454  */
8455 int
jl_yosoku_selected_cand(buf,selectpos)8456 jl_yosoku_selected_cand(buf, selectpos)
8457 register struct wnn_buf *buf;
8458 int selectpos;
8459 {
8460 	int ret;
8461 
8462 	if(!buf || !(buf->env)) return -1;
8463 	buf_wnn_errorno_set = 0;
8464 
8465 	ret = js_yosoku_selected_cand(buf->env, selectpos);
8466 	return(ret);
8467 }
8468 
8469 /*:::DOC_START
8470  *
8471  *    Function Name: jl_yosoku_delete_cand
8472  *    Description  : ������ͽ¬��ͽ¬����������
8473  *    Parameter    :
8474  *         buf :       (InOut) �Хåե��ؤΥݥ���
8475  *         selectpos :    (In) ����ꥹ���������
8476  *
8477  *    Return value : -1==ERROR  0�����ェλ
8478  *
8479  *    Revision history:
8480  *
8481  *:::DOC_END
8482  */
8483 int
jl_yosoku_delete_cand(buf,selectpos)8484 jl_yosoku_delete_cand(buf, selectpos)
8485 struct wnn_buf *buf;
8486 int selectpos;
8487 {
8488 	if(!buf || !(buf->env)) return -1;
8489 	buf_wnn_errorno_set = 0;
8490 
8491 	if (js_yosoku_delete_cand(buf->env, selectpos) < 0)
8492 		return -1;
8493 
8494 	return 0;
8495 }
8496 
8497 /*:::DOC_START
8498  *
8499  *    Function Name: jl_yosoku_cancel_toroku
8500  *    Description  : ������ͽ¬��ľ����Ͽ�ǡ������
8501  *    Parameter    :
8502  *         buf :       (InOut) �Хåե��ؤΥݥ���
8503  *
8504  *    Return value : -1==ERROR  0�����ェλ
8505  *
8506  *    Revision history:
8507  *
8508  *:::DOC_END
8509  */
8510 int
jl_yosoku_cancel_toroku(buf)8511 jl_yosoku_cancel_toroku(buf)
8512 struct wnn_buf *buf;
8513 {
8514 	if(!buf || !(buf->env)) return -1;
8515 	buf_wnn_errorno_set = 0;
8516 
8517 	if (js_yosoku_cancel_latest_toroku(buf->env) < 0)
8518 		return -1;
8519 
8520 	return 0;
8521 }
8522 
8523 /*:::DOC_START
8524  *
8525  *    Function Name: jl_yosoku_reset_pre_yosoku
8526  *    Description  : ������ͽ¬��ͽ¬��������ꥢ
8527  *    Parameter    :
8528  *         buf :       (InOut) �Хåե��ؤΥݥ���
8529  *
8530  *    Return value : -1==ERROR  0�����ェλ
8531  *
8532  *    Revision history:
8533  *
8534  *:::DOC_END
8535  */
8536 int
jl_yosoku_reset_pre_yosoku(buf)8537 jl_yosoku_reset_pre_yosoku(buf)
8538 register struct wnn_buf *buf;
8539 {
8540 	if(!buf || !(buf->env)) return -1;
8541 	buf_wnn_errorno_set = 0;
8542 
8543 	if (js_yosoku_reset_pre_yosoku(buf->env) < 0)
8544 		return -1;
8545 
8546 	return 0;
8547 }
8548 
8549 /*:::DOC_START
8550  *
8551  *    Function Name: jl_yosoku_ikkatsu_toroku
8552  *    Description  : ������ͽ¬��ͽ¬�����Ͽ
8553  *    Parameter    :
8554  *         buf :       (InOut) �Хåե��ؤΥݥ���
8555  *         str :       (In) 1 ��ʬ��ʸ����
8556  *        size :       (In) ʸ����
8557  *
8558  *    Return value : -1==ERROR  0�����ェλ
8559  *
8560  *    Revision history:
8561  *
8562  *:::DOC_END
8563  */
8564 int
jl_yosoku_ikkatsu_toroku(buf,str,size)8565 jl_yosoku_ikkatsu_toroku(buf, str, size)
8566 struct wnn_buf *buf;
8567 char *str;
8568 int size;
8569 {
8570 	if(!buf || !(buf->env)) return -1;
8571 	buf_wnn_errorno_set = 0;
8572 
8573 	if(js_yosoku_ikkatsu_toroku(buf->env, str, size) < 0)
8574 		return -1;
8575 
8576 	return 0;
8577 }
8578 
8579 /*:::DOC_START
8580  *
8581  *    Function Name: jl_yosoku_ikkatsu_toroku_init
8582  *    Description  : ������ͽ¬��ͽ¬�����Ͽ�����
8583  *    Parameter    :
8584  *         buf :       (InOut) �Хåե��ؤΥݥ���
8585  *
8586  *    Return value : -1==ERROR  0�����ェλ
8587  *
8588  *    Revision history:
8589  *
8590  *:::DOC_END
8591  */
8592 int
jl_yosoku_ikkatsu_toroku_init(buf)8593 jl_yosoku_ikkatsu_toroku_init(buf)
8594 struct wnn_buf *buf;
8595 {
8596 	if(!buf || !(buf->env)) return -1;
8597 	buf_wnn_errorno_set = 0;
8598 
8599 	if(js_yosoku_ikkatsu_toroku_init(buf->env) < 0)
8600 		return -1;
8601 
8602 	return 0;
8603 }
8604 
8605 /*:::DOC_START
8606  *
8607  *    Function Name: jl_yosoku_ikkatsu_toroku_end
8608  *    Description  : ������ͽ¬��ͽ¬�����Ͽ��λ
8609  *    Parameter    :
8610  *         buf :       (InOut) �Хåե��ؤΥݥ���
8611  *
8612  *    Return value : -1==ERROR  0�����ェλ
8613  *
8614  *    Revision history:
8615  *
8616  *:::DOC_END
8617  */
8618 int
jl_yosoku_ikkatsu_toroku_end(buf)8619 jl_yosoku_ikkatsu_toroku_end(buf)
8620 struct wnn_buf *buf;
8621 {
8622 	if(!buf || !(buf->env)) return -1;
8623 	buf_wnn_errorno_set = 0;
8624 
8625 	if(js_yosoku_ikkatsu_toroku_end(buf->env) < 0)
8626 		return -1;
8627 
8628 	return 0;
8629 }
8630 
8631 /*:::DOC_START
8632  *
8633  *    Function Name: jl_yosoku_save_datalist
8634  *    Description  : ������ͽ¬��ͽ¬�ǡ�����¸
8635  *    Parameter    :
8636  *         buf :       (InOut) �Хåե��ؤΥݥ���
8637  *
8638  *    Return value : -1==ERROR  0�����ェλ
8639  *
8640  *    Revision history:
8641  *
8642  *:::DOC_END
8643  */
8644 int
jl_yosoku_save_datalist(buf)8645 jl_yosoku_save_datalist(buf)
8646 struct wnn_buf *buf;
8647 {
8648 	if(!buf || !(buf->env)) return -1;
8649 	buf_wnn_errorno_set = 0;
8650 
8651 	if (js_yosoku_save_datalist(buf->env) < 0)
8652 		return -1;
8653 
8654 	return 0;
8655 }
8656 
8657 /*:::DOC_START
8658  *
8659  *    Function Name: jl_yosoku_set_user_inputinfo
8660  *    Description  : ������ͽ¬�ϥ������Ͽ�������å�
8661  *    Parameter    :
8662  *           buf     :    (InOut) �Хåե��ؤΥݥ���
8663  *           allkey  :    (In)    ͽ¬��ޤ᤿�������Ͽ�
8664  *           userkey :    (In)    �桼�����ºݤ����Ϥ����������Ͽ�
8665  *
8666  *    Return value : -1==ERROR  0�����ェλ
8667  *
8668  *    Revision history:
8669  *
8670  *:::DOC_END
8671  */
8672 int
jl_yosoku_set_user_inputinfo(buf,allkey,userkey)8673 jl_yosoku_set_user_inputinfo(buf, allkey, userkey)
8674 struct wnn_buf *buf;
8675 int allkey;
8676 int userkey;
8677 {
8678 	if(!buf || !(buf->env)) return -1;
8679 	buf_wnn_errorno_set = 0;
8680 
8681 	if (js_yosoku_set_user_inputinfo(buf->env, allkey, userkey) < 0)
8682 		return -1;
8683 
8684 	return 0;
8685 }
8686 
8687 /*:::DOC_START
8688  *
8689  *    Function Name: jl_yosoku_set_timeinfo
8690  *    Description  : ������ͽ¬�ϥ������ϻ��֤��å�
8691  *    Parameter    :
8692  *           buf           : (InOut) �Хåե��ؤΥݥ���
8693  *           yosokuselect  : (In)    ����������Ƥ��뤫�ե饰
8694  *           throughyosoku : (In)    ����������������ե饰
8695  *           inputtime     : (In)    ���ϻ���
8696  *           keylen        : (In)    ������Ĺ��
8697  *
8698  *    Return value : -1==ERROR  0�����ェλ
8699  *
8700  *    Revision history:
8701  *
8702  *:::DOC_END
8703  */
8704 int
jl_yosoku_set_timeinfo(buf,yosokuselect,throughyosoku,inputtime,keylen)8705 jl_yosoku_set_timeinfo(buf, yosokuselect, throughyosoku, inputtime, keylen)
8706 register struct wnn_buf *buf;
8707 int yosokuselect;
8708 int throughyosoku;
8709 unsigned int inputtime;
8710 int keylen;
8711 {
8712 	if(!buf || !(buf->env)) return -1;
8713 	buf_wnn_errorno_set = 0;
8714 
8715 	if (js_yosoku_set_timeinfo(buf->env, yosokuselect, throughyosoku, inputtime, keylen) < 0)
8716 		return -1;
8717 
8718 	return 0;
8719 }
8720 
8721 /*:::DOC_START
8722  *
8723  *    Function Name: jl_yosoku_status
8724  *    Description  : ������ͽ¬������ͽ¬��Ψ�ǡ�������
8725  *    Parameter    :
8726  *           buf           : (InOut) �Хåե��ؤΥݥ���
8727  *           ykinfo        : (Out)   ����ͽ¬��Ψ�ǡ����ι�¤��
8728  *
8729  *    Return value : -1==ERROR  0�����ェλ
8730  *
8731  *    Revision history:
8732  *
8733  *:::DOC_END
8734  */
8735 int
jl_yosoku_status(buf,ykinfo)8736 jl_yosoku_status(buf, ykinfo)
8737 register struct wnn_buf *buf;
8738 struct wnn_yosoku_info *ykinfo;
8739 {
8740 	if(!buf || !(buf->env)) return -1;
8741 	buf_wnn_errorno_set = 0;
8742 
8743 	if (js_yosoku_status(buf->env, ykinfo) < 0)
8744 		return -1;
8745 
8746 	return 0;
8747 }
8748 
8749 /*:::DOC_START
8750  *
8751  *  Function Name   :   jl_zenassoc_dai()
8752  *  Description     :   Ϣ���Ѵ���Ԥ�
8753  *
8754  *  Parameter       :
8755  *      buf         :   Wnn�ΥХåե�
8756  *      bun_no      :   ʸ���ϰϤ���Ƭ
8757  *      bun_no2     :   ʸ���ϰϤ�����
8758  *      use_maep    :   ��������Ȥ����ɤ����Υե饰
8759  *      uniq_level  :   Ʊ�������Ф����������ꤹ��ե饰
8760  *
8761  *  Return Value    :   0==SUCCESS, -1==ERROR
8762  *  Revision History:
8763  *
8764  *:::DOC_END
8765  */
jl_zenassoc_dai(buf,bun_no,bun_no2,use_maep,uniq_level)8766 int jl_zenassoc_dai(buf, bun_no, bun_no2, use_maep, uniq_level)
8767 register struct wnn_buf *buf;
8768 int bun_no, bun_no2, use_maep, uniq_level;
8769 {
8770 	register struct wnn_buf_mt *buf_m = (WNN_BUF_MT *)buf;
8771 	int cnt;
8772 	w_char yomi[LENGTHBUNSETSU];        /* �о�ʸ��δ������ɤߤȤ������Ѥ���*/
8773 	w_char yomi1[LENGTHBUNSETSU];       /* ľ���ξ�ʸ����ɤߢ���³���������*/
8774 	w_char yomi_orig[LENGTHBUNSETSU];   /* �о�ʸ����ɤ�*/
8775 	int tmp;
8776 	register int k;
8777 	int x;
8778 	int nobi_top;
8779 	int fuku, nhinsi, *hlist;
8780 
8781 	struct wnn_sho_bunsetsu *sp;
8782 	/****************************************************************
8783 		 * STEP1: �ɤߡ��������³���������
8784 		 ****************************************************************/
8785 
8786 	/* ʸ���ֹ��Ĵ��(ʸ���ֹ�2��ʸ���ֹ�1����ʸ�Ὢü��ۤ��ʤ�)*/
8787 	if (bun_no2 > (tmp = dai_end(buf_m, bun_no)) || bun_no2 < 0) bun_no2 = tmp;
8788 	/* �о�ʸ���ϰϤδ���������*/
8789 	jl_get_kanji_body(buf_m, bun_no, bun_no2, yomi, sizeof(yomi) / sizeof(w_char));
8790 	/* �о�ʸ���ϰϤ��ɤߤ�����*/
8791 	jl_get_yomi_body(buf_m, bun_no, bun_no2, yomi_orig, sizeof(yomi_orig) / sizeof(w_char));
8792 
8793 	if ((use_maep & WNN_USE_MAE) && bun_no > 0) {
8794 		/* ľ����ʸ��ξ��������*/
8795 		dumbhinsi = buf->bun[bun_no - 1]->hinsi;            /* �ʻ�*/
8796 		jl_get_yomi_body(buf_m, bun_no - 1, bun_no, yomi1, sizeof(yomi1) / sizeof(w_char)); /* �ɤ�*/
8797 		mae_fzk = yomi1 + buf->bun[bun_no - 1]->jirilen;    /* ��°��ؤΥݥ���*/
8798 	} else {
8799 		/* ľ����ʸ��ˤ���³���ʤ�*/
8800 		dumbhinsi = WNN_BUN_SENTOU;
8801 		mae_fzk = (w_char *)0;
8802 	}
8803 	if ((use_maep & WNN_USE_ATO) && bun_no2 < buf->bun_suu){
8804 		/* ľ���ʸ��ξ��������*/
8805 		syuutanv = buf->bun[bun_no2]->kangovect;/* ��³�٥����ơ��֥�ؤΥݥ���*/
8806 		syuutanv1 = WNN_VECT_KANZEN;            /* ��������Ф��ν�ü�٥���*/
8807 		buf->zenkouho_endvect = syuutanv;       /* ��ü�٥���������*/
8808 	} else {
8809 		/* ľ���ʸ��ˤ���³���ʤ�*/
8810 		syuutanv = WNN_VECT_KANZEN;             /* ��������Ф��ν�ü�٥���*/
8811 		syuutanv1 = WNN_VECT_NO;                /* �٥����ʤ�*/
8812 		if (bun_no2 < buf->bun_suu)             /* �ǽ�ʸ��Ǥʤ���С�*/
8813 			buf->bun[bun_no2]->dai_top = 1;     /* ����ʸ�����ʸ�����Ƭ�Ǥ���*/
8814 		buf->zenkouho_endvect = -1;             /* ��ü�٥����ʤ�*/
8815 	}
8816 	if (!(buf->env)) return(-1);                /* �Ķ������뤫�ɤ��������å�*/
8817 
8818 	/****************************************************************
8819 		 * STEP2: Ϣ���Ѵ�����������
8820 		 ****************************************************************/
8821 	fuku = buf->bun[bun_no]->fukugou;
8822 	nhinsi = buf->bun[bun_no]->num_hinsi;
8823 	hlist = buf->bun[bun_no]->hinsi_list;
8824 
8825 	cnt = js_assoc_with_data(buf->env,      /* �Ķ�*/
8826 	fuku,               /* ʣ���ͥ�褹�뤫�ɤ���*/
8827 	nhinsi,             /* �ʻ�ο�*/
8828 	WNN_KANZEN_SHO,     /* �Ѵ��μ���*/
8829 	yomi,               /* Ϣ���Ѵ������ɤ�*/
8830 	dumbhinsi,          /* ľ����ʸ����ʻ�*/
8831 	mae_fzk,            /* ľ����ʸ�����°��ؤ�pointer*/
8832 	syuutanv,           /* vector*/
8833 	syuutanv1,          /* vector1*/
8834 	WNN_VECT_BUNSETSU,  /* vector2*/
8835 	buf->bun[bun_no],   /* �о�ʸ�����Ƭ*/
8836 	yomi_orig,          /* ��Ȥ�Ȥ��ɤ�*/
8837 	&buf_rb);           /* �Ѵ���̤��֤���¤��*/
8838 	if (cnt < 0) {
8839 		if_dead_disconnect_b(buf_m);
8840 		return(-1);                             /* �Ѵ�����*/
8841 	}
8842 	sp = (struct wnn_sho_bunsetsu *)buf_rb.buf;
8843 	free_zenkouho(buf_m);
8844 	nobi_top = buf->bun[bun_no]->nobi_top;
8845 	set_sho(buf->bun[bun_no], &buf->zenkouho[0]);
8846 	buf->zenkouho_suu = 1;
8847 	/* Connection information of Old bunsetsu
8848 		 * May not be correct.
8849 		 */
8850 	k = get_c_jikouho(sp, cnt, buf->bun[bun_no]);
8851 	if(k >= 0){
8852 		buf->zenkouho[0]->dai_top = (sp[k].status == WNN_CONNECT)? 0:1;
8853 		buf->zenkouho[0]->dai_end = (sp[k].status_bkwd == WNN_CONNECT_BK)? 0:1;
8854 	}
8855 	if(uniq_level || k < 0){
8856 		insert_sho(buf_m, ZENKOUHO, -1, -1, sp, cnt, uniq_level, fuku, nhinsi, hlist);
8857 	} else{
8858 		insert_sho(buf_m, ZENKOUHO, -1, -1, sp, k, uniq_level, fuku, nhinsi, hlist);
8859 		insert_sho(buf_m, ZENKOUHO, -1, -1, sp + k + 1, cnt - k - 1,
8860 		    uniq_level, fuku, nhinsi, hlist);
8861 	}
8862 	buf->c_zenkouho = 0;
8863 	buf->zenkouho_bun = bun_no;
8864 	buf->zenkouho_end_bun = bun_no + 1;
8865 	buf->zenkouho_daip = RENSOU;
8866 
8867 	for(k = 0 ; k < buf->zenkouho_suu; k++){
8868 		if(k == 0 || (buf->zenkouho[k]->ima && buf->zenkouho[k]->dic_no != -1)){
8869 			add_down_bnst(buf_m, bun_no, buf->zenkouho[k]);
8870 		}
8871 		if (nobi_top) buf->zenkouho[k]->nobi_top = 1; /* added by wang */
8872 	}
8873 	x = buf->c_zenkouho;
8874 	return x;
8875 }
8876 
8877 /*:::DOC_START
8878  *
8879  *  Function Name   :   jl_set_henkan_hinsi_group()
8880  *  Description     :   �Ѵ��˻Ȥ����Ȥ�ʤ��ʻ�����ꤹ�롣
8881  *
8882  *  Parameter       :
8883  *      env         :   �Ķ��ؤΥݥ���
8884  *      hinsi       :   �ʻ��ֹ�
8885  *      start       :   ʣ���ʻ줬������Ρ��ʻ��ֹ���ϰϤ���Ƭ
8886  *      end         :   ʣ���ʻ줬������Ρ��ʻ��ֹ���ϰϤ�����
8887  *      usr         :   �Ѵ��˻Ȥ�:1 �Ȥ�ʤ�:0
8888  *
8889  *  Return Value    :   0==SUCCESS, -1==ERROR
8890  *  Revision History:
8891  *
8892  *:::DOC_END
8893  */
8894 int
jl_set_henkan_hinsi_group(env,hinsi,start,end,use)8895 jl_set_henkan_hinsi_group(env, hinsi, start, end, use)
8896 struct wnn_env_int *env;
8897 int hinsi;
8898 int start;
8899 int end;
8900 int use;
8901 {
8902 	int *hlist;
8903 	int ii;
8904 	int nhinsi;
8905 	int ret;
8906 
8907 	if (start > end)
8908 		return -1;
8909 	hlist = (int *)malloc((1 + end - start + 1 + 1) * sizeof(int));
8910 	if (!hlist)
8911 		return -1;
8912 
8913 	nhinsi = 0;
8914 	hlist[nhinsi++] = hinsi;
8915 	for (ii = start; ii <= end ; ii++)
8916 		hlist[nhinsi++] = ii;
8917 	hlist[nhinsi] = 0;
8918 
8919  	/* use == FALSE �����Ѵ��˻��Ѥ��ʤ��ʻ�ˤ��� */
8920  	if (!use)
8921 		nhinsi *= -1;
8922 	if(js_set_henkan_hinsi(env, 1, nhinsi, hlist) < 0)
8923 		ret = -1;
8924 	else
8925 		ret = 0;
8926 	free(hlist);
8927 	return ret;
8928 }
8929 /*:::DOC_START
8930  *
8931  *  Function Name   :   jl_rensou_unuse_hinsi_set
8932  *  Description     :   �Ѵ��˻Ȥ�ʤ��ʻ�,"Ϣ��"�����ꤹ�롣
8933  *
8934  *  Parameter       :
8935  *      env         :   �Ķ��ؤΥݥ���
8936  *
8937  *  Return Value    :   0==SUCCESS, -1==ERROR
8938  *  Revision History:
8939  *
8940  *:::DOC_END
8941  */
8942 int
jl_rensou_unuse_hinsi_set(env)8943 jl_rensou_unuse_hinsi_set(env)
8944 register struct wnn_env_int *env;
8945 {
8946     int hlist[2];
8947     w_char whname[16];
8948 
8949 	if(env == NULL) return (-1);
8950 
8951     _Sstrcpy(whname, "Ϣ��");
8952     if((hlist[0] = jl_hinsi_number_e_body(env, whname)) == -1) {
8953         return (-1);
8954     }
8955     if(js_set_henkan_hinsi(env, 1, -1, hlist) < 0) {
8956         return (-1);
8957     }
8958     return 0;
8959 }
8960 
8961 /* �հ�������������¸�Ѵؿ� */
8962 static void
rev_setting(dic_name,hindo_name,prio,rdonly,hrdonly,pwd_dic,pwd_hindo,rev)8963 rev_setting(dic_name, hindo_name, prio, rdonly, hrdonly, pwd_dic, pwd_hindo, rev)
8964 char *dic_name, *hindo_name, *pwd_dic, *pwd_hindo;
8965 int prio, rdonly, hrdonly, rev;
8966 {
8967 	struct st_rev_env *rev_p;
8968 	struct st_rev_env *rev_ep;
8969 
8970 	/* ���������ѤΥ��ꥢ����ݤ��� */
8971 	rev_p = (struct st_rev_env *)malloc(sizeof(struct st_rev_env));
8972 	if (!rev_p){
8973 		env_wnn_errorno_set=WNN_ALLOC_FAIL;
8974 		return;
8975 	}
8976     /* �հ�����������ι��ܤ�¤�Τ����ꤹ�� */
8977 	memset(rev_p->dict_name, 0, WNN_ENVNAME_LEN);
8978 	strncpy(rev_p->dict_name, dic_name, sizeof(rev_p->dict_name)-1);
8979 	memset(rev_p->hindo_name, 0, WNN_ENVNAME_LEN);
8980 	strncpy(rev_p->hindo_name, hindo_name, sizeof(rev_p->hindo_name)-1);
8981 	rev_p->prio = prio;
8982 	rev_p->rw = rdonly;
8983 	rev_p->hrw = hrdonly;
8984 	memset(rev_p->pwd_dict, 0, WNN_ENVNAME_LEN);
8985 	strncpy(rev_p->pwd_dict, pwd_dic, sizeof(rev_p->pwd_dict)-1);
8986 	memset(rev_p->pwd_hindo, 0, WNN_ENVNAME_LEN);
8987 	strncpy(rev_p->pwd_hindo, pwd_hindo, sizeof(rev_p->pwd_hindo)-1);
8988 	rev_p->rev = rev;
8989 	rev_p->jisho_cnt = 0;
8990 	rev_p->next = NULL;
8991 
8992 	if (!rev_env) {
8993 		rev_env = rev_p;
8994 	}else{
8995 		rev_ep = rev_env;
8996 		while(rev_ep->next)
8997 			rev_ep = rev_ep->next;
8998 		rev_ep->next = rev_p;
8999 	}
9000 }
9001