Mercurial > freewnn
annotate Wnn/jutil/dtoa.c @ 28:a7ccf412ba02
more warning suppression
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sat, 06 Mar 2010 23:24:53 +0900 |
parents | c966456648ad |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * $Id: dtoa.c,v 1.9 2005/06/12 17:14:23 aonoto Exp $ | |
3 */ | |
4 | |
5 /* | |
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system. | |
7 * This file is part of FreeWnn. | |
8 * | |
9 * Copyright Kyoto University Research Institute for Mathematical Sciences | |
10 * 1987, 1988, 1989, 1990, 1991, 1992 | |
11 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999 | |
12 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992 | |
13 * Copyright FreeWnn Project 1999, 2000, 2002, 2005 | |
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 辞書を ASCII 形式の辞書に変換するプログラム。 | |
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 #if HAVE_UNISTD_H | |
53 # include <unistd.h> | |
54 #endif | |
55 | |
56 #include "commonhd.h" | |
57 #include "wnn_config.h" | |
58 #include "jslib.h" | |
59 #include "jh.h" | |
60 #include "jdata.h" | |
61 #include "wnn_string.h" | |
62 #include "wnn_os.h" | |
63 | |
64 #ifdef CONVERT_with_SiSheng | |
65 #include "cplib.h" | |
66 extern int pzy_flag; /* Pinyin or Zhuyin */ | |
67 #endif | |
68 | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
69 /* prototypes */ |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
70 void parse_options(int *argc, char ***argv); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
71 void usage(void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
72 void input_dic(FILE *ifpter); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
73 void udtoujis(void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
74 void kset(void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
75 void sdtoujis(char *hopter, register int level); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
76 void ghindo (int argc, char **argv); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
77 int input_comment (register FILE *fp); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
78 int input_hinsi_list (register FILE *fp); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
79 static int rdtoujis (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
80 static int set_hinsi (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
81 static int input_hindo (register FILE *ifpter); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
82 static int add_hindo (register FILE *ifpter, int num); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
83 |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
84 /* extern */ |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
85 void sort (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
86 void output_ujis (register FILE *opter, int serial_out, int esc_exp); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
87 void exit1 (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
88 void init_jeary (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
89 void get_kanji_str (UCHAR* kptr, w_char* kanji, w_char* yomi, w_char* comment); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
90 |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
91 int input_header (FILE* ifpter, struct JT* jtp, struct wnn_file_head* fhp); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
92 int little_endian (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
93 int revdic (struct JT *jtl, int match); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
94 int wnn_loadhinsi (unsigned char *fname); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
95 int w_stradd (register w_char *str, register w_char **cp); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
96 int motoni2 (int hin); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
97 int init_heap (int hpb, int yhpb, int l, int rl, FILE *ipf); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
98 int input_hindo_header (FILE* ifpter, struct HJT* hjtp, struct wnn_file_head* fhp); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
99 |
0 | 100 #ifdef CONVERT_with_SiSheng |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
101 int cwnn_yincod_pzy (register w_char *pzy_buf, register w_char c, int which); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
102 int input_sisheng (register FILE *ifpter); |
0 | 103 #endif |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
104 |
0 | 105 /* Moved from Wnn/etc/bdic.c */ |
106 int get_n_EU_str (FILE* ifpter, int n, w_char* st); | |
107 int get_short (short* sp, FILE* ifpter); | |
108 | |
109 int which_dict; | |
110 | |
111 char *com_name; | |
112 char infile[LINE_SIZE]; | |
113 int esc_expand = 1; | |
114 | |
115 int serial_out = 0; | |
116 int need_sort = 1; | |
117 struct JT jt; | |
118 struct wnn_file_head file_head; | |
119 | |
120 char *hinsi_file_name = NULL; | |
121 | |
122 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
123 main (int argc, char **argv) |
0 | 124 { |
125 FILE *ifpter; | |
126 char *cswidth_name; | |
127 extern char *get_cswidth_name (); | |
128 extern void set_cswidth (); | |
129 | |
130 com_name = argv[0]; | |
131 | |
28
a7ccf412ba02
more warning suppression
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
22
diff
changeset
|
132 if ((cswidth_name = get_cswidth_name (WNN_DEFAULT_LANG))) |
0 | 133 set_cswidth (create_cswidth (cswidth_name)); |
134 parse_options (&argc, &argv); | |
135 | |
136 if ((ifpter = fopen (infile, "r")) == NULL) | |
137 { | |
138 fprintf (stderr, "Can't open the input file %s.\n", infile); | |
139 perror (""); | |
140 exit (1); | |
141 } | |
142 if (input_header (ifpter, &jt, &file_head) == -1) | |
143 exit (1); | |
144 which_dict = jt.syurui; | |
145 input_comment (ifpter); | |
146 input_hinsi_list (ifpter); | |
147 input_dic (ifpter); | |
148 if (little_endian ()) | |
149 { | |
150 revdic (&jt, 0); | |
151 } | |
152 set_hinsi (); | |
153 ghindo (argc - 2, argv + 2); /* Gather Hindo */ | |
154 if (which_dict == WNN_STATIC_DICT) | |
155 { | |
156 kset (); | |
28
a7ccf412ba02
more warning suppression
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
22
diff
changeset
|
157 sdtoujis ((char *)jt.hontai, 0); |
0 | 158 #ifdef CHINESE |
159 } | |
160 else if ((which_dict & 0x00ff) == WNN_REV_DICT) | |
161 { | |
162 #else | |
163 } | |
164 else if (which_dict == WNN_REV_DICT) | |
165 { | |
166 #endif | |
167 rdtoujis (); | |
168 } | |
169 else | |
170 { | |
171 udtoujis (); | |
172 } | |
173 if (need_sort) | |
174 { | |
175 sort (); | |
176 } | |
177 output_ujis (stdout, serial_out, esc_expand); | |
178 exit (0); | |
179 } | |
180 | |
181 | |
182 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
183 parse_options (int *argc, char ***argv) |
0 | 184 { |
185 int c; | |
186 extern int optind; | |
187 extern char *optarg; | |
188 | |
189 #ifdef CONVERT_with_SiSheng | |
190 # define OPTSTRING "nseEzh:" | |
191 #else | |
192 # define OPTSTRING "nseEh:" | |
193 #endif | |
194 | |
195 while ((c = getopt (*argc, *argv, OPTSTRING)) != EOF) | |
196 { | |
197 switch (c) | |
198 { | |
199 case 'n': | |
200 need_sort = 0; | |
201 break; | |
202 case 's': | |
203 serial_out = 1; | |
204 break; | |
205 case 'e': | |
206 esc_expand = 1; | |
207 break; | |
208 case 'E': | |
209 esc_expand = 0; | |
210 break; | |
211 case 'h': | |
212 hinsi_file_name = optarg; | |
213 break; | |
214 #ifdef CONVERT_with_SiSheng | |
215 case 'z': | |
216 pzy_flag = CWNN_ZHUYIN; | |
217 break; | |
218 #endif | |
219 default: | |
220 usage (); | |
221 } | |
222 } | |
223 if (optind) | |
224 { | |
225 optind--; | |
226 *argc -= optind; | |
227 *argv += optind; | |
228 } | |
229 if (*argc < 2) | |
230 { | |
231 usage (); | |
232 } | |
233 strcpy (infile, (*argv)[1]); | |
28
a7ccf412ba02
more warning suppression
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
22
diff
changeset
|
234 if (wnn_loadhinsi ((unsigned char *)hinsi_file_name) != 0) |
0 | 235 { |
236 fprintf (stderr, "Can't Open hinsi_file.\n"); | |
237 exit (1); | |
238 } | |
239 } | |
240 | |
241 | |
242 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
243 usage (void) |
0 | 244 { |
245 fprintf (stderr, "Usage: %s [-nse -h hinsi_file_name] <dictionary file> <hindo file>*\n", com_name); | |
246 fprintf (stderr, "Output the Text dictionary to stdout\n"); | |
247 #ifdef CONVERT_with_SiSheng | |
248 fprintf (stderr, "-z : Output Zhuyin (Default is Pinyin)\n"); | |
249 #endif | |
250 exit1 (); | |
251 } | |
252 | |
253 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
254 input_dic (FILE *ifpter) |
0 | 255 { |
256 | |
257 init_heap (0, /* jt.maxkanji, */ | |
258 jt.maxserial * YOMI_PER_LINE * 5, /* may be enough */ | |
259 jt.maxserial, jt.maxserial, stdin); | |
260 jt.table = (struct uind1 *) malloc (jt.maxtable * sizeof (struct uind1)); | |
261 jt.hontai = (UCHAR *) malloc (jt.maxhontai); | |
262 jt.ri1[D_YOMI] = (struct rind1 *) malloc (jt.maxri1[D_YOMI] * sizeof (struct rind1)); | |
263 jt.ri1[D_KANJI] = (struct rind1 *) malloc (jt.maxri1[D_KANJI] * sizeof (struct rind1)); | |
264 jt.kanji = (UCHAR *) malloc (jt.maxkanji + 1); | |
265 jt.ri2 = (struct rind2 *) malloc (jt.maxserial * sizeof (struct rind2)); | |
266 jt.hinsi = (w_char *) malloc (jt.maxserial * sizeof (w_char)); | |
267 if (!jt.table || !jt.hontai || !jt.ri1[D_YOMI] || !jt.ri1[D_KANJI] || !jt.kanji || !jt.ri2 || !jt.hinsi) | |
268 { | |
269 fprintf (stderr, "Malloc Failed.\n"); | |
270 exit (1); | |
271 } | |
272 init_jeary (); | |
273 | |
274 input_hindo (ifpter); | |
275 fread (jt.hinsi, 2, jt.maxserial, ifpter); | |
276 #ifdef CONVERT_with_SiSheng | |
277 if (which_dict == CWNN_REV_DICT) | |
278 input_sisheng (ifpter); | |
279 #endif | |
280 fread (jt.kanji, 1, jt.maxkanji, ifpter); | |
281 /* input_kanji(ifpter); */ | |
282 fread (jt.table, sizeof (struct uind1), jt.maxtable, ifpter); | |
283 fread (jt.ri1[D_YOMI], sizeof (struct rind1), jt.maxri1[D_YOMI], ifpter); | |
284 fread (jt.ri1[D_KANJI], sizeof (struct rind1), jt.maxri1[D_KANJI], ifpter); | |
285 fread (jt.hontai, 1, jt.maxhontai, ifpter); | |
286 fread (jt.ri2, sizeof (struct rind2), jt.maxserial, ifpter); | |
287 } | |
288 | |
289 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
290 udtoujis (void) |
0 | 291 { |
292 | |
293 w_char yomi[LENGTHYOMI]; /* 2 byte yomi */ | |
294 w_char kan[LENGTHYOMI]; /* 2 byte kanji */ | |
295 w_char comm[LENGTHYOMI]; | |
296 w_char ryomi[LENGTHYOMI]; | |
297 register struct uind2 *hop; | |
298 register int i, k; | |
299 register int serial; | |
300 int len; | |
301 UCHAR *c; | |
302 | |
303 for (i = 0; i < jt.maxtable; i++) | |
304 { | |
305 for (hop = (struct uind2 *) (jt.table[i].pter + (char *) jt.hontai); hop != (struct uind2 *) jt.hontai; hop = (struct uind2 *) (hop->next + (char *) jt.hontai)) | |
306 { | |
307 /* Though each hop has the same yomi, but calculate yomi each time. */ | |
308 yomi[0] = jt.table[i].yomi1 >> 16; | |
309 yomi[1] = jt.table[i].yomi1 & 0xffff; | |
310 if (yomi[1]) | |
311 { | |
312 yomi[2] = jt.table[i].yomi2 >> 16; | |
313 if (yomi[2]) | |
314 { | |
315 yomi[3] = jt.table[i].yomi2 & 0xffff; | |
316 } | |
317 } | |
318 len = hop->yomi[0]; | |
319 wnn_Strncpy (yomi + 4, (hop->yomi) + 1, len - 4); | |
320 yomi[len] = 0; | |
321 serial = hop->serial; | |
322 for (k = hop->kosuu, c = hop->kanjipter + jt.kanji; k > 0; k--, serial++) | |
323 { | |
324 get_kanji_str (c, kan, NULL, comm); | |
325 jeary[serial]->kanji = c; | |
326 c += *c; | |
327 jeary[serial]->serial = serial; | |
328 #ifdef CONVERT_with_SiSheng | |
329 wnn_Strcpy (ryomi, yomi); | |
330 #else | |
331 wnn_Sreverse (ryomi, yomi); | |
332 #endif | |
333 w_stradd (ryomi, &jeary[serial]->yomi); | |
334 w_stradd (kan, &jeary[serial]->kan); | |
335 w_stradd (comm, &jeary[serial]->comm); | |
336 } | |
337 } | |
338 } | |
339 } | |
340 | |
341 /* SD routine */ | |
342 | |
343 w_char yomi[LENGTHYOMI]; | |
344 int je = 0; | |
345 | |
346 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
347 kset (void) |
0 | 348 { |
349 int i; | |
350 UCHAR *c; | |
351 w_char kan[LENGTHYOMI]; /* 2 byte kanji */ | |
352 w_char comm[LENGTHYOMI]; /* 2 byte kanji */ | |
353 | |
354 | |
355 c = jt.kanji; | |
356 for (i = 0; i < jt.maxserial; i++) | |
357 { | |
358 get_kanji_str (c, kan, NULL, comm); | |
359 w_stradd (kan, &jeary[i]->kan); | |
360 w_stradd (comm, &jeary[i]->comm); | |
361 jeary[i]->kanji = c; | |
362 c += *c; | |
363 } | |
364 } | |
365 | |
366 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
367 sdtoujis (char *hopter, register int level) |
0 | 368 { |
369 register int k, j; | |
370 register int tsize; | |
371 register w_char *charst; | |
372 register w_char *sumst; | |
373 int *ptrst; | |
374 static w_char ry[LENGTHYOMI]; | |
375 | |
376 yomi[level + 1] = 0; | |
377 switch (*(w_char *) hopter) | |
378 { | |
379 case ST_NORMAL: | |
380 tsize = *(w_char *) (hopter + 2); | |
381 charst = (w_char *) (hopter + 12); | |
382 sumst = ((w_char *) charst + tsize + 2); /* + 2 keeps two zero words */ | |
383 ptrst = (int *) ((w_char *) sumst + tsize); | |
384 for (k = 0; k < tsize; k++) | |
385 { | |
386 j = sumst[k] - sumst[k - 1]; | |
387 if (j) | |
388 { | |
389 yomi[level] = charst[k]; | |
390 for (; j > 0; j--) | |
391 { | |
392 jeary[je]->serial = je; | |
393 #ifdef CONVERT_with_SiSheng | |
394 wnn_Strcpy (ry, yomi); | |
395 #else | |
396 wnn_Sreverse (ry, yomi); | |
397 #endif | |
398 w_stradd (ry, &jeary[je++]->yomi); | |
399 } | |
400 } | |
401 } | |
402 for (k = 0; k < tsize; k++) | |
403 { | |
404 if (ptrst[k] != ENDPTR) | |
405 { | |
406 yomi[level] = charst[k]; | |
407 sdtoujis ((char *) jt.hontai + ptrst[k], level + 1); | |
408 } | |
409 } | |
410 break; | |
411 case ST_NOENT: | |
412 tsize = *(w_char *) (hopter + 2); | |
413 charst = (w_char *) (hopter + 4); | |
414 ptrst = (int *) AL_INT ((w_char *) charst + tsize); | |
415 for (k = 0; k < tsize; k++) | |
416 { | |
417 if (ptrst[k] != ENDPTR) | |
418 { | |
419 yomi[level] = charst[k]; | |
420 sdtoujis ((char *) jt.hontai + ptrst[k], level + 1); | |
421 } | |
422 } | |
423 break; | |
424 case ST_NOPTER: | |
425 tsize = *(w_char *) (hopter + 2); | |
426 charst = (w_char *) (hopter + 12); | |
427 sumst = ((w_char *) charst + tsize + 2); /* + 2 keeps two zero words */ | |
428 for (k = 0; k < tsize; k++) | |
429 { | |
430 j = sumst[k] - sumst[k - 1]; | |
431 if (j) | |
432 { | |
433 yomi[level] = charst[k]; | |
434 for (; j > 0; j--) | |
435 { | |
436 jeary[je]->serial = je; | |
437 #ifdef CONVERT_with_SiSheng | |
438 wnn_Strcpy (ry, yomi); | |
439 #else | |
440 wnn_Sreverse (ry, yomi); | |
441 #endif | |
442 w_stradd (ry, &jeary[je++]->yomi); | |
443 } | |
444 } | |
445 } | |
446 break; | |
447 case ST_SMALL: | |
448 yomi[level] = *(w_char *) (hopter + 2); | |
449 sdtoujis (hopter + 4, level + 1); | |
450 break; | |
451 } | |
452 } | |
453 | |
454 static int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
455 rdtoujis (void) |
0 | 456 { |
457 w_char yomi[LENGTHYOMI]; /* 2 byte yomi */ | |
458 w_char kan[LENGTHYOMI]; /* 2 byte yomi */ | |
459 w_char comm[LENGTHYOMI]; /* 2 byte yomi */ | |
460 register struct rind2 *hop; | |
461 register int hopi; | |
462 register int i; | |
463 register int serial; | |
464 | |
465 for (i = 0; i < jt.maxri1[D_YOMI]; i++) | |
466 { | |
467 for (hopi = jt.ri1[D_YOMI][i].pter; hopi != RD_ENDPTR; hopi = hop->next[D_YOMI]) | |
468 { | |
469 hop = hopi + jt.ri2; | |
470 /* Though each hop has the same yomi, but calculate yomi each time. */ | |
471 get_kanji_str (hop->kanjipter + jt.kanji, kan, yomi, comm); | |
472 #ifdef CONVERT_with_SiSheng | |
473 cwnn_yincod_pzy_str (yomi, yomi, wnn_Strlen (yomi), pzy_flag); | |
474 #endif | |
475 serial = hopi; | |
476 jeary[serial]->kanji = hop->kanjipter + jt.kanji; | |
477 jeary[serial]->serial = serial; | |
478 | |
479 w_stradd (yomi, &jeary[serial]->yomi); | |
480 w_stradd (kan, &jeary[serial]->kan); | |
481 w_stradd (comm, &jeary[serial++]->comm); | |
482 } | |
483 } | |
484 return (0); | |
485 } | |
486 | |
487 void | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
488 ghindo (int argc, char **argv) |
0 | 489 { |
490 FILE *fp; | |
491 struct wnn_file_head h_file_head; | |
492 struct HJT hjt; | |
493 | |
494 | |
495 while (argc-- > 0) | |
496 { | |
497 if ((fp = fopen (*argv++, "r")) == NULL) | |
498 { | |
499 fprintf (stderr, "can't open %s\n", *(argv - 1)); | |
500 perror ("error in ghindo"); | |
501 exit (1); | |
502 } | |
503 if (input_hindo_header (fp, &hjt, &h_file_head) == -1) | |
504 { | |
505 perror ("error in ghindo 1"); | |
506 exit (1); | |
507 } | |
508 if (bcmp (&file_head.file_uniq_org, &hjt.dic_file_uniq, sizeof (struct wnn_file_uniq))) | |
509 { | |
510 fprintf (stderr, "%s(%s)Dic File and Hindo File mismatch.\n", infile, *(argv - 1)); | |
511 exit (1); | |
512 } | |
513 add_hindo (fp, hjt.maxserial); | |
514 } | |
515 } | |
516 | |
517 static int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
518 add_hindo (register FILE *ifpter, int num) |
0 | 519 { |
520 register int i; | |
521 register int k; | |
522 for (i = 0; i < num; i++) | |
523 { | |
524 jeary[i]->hindo += motoni2 ((k = getc (ifpter)) & 0x7f); | |
525 if (k == -1) | |
526 return (-1); | |
527 } | |
528 return (0); | |
529 } | |
530 | |
531 /* input dict routines */ | |
532 | |
533 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
534 input_comment (register FILE *fp) |
0 | 535 { |
536 return (get_n_EU_str (fp, jt.maxcomment, file_comment)); | |
537 } | |
538 | |
539 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
540 input_hinsi_list (register FILE *fp) |
0 | 541 { |
542 return (get_n_EU_str (fp, jt.maxhinsi_list, hinsi_list)); | |
543 } | |
544 | |
545 | |
546 static int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
547 input_hindo (register FILE *ifpter) |
0 | 548 { |
549 register int i; | |
550 register int k; | |
551 for (i = 0; i < jt.maxserial; i++) | |
552 { | |
553 jeary[i]->hindo = motoni2 ((k = getc (ifpter)) & 0x7f); | |
554 if (k == -1) | |
555 return (-1); | |
556 } | |
557 return (0); | |
558 } | |
559 | |
560 static int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
561 set_hinsi (void) |
0 | 562 { |
563 register int i; | |
564 | |
565 for (i = 0; i < jt.maxserial; i++) | |
566 { | |
567 jeary[i]->hinsi = jt.hinsi[i]; | |
568 } | |
569 return (0); | |
570 } | |
571 | |
572 #ifdef CONVERT_with_SiSheng | |
573 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
574 input_sisheng (register FILE *ifpter) |
0 | 575 { |
576 register int i; | |
577 unsigned short s; | |
578 | |
579 for (i = 0; i < jt.maxserial; i++) | |
580 { | |
581 if (get_short (&s, ifpter) == -1) | |
582 return (-1); | |
583 jeary[i]->ss = s; | |
584 } | |
585 return (0); | |
586 } | |
587 | |
588 #endif | |
589 | |
590 int | |
591 get_n_EU_str (FILE* ifpter, int n, w_char* st) | |
592 { | |
593 int k; | |
594 | |
595 for (; n; n--) | |
596 { | |
597 k = get_short ((short *) st++, ifpter); | |
598 if (k == -1) | |
599 return (-1); | |
600 } | |
601 return (0); | |
602 } | |
603 | |
604 int | |
605 get_short (short* sp, FILE* ifpter) | |
606 { | |
607 int i = 0; | |
608 int k; | |
609 | |
610 i |= (k = getc (ifpter)) << 8; | |
611 if (k == -1) | |
612 return (-1); | |
613 i |= (k = getc (ifpter)); | |
614 if (k == -1) | |
615 return (-1); | |
616 *sp = i; | |
617 return (0); | |
618 } |