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.0
138 */
139 /* �ʻ�ե�����ι�¤�˴ؤ������
140 */
141
142 #include <stdio.h>
143 #include "commonhd.h"
144 #include "config.h"
145 #include "wnnerror.h"
146 #include "jslib.h"
147 #include "wnn_os.h"
148 #include "wnn_string.h"
149 #include "hinsi_file.h"
150
151
152 /*
153 wnn_loadhinsi(NULL) �ʻ�ξ�����ɤ߹���
154
155 wnn_find_hinsi_by_name(c) ̾����Ϳ���ơ��ʻ��ֹ����
156 char *c;
157
158 char *wnn_get_hinsi_name(k) �ʻ��ֹ椫��̾������
159 int k;
160
161 int
162 wnn_get_fukugou_component(k,str, ) ʣ���ʻ���Ф��� �������Ǥ����
163 int k; �������ǤθĿ������ͤȤ����֤��졢
164 unsigned short **str; �������Ǥ� str �ʹߤ��֤���롣
165
166 */
167
168 /* extern int wnn_errorno; */
169
170 /*
171 *here start the real program
172 */
173
174 #define SIZE 1024
175
176 int wnnerror_hinsi;
177 static int hinsi_loaded = 0;
178 static int line_no = 0;
179
180 static int find_hinsi_by_name(w_char *c);
181 static w_char * get_hinsi_name(int k);
182
183 static w_char heap[HEAP_LEN];
184 static w_char *hp = heap;
185 static unsigned short wheap[WHEAP_LEN];
186 static unsigned short *whp = wheap;
187 static w_char *hinsi[MAXHINSI];
188 static struct wnn_fukugou fukugou[MAXFUKUGOU];
189 static struct wnn_hinsi_node node[MAXNODE];
190
191 int mhinsi = 0;
192 int mfukugou = 0;
193 int mnode = 0;
194
195 #if !defined(DSERVER) && defined(JSERVER)
196 extern char hinsi_file_name[];
197 #endif /* !DSERVER && JSERVER */
198
199 static void
error_long()200 error_long()
201 {
202 wnnerror_hinsi = WNN_TOO_LONG_HINSI_FILE_LINE;
203 }
204
205 static void
error_no_heap()206 error_no_heap()
207 {
208 wnnerror_hinsi = WNN_TOO_BIG_HINSI_FILE;
209 }
210
211 static int
get_char0(fp)212 get_char0(fp)
213 FILE *fp;
214 {
215 int c,d;
216
217 for(;(c = getc(fp)) == COMMENT_CHAR || c == CONTINUE_CHAR ||
218 c == IGNORE_CHAR1 || c == IGNORE_CHAR2;){
219 if(c == CONTINUE_CHAR){
220 if((d = getc(fp))== EOF){
221 break;
222 }
223 if(d == '\n'){
224 line_no += 1;
225 continue;
226 } else{
227 ungetc(d,fp);
228 break;
229 }
230 } else if(c == COMMENT_CHAR){
231 for(;;){
232 if((c = getc(fp))== EOF){
233 return(EOF);
234 }
235 if(c == '\n'){
236 ungetc(c,fp);
237 line_no += 1;
238 break;
239 }
240 }
241 }
242 }
243 if(c == '\n')line_no += 1;
244 return(c);
245 }
246
247 static int
get_char(fp)248 get_char(fp) /* remove null lines */
249 FILE *fp;
250 {
251 int d;
252 static int cucucu = -1;
253 static int fufufu = 0;
254
255 if (cucucu != -1){
256 d = cucucu;
257 cucucu = -1;
258 return(d);
259 }
260 if (fufufu == 0) { /* remove all new lines in the head of the file */
261 for(;(d = get_char0(fp)) == '\n';);
262 fufufu = 1;
263 } else {
264 d = get_char0(fp);
265 }
266 if (d == '\n') {
267 while((cucucu = get_char0(fp)) == '\n');
268 }
269 return(d);
270 }
271
272 /* get one phrase and return the separater */
273 static int
get_phrase(s0,size,fp)274 get_phrase(s0,size,fp)
275 UCHAR *s0;
276 int size;
277 FILE *fp;
278 {
279 UCHAR *s = s0;
280 int c;
281 static int eof = 0;
282
283 if(eof){
284 *s0 = 0;
285 return(EOF);
286 }
287
288 #if defined(JSERVER) && !defined(DSERVER)
289 if(fp) {
290 #endif /* JSERVER && !DSERVER */
291 while(((c = get_char(fp)) != '\n') &&
292 (c != DEVIDE_CHAR) &&
293 (c != NODE_CHAR) &&
294 (c != HINSI_SEPARATE_CHAR) &&
295 (c != EOF)
296 ){
297 if(s - s0 >= size){
298 error_long();
299 return(HINSI_ERR);
300 }
301 *s++ = c;
302 }
303 #if defined(JSERVER) && !defined(DSERVER)
304 } else {
305 while(((c = get4com()) != '\n') &&
306 (c != DEVIDE_CHAR) &&
307 (c != NODE_CHAR) &&
308 (c != HINSI_SEPARATE_CHAR) &&
309 (c != EOF)
310 ){
311 if(s - s0 >= size){
312 error_long();
313 return(HINSI_ERR);
314 }
315 *s++ = c;
316 }
317 }
318 #endif /* JSERVER && !DSERVER */
319
320 if(c == EOF) eof = 1;
321 if(s - s0 >= size - 1){
322 error_long();
323 return(HINSI_ERR);
324 }
325 *s++ = '\0';
326 return(c);
327 }
328
329 static int
stradd(cp,str)330 stradd(cp,str)
331 w_char **cp;
332 char *str;
333 {
334 int len = strlen(str);
335
336 if(hp + len + 1 >= heap + HEAP_LEN){
337 error_no_heap();
338 return(-1);
339 }
340 *cp = hp;
341 wnn_Sstrcpy(hp,str);
342 hp += wnn_Strlen(hp) + 1;
343 return(0);
344 }
345
346 static int
w_stradd(cp,str)347 w_stradd(cp, str)
348 unsigned short **cp;
349 unsigned short *str;
350 {
351
352 *cp = whp;
353 for(;*str != TERMINATE; str++,whp++){
354 if(whp >= wheap + WHEAP_LEN){
355 error_no_heap();
356 return(-1);
357 }
358 *whp = *str;
359 }
360 *whp++ = TERMINATE;
361 return(0);
362 }
363
364 int
wnn_loadhinsi(fname)365 wnn_loadhinsi(fname)
366 char *fname;
367 {
368 FILE *fp;
369 UCHAR buf[SIZE];
370 unsigned short fukugou_str[MAXHINSI];
371 int sep;
372 int h;
373 int len;
374 unsigned short *c;
375 char hinsi_file_name[MAXPATHLEN];
376 extern int wnn_find_hinsi_by_name(char *name);
377
378
379 if((fname == NULL) || (*fname == 0)){
380 memset(hinsi_file_name, 0, sizeof(hinsi_file_name));
381 strncpy(hinsi_file_name, LIBDIR, sizeof(hinsi_file_name) - 1);
382 strncat(hinsi_file_name, HINSIDATA_FILE, sizeof(hinsi_file_name) - strlen(hinsi_file_name) - 1);
383 fname = &hinsi_file_name[0];
384 }
385
386
387 if((fp = fopen((char *)fname, "r")) == NULL){
388 wnnerror_hinsi = WNN_NO_HINSI_DATA_FILE;
389 goto err_1;
390 }
391
392 hinsi_loaded = 1;
393 while((sep = get_phrase(buf,SIZE,fp)) != EOF){
394 if(sep == HINSI_ERR){
395 goto err; /* wnnerror_hinsi set in get_phrase */
396 }
397 if(buf[0] == YOYAKU_CHAR){ /* yoyaku */
398 if(sep != '\n'){
399 wnnerror_hinsi = WNN_BAD_HINSI_FILE;
400 goto err;
401 }
402 hinsi[mhinsi++] = NULL;
403 } else if(sep == '\n'){ /* hinsi */
404 if(stradd(&hinsi[mhinsi++],buf))goto err;
405 } else if(sep == DEVIDE_CHAR){ /* fukugou */
406 if(stradd(&fukugou[mfukugou].name,buf))goto err;
407 c = fukugou_str;
408 len = sizeof(fukugou_str) / sizeof(unsigned short);
409 while((sep = get_phrase(buf,SIZE,fp)) != EOF){
410 if(sep == -1){
411 goto err; /* wnnerror_hinsi set in get_phrase */
412 }
413 if(sep != EOF && sep != HINSI_SEPARATE_CHAR && sep != '\n'){
414 wnnerror_hinsi = WNN_BAD_HINSI_FILE;
415 goto err;
416 }
417 if((h = wnn_find_hinsi_by_name(buf)) == -1 ||
418 h >= mhinsi){
419 wnnerror_hinsi = WNN_BAD_HINSI_FILE;
420 goto err;
421 }
422 if (len-- <= 1) {
423 wnnerror_hinsi = WNN_BAD_HINSI_FILE;
424 goto err;
425 }
426 *c++ = h;
427 if(sep == '\n' || sep == EOF)
428 break;
429 }
430 *c = TERMINATE;
431 if(w_stradd(&fukugou[mfukugou++].component,fukugou_str))goto err;
432 } else if(sep == NODE_CHAR){
433 int first = 1;
434 w_char *dummy;
435
436 node[mnode].kosuu = 0;
437 if(stradd(&node[mnode].name,buf))goto err;
438 while((sep = get_phrase(buf,SIZE,fp)) != EOF){
439 if(sep == -1){
440 goto err; /* wnnerror_hinsi set in get_phrase */
441 }
442 if(sep != EOF && sep != HINSI_SEPARATE_CHAR && sep != '\n'){
443 wnnerror_hinsi = WNN_BAD_HINSI_FILE;
444 goto err;
445 }
446 node[mnode].kosuu++;
447 if(first){
448 if(stradd(&node[mnode].son,buf))goto err;
449 first = 0;
450 } else{
451 if(stradd(&dummy,buf))goto err;
452 }
453 if(sep == '\n' || sep == EOF)
454 break;
455 }
456 mnode++;
457 }
458 }
459 fclose(fp);
460 return(0);
461 err:
462 fclose(fp);
463 err_1:
464 return(HINSI_ERR);
465 }
466
467 static int
find_hinsi_by_name(c)468 find_hinsi_by_name(c)
469 register w_char *c;
470 {
471 register int k;
472 char *hfname = NULL;
473
474 #if !defined(DSERVER) && defined(JSERVER)
475 hfname = &hinsi_file_name[0];
476 #endif /* !DSERVER && JSERVER */
477 if(!hinsi_loaded){
478 if(wnn_loadhinsi(hfname) != 0){
479 return(-1);
480 }
481 }
482 for(k = 0 ; k < mhinsi; k++){
483 if(hinsi[k] && wnn_Strcmp(hinsi[k],c) == 0){
484 return(k);
485 }
486 }
487 for(k = 0 ; k < mfukugou; k++){
488 if(fukugou[k].name && wnn_Strcmp(fukugou[k].name,c) == 0){
489 return(FUKUGOU_START - k);
490 }
491 }
492 return(-1);
493 }
494
495
496 int
wnn_find_hinsi_by_name(name)497 wnn_find_hinsi_by_name(name)
498 register char *name;
499 {
500 w_char hin[WNN_HINSI_NAME_LEN];
501
502 wnn_Sstrncpy(hin, (sizeof(hin) / sizeof(w_char)) - 1, name, -1);
503 return(find_hinsi_by_name(hin));
504 }
505
506
507 static w_char *
get_hinsi_name(k)508 get_hinsi_name(k)
509 int k;
510 {
511 char *hfname = NULL;
512
513 #if !defined(DSERVER) && defined(JSERVER)
514 hfname = &hinsi_file_name[0];
515 #endif /* !DSERVER && JSERVER */
516 if(!hinsi_loaded){
517 if(wnn_loadhinsi(hfname) != 0){
518 return(NULL);
519 }
520 }
521 if(k < mhinsi && k >= 0){
522 return(hinsi[k]);
523 } else if(k > FUKUGOU_START - mfukugou){
524 return(fukugou[FUKUGOU_START - k].name);
525 }
526 return(NULL);
527 }
528
529 char *
wnn_get_hinsi_name(k)530 wnn_get_hinsi_name(k)
531 int k;
532 {
533 w_char *s;
534 static char hin[WNN_HINSI_NAME_LEN * 2];
535
536 if((s = get_hinsi_name(k)) == NULL)return(NULL);
537 wnn_sStrncpy(hin, sizeof(hin) - 1, s, -1);
538 return(hin);
539 }
540
541 static
542 int
wnn_get_fukugou_component_body(k,shp)543 wnn_get_fukugou_component_body(k, shp)
544 register int k;
545 register unsigned short **shp;
546 {
547 static unsigned short tmp;
548 register unsigned short *s;
549 int n;
550
551 if(k < mhinsi && k >= 0){
552 tmp = k;
553 *shp = &tmp;
554 return(1);
555 }
556 if(k > FUKUGOU_START - mfukugou && k <= FUKUGOU_START){
557 n = FUKUGOU_START - k;
558 for(*shp = s = fukugou[n].component;*s != TERMINATE;s++)
559 ;
560 return(s - *shp);
561 }
562 return(-1);
563 }
564
565 int
wnn_get_fukugou_component(k,shp)566 wnn_get_fukugou_component(k, shp)
567 register int k;
568 register unsigned short **shp;
569 {
570 char *hfname = NULL;
571
572 #if !defined(DSERVER) && defined(JSERVER)
573 hfname = &hinsi_file_name[0];
574 #endif /* !DSERVER && JSERVER */
575 if(!hinsi_loaded){
576 if(wnn_loadhinsi(hfname) != 0){
577 return(-1);
578 }
579 }
580 return(wnn_get_fukugou_component_body(k, shp));
581 }
582
583
584
585
586 /* ?? need doc. */
587 int
wnn_get_hinsi_i4_boundary_free(hinsi_pter)588 wnn_get_hinsi_i4_boundary_free(hinsi_pter)
589 register unsigned char *hinsi_pter;
590 {
591 register int ret;
592
593 ret = *hinsi_pter;
594 ret = (ret<<8) | *(hinsi_pter+1);
595 return(ret);
596 }
597