Mercurial > freewnn
annotate Wnn/jutil/ujisf.c @ 23:e1aadb6dcbd4
- fixed the build rule for build_stamp.h. keywords in template for hg tip should surrounded by curly braces instead of hash marks.
- fixed usage of libtool in building jlib.V3. newer libtool does not work without mode specifier.
- replaced some libtool related files. (should remove these?)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Fri, 23 Jan 2009 16:36:13 +0900 |
parents | c966456648ad |
children | a7ccf412ba02 |
rev | line source |
---|---|
0 | 1 /* |
2 * $Id: ujisf.c,v 1.7 2002/07/14 04:26:57 hiroo Exp $ | |
3 */ | |
4 | |
5 /* | |
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system. | |
7 * This file is part of FreeWnn. | |
8 * | |
9 * Copyright Kyoto University Research Institute for Mathematical Sciences | |
10 * 1987, 1988, 1989, 1990, 1991, 1992 | |
11 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999 | |
12 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992 | |
13 * Copyright FreeWnn Project 1999, 2000, 2002 | |
14 * | |
15 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp> | |
16 * | |
17 * This program is free software; you can redistribute it and/or modify | |
18 * it under the terms of the GNU General Public License as published by | |
19 * the Free Software Foundation; either version 2 of the License, or | |
20 * (at your option) any later version. | |
21 * | |
22 * This program is distributed in the hope that it will be useful, | |
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 * GNU General Public License for more details. | |
26 * | |
27 * You should have received a copy of the GNU General Public License | |
28 * along with this program; if not, write to the Free Software | |
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
30 */ | |
31 | |
32 /* | |
33 * Ujis format <--> internal data. | |
34 */ | |
35 | |
36 #ifdef HAVE_CONFIG_H | |
37 # include <config.h> | |
38 #endif | |
39 | |
40 #include <stdio.h> | |
41 #if STDC_HEADERS | |
42 # include <stdlib.h> | |
43 # include <string.h> | |
44 #else | |
45 # if HAVE_MALLOC_H | |
46 # include <malloc.h> | |
47 # endif | |
48 # if HAVE_STRINGS_H | |
49 # include <strings.h> | |
50 # endif | |
51 #endif /* STDC_HEADERS */ | |
52 | |
53 #include "commonhd.h" | |
54 #include "jslib.h" | |
55 #include "jh.h" | |
56 #include "jdata.h" | |
57 #include "wnn_os.h" | |
58 #include "wnn_string.h" | |
59 | |
60 #ifdef CHINESE | |
61 #include "cplib.h" | |
62 int pzy_flag = CWNN_PINYIN; /* Pinyin or Zhuyin */ | |
63 static void sisheng_num (), read_kanji_str_w (); | |
64 #endif | |
65 | |
66 #ifndef min | |
67 #define min(a, b) ((a > b)? b:a) | |
68 #define max(a, b) ((a < b)? b:a) | |
69 #endif | |
70 | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
71 /* prototypes */ |
0 | 72 extern unsigned char kanjiaddr (); |
73 extern void Print_entry (); | |
74 extern int wnn_find_hinsi_by_name (); | |
75 #ifdef CHINESE | |
76 extern void cwnn_zy_str_analysis (), cwnn_py_str_analysis (); | |
77 #endif | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
78 |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
79 |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
80 #include "ujisf.h" |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
81 |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
82 static void Kanjistradd (w_char *k, w_char *y, w_char *c, register UCHAR **cp); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
83 static void bunpou_num (register char *a, register int *p); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
84 static void read_kanji_str (register char *c, register char *o); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
85 static void toesc (char *ckanji, char *cyomi); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
86 void exit1 (void); |
0 | 87 |
88 extern struct JT jt; | |
89 | |
90 /* extern variables */ | |
91 | |
92 struct je **jeary; | |
93 int wnnerror; | |
94 | |
95 #define WNN_HINSI_LEN 4096 | |
96 | |
97 w_char file_comment[WNN_COMMENT_LEN]; | |
98 w_char hinsi_list[WNN_HINSI_LEN]; | |
99 | |
100 | |
101 | |
102 /* static variables */ | |
103 static UCHAR *heap, *hp, *heapend; | |
104 static w_char *yomi_heap, *yhp, *yheapend; | |
105 static struct je *je_heap, *jehp, *jeheapend; | |
106 static FILE *ifpter; | |
107 static int maxline; | |
108 | |
109 /* extern functions of this file are | |
110 ujis_header(); | |
111 read_ujis(reversep, to_esc, which_dict); | |
112 reverse_yomi(); | |
113 sort(); | |
114 uniq_je(func); | |
115 output_ujis(opter, serial_out, esc_exp); | |
116 */ | |
117 | |
118 int lc; | |
119 | |
120 static char stack[LINE_SIZE] = { 0 }; | |
121 | |
122 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
123 get_line (register char *c) |
0 | 124 { |
125 if (stack[0]) | |
126 { | |
127 strcpy (c, stack); | |
128 stack[0] = 0; | |
129 } | |
130 else | |
131 { | |
132 if (fgets (c, LINE_SIZE, ifpter) == NULL) | |
133 { | |
134 return (EOF); | |
135 } | |
136 } | |
137 return (0); | |
138 } | |
139 | |
140 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
141 unget_line (char *c) |
0 | 142 { |
143 strcpy (stack, c); | |
144 } | |
145 | |
146 | |
147 char * | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
148 get_string (register char *str, char *buf) |
0 | 149 { |
150 register char *c = buf; | |
151 for (; *c == '\t' || *c == ' '; c++); | |
152 if (*c == '\0' || *c == '\n') | |
153 { | |
154 *str = 0; | |
155 return (NULL); | |
156 } | |
157 for (; *c != '\t' && *c != ' ' && *c != '\n' && *c != '\0'; c++) | |
158 { | |
159 *str++ = *c; | |
160 } | |
161 *str = 0; | |
162 return (c); | |
163 } | |
164 | |
165 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
166 bad_line (char *bf) |
0 | 167 { |
168 static int badl = 0; | |
169 | |
170 fprintf (stderr, "Bad line \"%s\"\n", bf); | |
171 fprintf (stderr, "Bad line omitted\n"); | |
172 if (++badl > BADLMAX) | |
173 { | |
174 fprintf (stderr, "Too many bad lines.\n"); | |
175 exit1 (); | |
176 } | |
177 } | |
178 | |
179 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
180 error_no_heap (void) |
0 | 181 { |
182 fprintf (stderr, "Heap area is exhausted.\n"); | |
183 exit1 (); | |
184 } | |
185 | |
186 static int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
187 get_one_line (char *buffer, register struct je **jep, int rev, int to_esc, int which_dict) |
0 | 188 { |
189 register char *c = buffer; | |
190 static char tmp[LINE_SIZE]; | |
191 static char ckanji[LINE_SIZE]; | |
192 static char cyomi[LINE_SIZE]; | |
193 static w_char yomi[LINE_SIZE]; | |
194 static w_char kanji[LINE_SIZE]; | |
195 static w_char comm[LINE_SIZE]; | |
196 #ifdef CHINESE | |
197 static w_char un_sisheng_yincod_str[LINE_SIZE]; | |
198 static w_char yincod_str[LINE_SIZE]; | |
199 static char csisheng[LINE_SIZE]; | |
200 static w_char wtmp[LINE_SIZE]; | |
201 #endif | |
202 char *c1; | |
203 | |
204 if (jehp == jeheapend) | |
205 { | |
206 if ((jehp = je_heap = (struct je *) malloc ((HEAPINC * sizeof (struct je)))) == NULL) | |
207 { | |
208 fprintf (stderr, "Malloc Failed\n"); | |
209 return (-1); | |
210 } | |
211 jeheapend = je_heap + HEAPINC; | |
212 } | |
213 *jep = jehp; | |
214 jehp++; | |
215 | |
216 if (rev == REVERSE) | |
217 { | |
218 if ((c = get_string (ckanji, c)) == NULL) | |
219 return (1); | |
220 } | |
221 else | |
222 { | |
223 if ((c = get_string (cyomi, c)) == NULL) | |
224 return (1); | |
225 } | |
226 if (rev == REVERSE) | |
227 { | |
228 if ((c = get_string (cyomi, c)) == NULL) | |
229 return (-1); | |
230 } | |
231 else | |
232 { | |
233 if ((c = get_string (ckanji, c)) == NULL) | |
234 return (-1); | |
235 } | |
236 #ifdef CHINESE | |
237 /* here ,should seperate pinyin to two part */ | |
238 /* one is usually pinyin string like Zhong.Guo. */ | |
239 /* the is sisheng string like 23 */ | |
240 | |
241 if (which_dict == CWNN_REV_DICT || which_dict == BWNN_REV_DICT) | |
242 { | |
243 if (pzy_flag == CWNN_ZHUYIN) | |
244 cwnn_zy_str_analysis (cyomi, csisheng, un_sisheng_yincod_str, yincod_str); | |
245 else | |
246 cwnn_py_str_analysis (cyomi, csisheng, un_sisheng_yincod_str, yincod_str); | |
247 | |
248 sisheng_num (csisheng, &((*jep)->ss)); | |
249 read_kanji_str_w (wtmp, un_sisheng_yincod_str); | |
250 wnn_Strcpy (yomi, wtmp); | |
251 } | |
252 else | |
253 { | |
254 read_kanji_str (tmp, cyomi); | |
255 wnn_Sstrcpy (yomi, tmp); | |
256 } | |
257 #else | |
258 read_kanji_str (tmp, cyomi); | |
259 wnn_Sstrcpy (yomi, tmp); | |
260 #endif | |
261 if (wnn_Strlen (yomi) >= LENGTHYOMI) | |
262 { | |
263 fprintf (stderr, "YOMI is longer in line %d.\n", lc); | |
264 return (-1); | |
265 } | |
266 w_stradd (yomi, &((*jep)->yomi)); | |
267 | |
268 read_kanji_str (tmp, ckanji); | |
269 wnn_Sstrcpy (kanji, tmp); | |
270 if (wnn_Strlen (kanji) >= LENGTHYOMI) | |
271 { | |
272 fprintf (stderr, "KANJI is longer in line %d.\n", lc); | |
273 return (-1); | |
274 } | |
275 w_stradd (kanji, &((*jep)->kan)); | |
276 | |
277 if ((c = get_string (tmp, c)) == NULL) | |
278 return (-1); | |
279 bunpou_num (tmp, &((*jep)->hinsi)); | |
280 | |
281 if ((c = get_string (tmp, c)) == NULL) | |
282 return (-1); | |
283 if (tmp[0] == '-') | |
284 { | |
285 (*jep)->hindo = -1; /* Real hindo == -1 means Not to use it */ | |
286 } | |
287 else | |
288 { | |
289 sscanf (tmp, "%d", &((*jep)->hindo)); | |
290 } | |
291 | |
292 if ((get_string (tmp, c)) == NULL) | |
293 { | |
294 c1 = NULL; | |
295 (*jep)->comm = NULL; | |
296 comm[0] = 0; | |
297 } | |
298 else | |
299 { | |
300 /* left entries are all considered as comment */ | |
301 for (; *c == '\t' || *c == ' '; c++); | |
302 if (c[strlen (c) - 1] == '\n') | |
303 c[strlen (c) - 1] = '\0'; | |
304 c1 = c; | |
305 wnn_Sstrcpy (comm, c1); | |
306 if (wnn_Strlen (comm) >= LENGTHYOMI) | |
307 { | |
308 fprintf (stderr, "COMMENT is longer in line %d.\n", lc); | |
309 return (-1); | |
310 } | |
311 w_stradd (comm, &((*jep)->comm)); | |
312 } | |
313 | |
314 if (to_esc) | |
315 { | |
316 toesc (ckanji, cyomi); | |
317 } | |
318 /* | |
319 if(strchr(ckanji, DIC_COMMENT_CHAR) || | |
320 strchr(ckanji, DIC_YOMI_CHAR)){ | |
321 fprintf(stderr, "Bad character in kanji\n"); | |
322 return(-1); | |
323 } | |
324 if(which_dict){ | |
325 if(strchr(cyomi, DIC_COMMENT_CHAR) || | |
326 strchr(cyomi, DIC_YOMI_CHAR)){ | |
327 fprintf(stderr, "Bad character in yomi\n"); | |
328 return(-1); | |
329 } | |
330 } | |
331 */ | |
332 Kanjistradd (kanji, | |
333 #ifdef CHINESE | |
334 ((which_dict == CWNN_REV_DICT || which_dict == BWNN_REV_DICT) ? yincod_str : ((which_dict == WNN_REV_DICT) ? yomi : NULL)), | |
335 #else | |
336 (which_dict) ? yomi : NULL, | |
337 #endif | |
338 comm, &(*jep)->kanji); | |
339 return (0); | |
340 } | |
341 | |
342 static void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
343 Kanjistradd (w_char *k, w_char *y, w_char *c, register UCHAR **cp) |
0 | 344 { |
345 int len; | |
346 if (hp + LENGTHKANJI >= heapend) | |
347 { | |
348 if ((hp = heap = (UCHAR *) malloc ((HEAPINC * HEAP_PER_LINE))) == NULL) | |
349 { | |
350 fprintf (stderr, "Malloc Failed\n"); | |
351 exit (1); | |
352 } | |
353 heapend = heap + (HEAPINC * HEAP_PER_LINE); | |
354 } | |
355 *cp = hp; | |
356 if ((len = kanjiaddr (hp, k, y, c)) >= LENGTHKANJI) | |
357 { | |
358 fprintf (stderr, "KANJI is longer in line %d.\n", lc); | |
359 exit (1); | |
360 } | |
361 hp += len; | |
362 } | |
363 | |
364 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
365 w_stradd (register w_char *str, register w_char **cp) |
0 | 366 { |
367 register int len = wnn_Strlen (str); | |
368 | |
369 if (yhp + len + 1 >= yheapend) | |
370 { | |
371 if ((yhp = yomi_heap = (w_char *) malloc ((HEAPINC * sizeof (w_char)))) == NULL) | |
372 { | |
373 fprintf (stderr, "Malloc Failed\n"); | |
374 return (-1); | |
375 } | |
376 yheapend = yomi_heap + HEAPINC; | |
377 } | |
378 *cp = yhp; | |
379 wnn_Strcpy (yhp, str); | |
380 yhp += len + 1; | |
381 return (0); | |
382 } | |
383 | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
384 |
0 | 385 #ifdef CHINESE |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
386 void ujis_header (int *which_dict) |
0 | 387 #else |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
388 void ujis_header (void) |
0 | 389 #endif |
390 { | |
391 char buffer[LINE_SIZE]; | |
392 char *c = buffer; | |
393 char str[LINE_SIZE]; | |
394 | |
395 jt.total = 0; | |
396 file_comment[0] = 0; | |
397 hinsi_list[0] = 0; | |
398 | |
399 for (;;) | |
400 { | |
401 if (get_line (buffer) == EOF) | |
402 { | |
403 goto EOF_HEAD; | |
404 } | |
405 c = buffer; | |
406 if ((c = get_string (str, c)) == NULL) | |
407 continue; | |
408 if (strcmp (str, COMMENT) == 0) | |
409 { | |
410 /* for(;;){ | |
411 if(get_line(buffer) == EOF){ | |
412 goto EOF_EHAD; | |
413 } | |
414 if(buffer[0] == '\\'){ | |
415 unget_line(buffer); | |
416 break; | |
417 } | |
418 if(wnn_Strlen(file_comment) + strlen(buffer) | |
419 >= WNN_COMMENT_LEN){ | |
420 fprintf(stderr, "Too Long Comment.\n"); | |
421 exit1(); | |
422 } | |
423 wnn_Sstrcpy(file_comment + wnn_Strlen(file_comment), buffer); | |
424 } | |
425 */ | |
426 get_string (str, c); | |
427 /* | |
428 if(str[strlen(str) - 1] == '\n'){ | |
429 c[strlen(str) - 1] = '\0'; | |
430 } | |
431 */ | |
432 wnn_Sstrcpy (file_comment, str); | |
433 #ifdef CHINESE | |
434 } | |
435 else if (strcmp (str, PINYIN) == 0) | |
436 { | |
437 *which_dict = CWNN_REV_DICT; | |
438 pzy_flag = CWNN_PINYIN; | |
439 } | |
440 else if (strcmp (str, ZHUYIN) == 0) | |
441 { | |
442 *which_dict = CWNN_REV_DICT; | |
443 pzy_flag = CWNN_ZHUYIN; | |
444 } | |
445 else if (strcmp (str, BIXING) == 0) | |
446 { | |
447 *which_dict = BWNN_REV_DICT; | |
448 #endif | |
449 } | |
450 else if (strcmp (str, HINSI) == 0 | |
451 #ifdef CHINESE | |
452 || strcmp (str, CHINSI) == 0 | |
453 #endif | |
454 ) | |
455 { | |
456 for (;;) | |
457 { | |
458 if (get_line (buffer) == EOF) | |
459 { | |
460 goto EOF_HEAD; | |
461 } | |
462 if (buffer[0] == '\\' || buffer[0] == '\n') | |
463 { | |
464 unget_line (buffer); | |
465 break; | |
466 } | |
467 wnn_Sstrcpy (hinsi_list + wnn_Strlen (hinsi_list), buffer); | |
468 } | |
469 } | |
470 else if (strcmp (str, TOTAL) == 0) | |
471 { | |
472 get_string (str, c); | |
473 jt.total = atoi (str); | |
474 } | |
475 else if (strcmp (str, DIC_NO) == 0) | |
476 { /* for word_reg.c */ | |
477 get_string (str, c); | |
478 jt.total = atoi (str); | |
479 } | |
480 else | |
481 { | |
482 unget_line (buffer); | |
483 break; | |
484 } | |
485 } | |
486 EOF_HEAD: | |
487 jt.maxcomment = wnn_Strlen (file_comment); | |
488 jt.maxhinsi_list = wnn_Strlen (hinsi_list) + 1; | |
489 } | |
490 | |
491 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
492 read_ujis (int rev, int to_esc, int which_dict) |
0 | 493 { |
494 char buffer[LINE_SIZE]; | |
495 register int tmp; | |
496 | |
497 for (lc = 0; get_line (buffer) != EOF;) | |
498 { | |
499 if ((tmp = get_one_line (buffer, jeary + lc, rev, to_esc, which_dict)) == -1) | |
500 { | |
501 bad_line (buffer); | |
502 } | |
503 else if (tmp == 0) | |
504 { /* succeed */ | |
505 lc++; | |
506 if (lc > maxline) | |
507 { | |
508 error_no_heap (); | |
509 } | |
510 } | |
511 } | |
512 jt.maxserial = lc; /* i starts with 1 in order to leave 0 unused */ | |
513 #ifdef CHINESE | |
514 jt.syurui = which_dict; | |
515 #endif | |
516 } | |
517 | |
518 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
519 reverse_yomi (void) |
0 | 520 { |
521 register int i; | |
522 w_char ytmp[LINE_SIZE]; | |
523 | |
524 for (i = 0; i < jt.maxserial; i++) | |
525 { | |
526 if (jeary[i]->yomi != 0) | |
527 { /* ºï½ü¤µ¤ì¤Æ¤Ê¤¤¤â¤Î¤À¤± */ | |
528 wnn_Sreverse (ytmp, jeary[i]->yomi); | |
529 wnn_Strcpy (jeary[i]->yomi, ytmp); | |
530 wnn_Sreverse (ytmp, jeary[i]->kan); | |
531 wnn_Strcpy (jeary[i]->kan, ytmp); | |
532 } | |
533 | |
534 } | |
535 } | |
536 | |
537 extern char *wnn_get_hinsi_name (); | |
538 | |
539 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
540 print_je (register struct je *jep, register FILE *opter, int serial_out, int esc_exp) |
0 | 541 { |
542 /* if (jep->yomi != 0) { */ | |
543 if (jep->hinsi != SAKUJO_HINSI) | |
544 { | |
545 Print_entry (jep->yomi, jep->kan, jep->comm, jep->hindo, 0, jep->hinsi, serial_out ? jep->serial : -1, opter, esc_exp); | |
546 } | |
547 } | |
548 | |
549 #ifdef nodef | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
550 kprint (register FILE *fp, register w_char *kpter) |
0 | 551 { |
552 char out_str[LENGTHKANJI]; | |
553 register int out_len; | |
554 char tmp[LENGTHKANJI]; | |
555 | |
556 wnn_sStrcpy (tmp, kpter); | |
557 out_len = make_kanji_str (out_str, tmp); | |
558 fprintf (fp, "%s", out_str); | |
559 if (out_len < 8) | |
560 putc ('\t', fp); | |
561 if (out_len < 16) | |
562 putc ('\t', fp); | |
563 putc ('\t', fp); | |
564 } | |
565 #endif | |
566 | |
567 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
568 output_ujis (register FILE *opter, int serial_out, int esc_exp) |
0 | 569 { |
570 register struct je **jep; | |
571 char buffer[WNN_COMMENT_LEN + WNN_HINSI_LEN]; | |
572 register int i; | |
573 | |
574 wnn_sStrcpy (buffer, file_comment); | |
575 fprintf (opter, "%s\t%s\n", COMMENT, buffer); | |
576 fprintf (opter, "%s\t%d\n", TOTAL, jt.total); | |
577 wnn_sStrcpy (buffer, hinsi_list); | |
578 #ifdef CHINESE | |
579 fprintf (opter, "%s\n", CHINSI); | |
580 if (jt.syurui == CWNN_REV_DICT) | |
581 { | |
582 if (pzy_flag == CWNN_PINYIN) | |
583 { | |
584 fprintf (opter, "%s\n", PINYIN); | |
585 } | |
586 else | |
587 { | |
588 fprintf (opter, "%s\n", ZHUYIN); | |
589 } | |
590 } | |
591 else if (jt.syurui == BWNN_REV_DICT) | |
592 { | |
593 fprintf (opter, "%s\n", BIXING); | |
594 } | |
595 #else | |
596 fprintf (opter, "%s\n", HINSI); | |
597 #endif | |
598 fprintf (opter, "%s", buffer); | |
599 fprintf (opter, "\n"); | |
7
6ab41ec6f895
fix dtoa crash when it encounters malformed entry.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
600 for (jep = jeary, i = 0; i < jt.maxserial; i++, jep++) { |
6ab41ec6f895
fix dtoa crash when it encounters malformed entry.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
601 if (jep && opter && (*jep)->yomi) { |
6ab41ec6f895
fix dtoa crash when it encounters malformed entry.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
602 print_je (*jep, opter, serial_out, esc_exp); |
6ab41ec6f895
fix dtoa crash when it encounters malformed entry.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
603 } |
6ab41ec6f895
fix dtoa crash when it encounters malformed entry.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
604 } |
0 | 605 } |
606 | |
607 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
608 init_heap (int hpb, int yhpb, int l, int rl, FILE *ipf) |
0 | 609 { |
610 jehp = je_heap = (struct je *) malloc ((rl * sizeof (struct je))); | |
611 hp = heap = (UCHAR *) malloc (hpb); | |
612 yhp = yomi_heap = (w_char *) malloc ((yhpb * sizeof (w_char))); | |
613 if ((jeary = (struct je **) calloc (l, sizeof (struct je *))) == NULL) | |
614 { | |
615 fprintf (stderr, "Malloc Failed\n"); | |
616 return (-1); | |
617 } | |
618 ifpter = ipf; | |
619 maxline = l; | |
620 heapend = heap + hpb; | |
621 yheapend = yomi_heap + yhpb; | |
622 jeheapend = je_heap + rl; | |
623 return (0); | |
624 } | |
625 | |
626 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
627 init_jeary (void) |
0 | 628 { |
629 int k; | |
630 for (k = 0; k < jt.maxserial; k++) | |
631 { | |
632 jeary[k] = je_heap + k; | |
633 } | |
634 } | |
635 | |
636 /* test program | |
637 main() | |
638 { | |
639 yhp = yomi_heap = (w_char *)malloc(100000); | |
640 jeary = (struct je *)malloc(100000); | |
641 | |
642 ifpter = stdin; | |
643 ujis_header(); | |
644 read_ujis(); | |
645 | |
646 sort(); | |
647 uniq_je(func); | |
648 output_ujis(stdout, 0, 1); | |
649 } | |
650 */ | |
651 | |
652 void | |
653 exit1 () | |
654 { | |
655 exit (1); | |
656 } | |
657 | |
658 /* must be updated later */ | |
659 | |
660 static void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
661 bunpou_num (register char *a, register int *p) |
0 | 662 { |
663 int tmp; | |
664 if ((tmp = wnn_find_hinsi_by_name (a)) == -1) | |
665 { | |
666 if (sscanf (a, "%d", p) == 0) | |
667 { | |
668 fprintf (stderr, "Bad hinsi name \"%s\".\n", a); | |
669 exit1 (); | |
670 } | |
671 } | |
672 else | |
673 { | |
674 *p = tmp; | |
675 } | |
676 #ifdef nodef | |
677 sscanf (a, "%d", p); | |
678 #endif | |
679 } | |
680 | |
681 #ifdef CHINESE | |
682 static void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
683 sisheng_num (register char *a, register int *p) |
0 | 684 { |
685 sscanf (a, "%d", p); | |
686 } | |
687 #endif | |
688 | |
689 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
690 sort_func_je (const void *a, const void *b) |
0 | 691 { |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
692 return (sort_func ((char *)a, (char *)b, D_YOMI)); |
0 | 693 } |
694 | |
695 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
696 sort_func_je_kanji (const void *a, const void *b) |
0 | 697 { |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
698 return (sort_func ((char *)a, (char *)b, D_KANJI)); |
0 | 699 } |
700 | |
701 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
702 sort_func (register char *a, register char *b, int which) |
0 | 703 { |
704 register int tmp; | |
705 register struct je *pa, *pb; | |
706 pa = *((struct je **) a); | |
707 pb = *((struct je **) b); | |
708 if (pa->hinsi == SAKUJO_HINSI) | |
709 { | |
710 if (pb->hinsi == SAKUJO_HINSI) | |
711 return (0); | |
712 return (-1); | |
713 } | |
714 if (pb->hinsi == SAKUJO_HINSI) | |
715 return (1); | |
716 | |
717 if (which == D_YOMI) | |
718 { | |
719 | |
720 if (!(pa->yomi) || !(pb->yomi)) | |
721 return (0); | |
722 tmp = wnn_Strcmp (pa->yomi, pb->yomi); | |
723 if (tmp) | |
724 return (tmp); | |
725 | |
726 if (pa->hinsi != pb->hinsi) | |
727 { | |
728 return ((int) (pa->hinsi) - (int) (pb->hinsi)); | |
729 } | |
730 | |
731 #ifdef CHINESE | |
732 if (jt.syurui == CWNN_REV_DICT) | |
733 { | |
734 if (pa->ss != pb->ss) | |
735 { | |
736 return ((int) (pa->ss) - (int) (pb->ss)); | |
737 } | |
738 } | |
739 #endif | |
740 if (!(pa->kan) || !(pb->kan)) | |
741 return (0); | |
742 tmp = wnn_Strcmp (pa->kan, pb->kan); | |
743 if (tmp) | |
744 return (tmp); | |
745 } | |
746 else | |
747 { | |
748 if (!(pa->kan) || !(pb->kan)) | |
749 return (0); | |
750 tmp = wnn_Strcmp (pa->kan, pb->kan); | |
751 if (tmp) | |
752 return (tmp); | |
753 | |
754 if (pa->hinsi != pb->hinsi) | |
755 { | |
756 return ((int) (pa->hinsi) - (int) (pb->hinsi)); | |
757 } | |
758 #ifdef CHINESE | |
759 if (jt.syurui == CWNN_REV_DICT) | |
760 { | |
761 if (pa->ss != pb->ss) | |
762 { | |
763 return ((int) (pa->ss) - (int) (pb->ss)); | |
764 } | |
765 } | |
766 #endif | |
767 if (!(pa->yomi) || !(pb->yomi)) | |
768 return (0); | |
769 tmp = wnn_Strcmp (pa->yomi, pb->yomi); | |
770 if (tmp) | |
771 return (tmp); | |
772 } | |
773 return (0); | |
774 } | |
775 | |
776 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
777 sort (void) |
0 | 778 { |
779 qsort ((char *) jeary, jt.maxserial, sizeof (struct je *), sort_func_je); | |
780 } | |
781 | |
782 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
783 sort_if_not_sorted (void) |
0 | 784 { |
785 if (!Sorted ((char *) jeary, jt.maxserial, sizeof (struct je *), sort_func_je)) | |
786 { | |
787 sort (); | |
788 } | |
789 } | |
790 | |
791 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
792 sort_kanji (void) |
0 | 793 { |
794 qsort ((char *) jeary, jt.maxserial, sizeof (struct je *), sort_func_je_kanji); | |
795 } | |
796 | |
797 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
798 uniq_je (int (*func) ()) |
0 | 799 { |
800 int k; | |
801 struct je **prev, **jep; | |
802 | |
803 if (jt.maxserial == 0) | |
804 return; | |
805 prev = &jeary[0]; | |
806 for (k = 1; k < jt.maxserial; k++) | |
807 { | |
808 jep = &jeary[k]; | |
809 if (func ((char *) jep, (char *) prev) == 0) | |
810 { | |
811 w_char tmp[LENGTHYOMI]; | |
812 char tmp1[LENGTHYOMI]; | |
813 char tmp2[LENGTHKANJI]; | |
814 #ifdef CHINESE | |
815 char tmp3[LENGTHKANJI]; | |
816 if (jt.syurui == BWNN_REV_DICT || jt.syurui == CWNN_REV_DICT) | |
817 { | |
818 wnn_Strcpy (tmp, (*jep)->yomi); | |
819 wnn_sStrcpy (tmp1, tmp); | |
820 wnn_Strcpy (tmp, (*jep)->kan); | |
821 wnn_sStrcpy (tmp2, tmp); | |
822 sprintf (tmp3, "%d", (*jep)->ss); | |
823 } | |
824 else | |
825 { | |
826 #endif | |
827 wnn_Sreverse (tmp, (*jep)->yomi); | |
828 wnn_sStrcpy (tmp1, tmp); | |
829 wnn_Sreverse (tmp, (*jep)->kan); | |
830 wnn_sStrcpy (tmp2, tmp); | |
831 #ifdef CHINESE | |
832 } | |
833 if (jt.syurui == CWNN_REV_DICT) | |
834 fprintf (stderr, "Entries with same yomi(%s), kanji(%s), hinsi(%s),sisheng(%s) are merged.\n", tmp1, tmp2, wnn_get_hinsi_name ((*jep)->hinsi), tmp3); | |
835 else | |
836 #endif | |
837 fprintf (stderr, "Entries with same yomi(%s), kanji(%s), hinsi(%s) are merged.\n", tmp1, tmp2, wnn_get_hinsi_name ((*jep)->hinsi)); | |
838 } | |
839 else | |
840 { | |
841 prev++; | |
842 if (prev != jep) | |
843 { | |
844 *prev = *jep; | |
845 } | |
846 } | |
847 } | |
848 prev++; | |
849 jt.maxserial = prev - &jeary[0]; | |
850 } | |
851 | |
852 #ifdef nodef | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
853 make_kanji_str (register UCHAR *o, register UCHAR *c) |
0 | 854 { |
855 register UCHAR *o0 = o; | |
856 | |
857 for (; *c; c++) | |
858 { | |
859 if (*c == '\\') | |
860 { | |
861 *o++ = '\\'; | |
862 *o++ = '\\'; | |
863 } | |
864 else if (*c > 0x20) | |
865 { | |
866 *o++ = *c; | |
867 } | |
868 else | |
869 { | |
870 sprintf (o, "\\0%o", *c); | |
871 for (; *o; o++); | |
872 } | |
873 } | |
874 *o = 0; | |
875 return (o - o0); | |
876 } | |
877 #endif | |
878 | |
879 static void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
880 read_kanji_str (register char *c, register char *o) |
0 | 881 { |
882 for (; *o; c++) | |
883 { | |
884 if (*o == '\\') | |
885 { | |
886 if (*++o == '0') | |
887 { | |
888 o += 1; | |
889 if (*o >= '0' && *o <= '7') | |
890 { | |
891 *c = (*o++ - '0'); | |
892 } | |
893 else | |
894 continue; | |
895 if (*o >= '0' && *o <= '7') | |
896 { | |
897 *c *= 8; | |
898 *c |= (*o++ - '0'); | |
899 } | |
900 else | |
901 continue; | |
902 } | |
903 else | |
904 { | |
905 *c = *o++; | |
906 } | |
907 } | |
908 else | |
909 { | |
910 *c = *o++; | |
911 } | |
912 } | |
913 *c = 0; | |
914 } | |
915 | |
916 #ifdef CHINESE | |
917 static void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
918 read_kanji_str_w (register w_char *c, register w_char *) |
0 | 919 { |
920 for (; *o; c++) | |
921 { | |
922 if (*o == (w_char) '\\') | |
923 { | |
924 if (*++o == (w_char) '0') | |
925 { | |
926 o += 1; | |
927 if (*o >= (w_char) '0' && *o <= (w_char) '7') | |
928 { | |
929 *c = (*o++ - (w_char) '0'); | |
930 } | |
931 else | |
932 continue; | |
933 if (*o >= (w_char) '0' && *o <= (w_char) '7') | |
934 { | |
935 *c *= 8; | |
936 *c |= (*o++ - (w_char) '0'); | |
937 } | |
938 else | |
939 continue; | |
940 } | |
941 else | |
942 { | |
943 *c = *o++; | |
944 } | |
945 } | |
946 else | |
947 { | |
948 *c = *o++; | |
949 } | |
950 } | |
951 *c = 0; | |
952 } | |
953 #endif | |
954 | |
955 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
956 Sorted (register char *st, register int lc, int size, int (*sort_fun) (const void *a, const void *b)) |
0 | 957 { |
958 char *dst = st + size; | |
959 for (lc--; lc > 0; lc--, st = dst, dst += size) | |
960 { | |
961 if (sort_fun (st, dst) > 0) | |
962 { | |
963 return (0); | |
964 } | |
965 } | |
966 return (1); | |
967 } | |
968 | |
969 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
970 is_katakana (register char *k, register char *y) |
0 | 971 { |
972 for (; *k && *y;) | |
973 { | |
974 if (*y == (char) 0xa1 && *k == (char) 0xa1 && *(y + 1) == (char) 0xbc && *(y + 1) == (char) 0xbc) | |
975 { /*"¡¼" */ | |
976 y += 2; | |
977 k += 2; | |
978 continue; | |
979 } | |
980 if (*y++ != (char) 0xa4 || *k++ != (char) 0xa5) | |
981 return (0); | |
982 /* be careful, char comparison. */ | |
983 if (*y++ != *k++) | |
984 { | |
985 return (0); | |
986 } | |
987 } | |
988 return (!(*k | *y)); | |
989 } | |
990 | |
991 static void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
7
diff
changeset
|
992 toesc (char *ckanji, char *cyomi) |
0 | 993 { |
994 if (strcmp (ckanji, cyomi) == 0) | |
995 { | |
996 strcpy (ckanji, DIC_HIRAGANA); | |
997 } | |
998 else if (is_katakana (ckanji, cyomi)) | |
999 { | |
1000 strcpy (ckanji, DIC_KATAKANA); | |
1001 } | |
1002 } |