Mercurial > freewnn
annotate Wnn/jutil/atod.c @ 28:a7ccf412ba02
more warning suppression
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sat, 06 Mar 2010 23:24:53 +0900 |
parents | c966456648ad |
children | 35bc1f2e3f14 |
rev | line source |
---|---|
0 | 1 /* |
2 * $Id: atod.c,v 1.13 2004/08/12 09:03:19 aono 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, 2004 | |
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 形式を、辞書登録可能形式, 及び固定形式辞書に変換するプログラム。 | |
34 */ | |
35 | |
36 #ifdef HAVE_CONFIG_H | |
37 # include <config.h> | |
38 #endif | |
39 | |
40 #include <stdio.h> | |
41 #include <ctype.h> | |
42 #if STDC_HEADERS | |
43 # include <stdlib.h> | |
44 # include <string.h> | |
45 #else | |
46 # if HAVE_MALLOC_H | |
47 # include <malloc.h> | |
48 # endif | |
49 # if HAVE_STRINGS_H | |
50 # include <strings.h> | |
51 # endif | |
52 #endif /* STDC_HEADERS */ | |
53 #if HAVE_UNISTD_H | |
54 # include <unistd.h> | |
55 #endif | |
56 | |
57 #include "commonhd.h" | |
58 #include "wnn_config.h" | |
59 #include "jslib.h" | |
60 #include "jh.h" | |
61 #include "jdata.h" | |
62 #ifdef CHINESE | |
63 #include "cplib.h" | |
64 #endif | |
65 #include "getopt.h" /* GNU getopt in the stock */ | |
66 #include "wnn_string.h" | |
67 #include "wnn_os.h" | |
68 | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
69 /* for prototype */ |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
70 #include "atorev.h" |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
71 #include "ujisf.h" |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
72 #include "atod.h" |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
73 |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
74 /* prototypes */ |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
75 int wnn_loadhinsi (unsigned char *fname); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
76 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:
1
diff
changeset
|
77 int little_endian (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
78 int revdic (struct JT *jtl, int match); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
79 |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
80 int Sorted (register char *st, register int lc, int size, int (*sort_fun) ()); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
81 int asshuku (); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
82 |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
83 #ifdef CHINESE |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
84 void ujis_header (int *which_dict); |
0 | 85 #else |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
86 void ujis_header (void); |
0 | 87 #endif |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
88 |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
89 void read_ujis (int rev, int to_esc, int which_dict); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
90 void uniq_je (int (*func)()); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
91 void reverse_yomi (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
92 void sort_if_not_sorted (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
93 void exit1 (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
94 |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
95 void create_rev_dict (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
96 void output_header (FILE* ofpter, struct JT* jtp, struct wnn_file_head* fhp); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
97 void udytoS (); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
98 void output_ri (FILE* ofpter); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
99 void new_pwd (); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
100 void rev_short_fun (); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
101 void rev_w_char (); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
102 |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
103 #ifdef BDIC_WRITE_CHECK |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
104 int put_n_EU_str (); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
105 #else |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
106 void put_n_EU_str (); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
107 #endif |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
108 |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
109 static void ujistoud (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
110 static void output_dic_index (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
111 static void usage (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
112 static void sdic_sort (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
113 static void ujistosd (int start_je, int level); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
114 static void not_enough_area (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
115 static void get_pwd (char* fname, char* crypted); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
116 static void output_hindo (FILE* ofpter); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
117 static void output_hinsi (FILE* ofpter); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
118 static void output_kanji (FILE* ofpter); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
119 static void rev_dic_data (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
120 static void set_pter1 (void); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
121 static void output_comment (FILE* fp); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
122 static void output_hinsi_list (FILE* fp); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
123 void upd_kanjicount (int k); |
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
124 void output_dic_data (void); |
0 | 125 |
126 /* Switcher variable between UD and SD */ | |
127 | |
128 int which_dict = WNN_REV_DICT; | |
129 #ifdef CHINESE | |
130 extern int pzy_flag; | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
131 static void output_sisheng (FILE* ofpter); |
0 | 132 #endif |
133 | |
134 /* Variables both for UD and SD */ | |
135 int reverse_dict = NORMAL; | |
136 | |
137 char *com_name; | |
138 int maxserial = MAX_ENTRIES; | |
139 int kanjicount = 0; | |
140 char outfile[LINE_SIZE]; | |
141 struct wnn_file_head file_head; | |
142 struct JT jt; | |
143 UCHAR *hostart, *hoend; /* index 2 */ | |
144 int to_esc = 0; | |
145 | |
146 /* For SD */ | |
147 #define HONTAI_PER_ENTRY 20 | |
148 int node_count = 0; | |
149 UCHAR *hopter; | |
150 | |
151 | |
152 /* For UD */ | |
153 struct uind1 *tary; /* index 1 */ | |
154 int tnum = 0; | |
155 struct uind2 *uhopter; | |
156 | |
157 char *hinsi_file_name = NULL; | |
158 | |
159 | |
160 void | |
161 init (int argc, char **argv) | |
162 { | |
163 int c; | |
164 | |
165 maxserial = MAX_ENTRIES; | |
166 while ((c = getopt (argc, argv, "SURrs:P:p:Nneh:")) != EOF) | |
167 { | |
168 switch (c) | |
169 { | |
170 case 'S': | |
171 which_dict = WNN_STATIC_DICT; | |
172 break; | |
173 case 'U': | |
174 which_dict = WNN_UD_DICT; | |
175 break; | |
176 case 'R': | |
177 which_dict = WNN_REV_DICT; | |
178 break; | |
179 case 'r': | |
180 reverse_dict = REVERSE; | |
181 break; | |
182 case 'P': | |
183 get_pwd (optarg, file_head.file_passwd); | |
184 break; | |
185 case 'p': | |
186 get_pwd (optarg, jt.hpasswd); | |
187 break; | |
188 case 'N': | |
189 strcpy (file_head.file_passwd, "*"); | |
190 break; | |
191 case 'n': | |
192 strcpy (jt.hpasswd, "*"); | |
193 break; | |
194 case 'e': | |
195 to_esc = 1; | |
196 break; | |
197 case 'h': | |
198 hinsi_file_name = optarg; | |
199 break; | |
200 case 's': | |
201 if (sscanf (optarg, "%d", &maxserial) == 0) | |
202 { | |
203 usage (); | |
204 exit (1); | |
205 } | |
206 break; | |
207 } | |
208 } | |
209 if (to_esc && which_dict == WNN_REV_DICT) | |
210 { | |
211 fprintf (stderr, "You can't make the kanji component of reverse dictionary compact.\n"); | |
212 exit (1); | |
213 } | |
214 if (optind) | |
215 { | |
216 optind--; | |
217 argc -= optind; | |
218 argv += optind; | |
219 } | |
220 if (argc != 2) | |
221 { | |
222 usage (); | |
223 exit (1); | |
224 } | |
225 strncpy (outfile, argv[1], LINE_SIZE-1); | |
226 outfile[LINE_SIZE-1] = '\0'; | |
28
a7ccf412ba02
more warning suppression
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
22
diff
changeset
|
227 if (wnn_loadhinsi ((unsigned char *)hinsi_file_name) != 0) |
0 | 228 { |
229 fprintf (stderr, "Can't Open hinsi_file.\n"); | |
230 exit (1); | |
231 } | |
232 if (init_heap (DEF_ENTRIES * HEAP_PER_LINE, DEF_ENTRIES * YOMI_PER_LINE, maxserial, DEF_ENTRIES, stdin) == -1) | |
233 exit (1); | |
234 } | |
235 | |
236 void | |
237 alloc_area (void) | |
238 { | |
239 if (which_dict == WNN_STATIC_DICT) | |
240 { | |
241 if ((hostart = (UCHAR *) malloc (maxserial * HONTAI_PER_ENTRY)) == NULL) | |
242 { | |
243 fprintf (stderr, "Malloc Failed\n"); | |
244 exit (1); | |
245 } | |
246 hopter = hostart; | |
247 hoend = (UCHAR *) hostart + maxserial * HONTAI_PER_ENTRY; | |
248 } | |
249 else | |
250 { | |
251 if ((tary = (struct uind1 *) malloc (jt.maxserial * sizeof (struct uind1))) == NULL || | |
252 /* Too large? */ | |
253 (hostart = (UCHAR *) malloc (jt.maxserial * (sizeof (struct uind2) + sizeof (w_char) * 2))) == NULL) | |
254 { | |
255 /* 2 must be enough? */ | |
256 fprintf (stderr, "Malloc Failed\n"); | |
257 exit (1); | |
258 } | |
259 hoend = (UCHAR *) ((char *) hostart + jt.maxserial * (sizeof (struct uind2) + sizeof (w_char) * 2)); | |
260 } | |
261 } | |
262 | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
263 int sort_func_sdic (const void* a, const void* b); |
0 | 264 FILE *ofpter; |
265 | |
266 int | |
267 main (int argc, char** argv) | |
268 { | |
269 char *cswidth_name; | |
270 extern char *get_cswidth_name (); | |
271 extern void set_cswidth (); | |
272 | |
273 com_name = argv[0]; | |
274 init (argc, argv); | |
275 | |
28
a7ccf412ba02
more warning suppression
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
22
diff
changeset
|
276 if ((cswidth_name = get_cswidth_name (WNN_DEFAULT_LANG))) |
0 | 277 set_cswidth (create_cswidth (cswidth_name)); |
278 | |
279 #ifdef CHINESE | |
280 ujis_header (&which_dict); /* read header of UJIS dic */ | |
281 #else | |
282 ujis_header (); /* read header of UJIS dic */ | |
283 #endif | |
284 /* like comment,total,hinsi */ | |
285 #ifdef CHINESE | |
286 read_ujis (reverse_dict, to_esc, which_dict); | |
287 | |
288 if (which_dict != CWNN_REV_DICT && which_dict != BWNN_REV_DICT) | |
289 reverse_yomi (); | |
290 #else | |
291 read_ujis (reverse_dict, to_esc, (which_dict == WNN_REV_DICT) ? 1 : 0); | |
292 #ifndef CONVERT_from_TOP | |
293 reverse_yomi (); | |
294 #endif | |
295 #endif | |
296 | |
297 if ((ofpter = fopen (outfile, "w")) == NULL) | |
298 { | |
299 fprintf (stderr, "Can't open the output file %s.\n", outfile); | |
300 perror (""); | |
301 exit (1); | |
302 } | |
303 | |
304 #ifdef CHINESE | |
305 if ((which_dict & 0xff) == WNN_REV_DICT) | |
306 { | |
307 #else | |
308 if (which_dict == WNN_REV_DICT) | |
309 { | |
310 #endif | |
311 create_rev_dict (); | |
312 } | |
313 else | |
314 { | |
315 alloc_area (); | |
316 if (which_dict == WNN_STATIC_DICT) | |
317 { | |
318 sdic_sort (); | |
319 uniq_je (sort_func_sdic); | |
320 output_dic_data (); | |
321 ujistosd (0, 0); | |
322 } | |
323 else | |
324 { | |
325 sort_if_not_sorted (); | |
326 uniq_je (sort_func_je); | |
327 output_dic_data (); | |
328 ujistoud (); | |
329 set_pter1 (); | |
330 } | |
331 } | |
332 output_dic_index (); | |
333 rewind (ofpter); | |
334 output_header (ofpter, &jt, &file_head); | |
335 #ifdef nodef | |
336 output_comment (ofpter); /* In order to change the byte order */ | |
337 output_hinsi_list (ofpter); /* In order to change the byte order */ | |
338 #endif | |
339 exit (0); | |
340 } | |
341 | |
342 | |
343 w_char * | |
344 addyomient (int tn, w_char* yomi) | |
345 { | |
346 int len = wnn_Strlen (yomi); | |
347 tary[tn].yomi2 = 0; | |
348 tary[tn].yomi1 = yomi[0] << 16; | |
349 | |
350 uhopter->yomi[0] = len; | |
351 if (yomi[1]) | |
352 { | |
353 tary[tn].yomi1 |= yomi[1]; | |
354 if (yomi[2]) | |
355 { | |
356 tary[tn].yomi2 = yomi[2] << 16; | |
357 if (yomi[3]) | |
358 { | |
359 tary[tn].yomi2 |= yomi[3]; | |
360 } | |
361 if (len > 4) | |
362 { | |
363 wnn_Strncpy (uhopter->yomi + 1, yomi + 4, len - 4); | |
364 return (uhopter->yomi + 1 + len - 4); | |
365 } | |
366 } | |
367 } | |
368 return (uhopter->yomi + 1); | |
369 } | |
370 | |
371 static void | |
372 ujistoud (void) | |
373 { | |
374 w_char *yomi; | |
375 w_char dummy = 0; /* 2 byte yomi */ | |
376 w_char *pyomi; /* maeno tangono yomi */ | |
377 w_char *wcp; | |
378 int serial_count; | |
379 w_char *kosuup = NULL; | |
380 | |
381 *(int *) hostart = 0; | |
382 uhopter = (struct uind2 *) ((int *) hostart + 1); | |
383 | |
384 yomi = &dummy; | |
385 | |
386 for (serial_count = 0; serial_count < jt.maxserial; serial_count++) | |
387 { | |
388 pyomi = yomi; | |
389 yomi = jeary[serial_count]->yomi; | |
390 | |
391 if (wnn_Strcmp (yomi, pyomi)) | |
392 { | |
393 tary[tnum++].pter = (char *) uhopter - (char *) hostart; | |
394 uhopter->next = 0; | |
395 uhopter->serial = serial_count; | |
396 uhopter->kanjipter = kanjicount; | |
397 uhopter->kosuu = 1; | |
398 kosuup = &uhopter->kosuu; | |
399 wcp = addyomient (tnum - 1, yomi); | |
400 uhopter = (struct uind2 *) (AL_INT (wcp)); | |
401 } | |
402 else | |
403 { | |
404 if (kosuup) | |
405 *kosuup += 1; | |
406 } | |
407 upd_kanjicount (serial_count); | |
408 } | |
409 } | |
410 | |
411 void | |
412 upd_kanjicount (int k) | |
413 { | |
414 kanjicount += *jeary[k]->kanji; | |
415 } | |
416 | |
417 static void | |
418 set_pter1 (void) | |
419 { | |
420 int k; | |
421 int len; | |
422 w_char oyomi[LENGTHYOMI], nyomi[LENGTHYOMI]; | |
423 /* May be a little slow, but simple! */ | |
424 int lasts[LENGTHYOMI]; /* pter_to */ | |
425 | |
426 for (k = 0; k < LENGTHYOMI; k++) | |
427 { | |
428 lasts[k] = -1; | |
429 } | |
430 | |
431 for (k = 0; k < tnum; k++) | |
432 { | |
433 len = ((struct uind2 *) ((char *) hostart + tary[k].pter))->yomi[0]; | |
434 lasts[len] = k; | |
435 for (len--; len; len--) | |
436 { | |
437 if (lasts[len] >= 0) | |
438 { | |
439 udytoS (oyomi, lasts[len], hostart, tary); | |
440 udytoS (nyomi, k, hostart, tary); | |
441 if (wnn_Substr (oyomi, nyomi)) | |
442 { | |
443 tary[k].pter1 = lasts[len]; | |
444 break; | |
445 } | |
446 } | |
447 } | |
448 if (len == 0) | |
449 tary[k].pter1 = -1; | |
450 } | |
451 } | |
452 | |
453 void | |
454 output_dic_data (void) | |
455 { | |
456 | |
457 fprintf (stderr, "%d words are in this dictionary\n", jt.maxserial); | |
458 | |
459 if (little_endian ()) | |
460 { | |
461 rev_dic_data (); | |
462 } | |
463 | |
464 jt.syurui = which_dict; | |
465 jt.gosuu = jt.maxserial; | |
466 output_header (ofpter, &jt, &file_head); /* dummy; Will be rewitten. */ | |
467 output_comment (ofpter); | |
468 output_hinsi_list (ofpter); | |
469 output_hindo (ofpter); | |
470 output_hinsi (ofpter); | |
471 #ifdef CONVERT_with_SiSheng | |
472 if (which_dict == CWNN_REV_DICT) | |
473 output_sisheng (ofpter); | |
474 #endif | |
475 output_kanji (ofpter); | |
476 } | |
477 | |
478 static void | |
479 output_dic_index (void) | |
480 { | |
481 if (which_dict == WNN_UD_DICT) | |
482 { | |
483 fprintf (stderr, " tnum = %d\n ind2= %d\n kanji = %d\n", tnum, (char *) uhopter - (char *) hostart, kanjicount); | |
484 jt.maxtable = tnum; | |
485 jt.maxhontai = (char *) uhopter - (char *) hostart; | |
486 jt.maxri2 = jt.maxri1[D_YOMI] = jt.maxri1[D_KANJI] = 0; | |
487 jt.hontai = hostart; | |
488 jt.table = tary; | |
489 jt.ri1[D_YOMI] = NULL; | |
490 jt.ri1[D_KANJI] = NULL; | |
491 jt.ri2 = NULL; | |
492 #ifdef CHINESE | |
493 } | |
494 else if ((which_dict & 0xff) == WNN_REV_DICT) | |
495 { | |
496 #else | |
497 } | |
498 else if (which_dict == WNN_REV_DICT) | |
499 { | |
500 #endif | |
501 fprintf (stderr, "kanji = %d\n", kanjicount); | |
502 jt.maxtable = 0; | |
503 jt.maxhontai = 0; | |
504 jt.maxri2 = jt.maxserial; | |
505 jt.hontai = NULL; | |
506 jt.table = NULL; | |
507 /* jt.ri1, jt.ri2 is set in create_rev_dict */ | |
508 } | |
509 else | |
510 { | |
511 fprintf (stderr, "node_count = %d ind= %d\n kanji = %d\n", node_count, (char *) hopter - (char *) hostart, kanjicount); | |
512 jt.maxtable = 0; | |
513 jt.maxhontai = (char *) hopter - (char *) hostart; | |
514 jt.maxri2 = jt.maxri1[D_YOMI] = jt.maxri1[D_KANJI] = 0; | |
515 jt.hontai = hostart; | |
516 jt.table = NULL; | |
517 jt.ri1[D_YOMI] = NULL; | |
518 jt.ri1[D_KANJI] = NULL; | |
519 jt.ri2 = NULL; | |
520 } | |
521 jt.maxkanji = kanjicount; | |
522 | |
523 if (little_endian ()) | |
524 { | |
525 revdic (&jt, 1); | |
526 } | |
527 | |
528 if (which_dict == WNN_UD_DICT) | |
529 { | |
530 fwrite ((char *) tary, sizeof (struct uind1), tnum, ofpter); | |
531 fwrite (hostart, 1, (char *) uhopter - (char *) hostart, ofpter); | |
532 #ifdef CHINESE | |
533 } | |
534 else if ((which_dict & 0xff) == WNN_REV_DICT) | |
535 { | |
536 #else | |
537 } | |
538 else if (which_dict == WNN_REV_DICT) | |
539 { | |
540 #endif | |
541 output_ri (ofpter); | |
542 } | |
543 else | |
544 { | |
545 fwrite (hostart, 1, (char *) hopter - (char *) hostart, ofpter); | |
546 } | |
547 } | |
548 | |
549 | |
550 static void | |
551 usage (void) | |
552 { | |
553 fprintf (stderr, "Usage : %s [-r -R -S -U -e -s maximum word count(default %d) -P passwd (or -N) -p hindo_passwd (or -n) -h hinsi_file_name] <dictonary filename>\n", com_name, MAX_ENTRIES); | |
554 fprintf (stderr, "Input the ascii dictionary from stdin\n"); | |
555 fprintf (stderr, "-r is for creating dictionary with normal and reverse index\n"); | |
556 fprintf (stderr, "-R is for creating reverse (implies updatable) dictionary. (default)\n"); | |
557 fprintf (stderr, "-S is for creating static dictionary.\n"); | |
558 fprintf (stderr, "-U is for creating updatable dictionary.\n"); | |
559 fprintf (stderr, "-e is for compacting kanji string.\n"); | |
560 exit1 (); | |
561 } | |
562 | |
563 /* SD commands */ | |
564 | |
565 int | |
566 yStrcmp (w_char* a, w_char*b) | |
567 { | |
568 register int c, d; | |
569 for (; *a && *a == *b; a++, b++); | |
570 if (*a == 0) | |
571 return (-(int) *b); | |
572 if (*b == 0) | |
573 return ((int) *a); | |
574 c = *(a + 1); | |
575 d = *(b + 1); | |
576 if (c == 0 && d == 0) | |
577 return ((int) *a - (int) *b); | |
578 if (c == 0) | |
579 return (-1); | |
580 if (d == 0) | |
581 return (1); | |
582 return ((int) *a - (int) *b); | |
583 } | |
584 | |
585 int | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
586 sort_func_sdic (const void *a, const void *b) |
0 | 587 { |
588 int tmp; | |
589 struct je *pa, *pb; | |
590 pa = *((struct je **) a); | |
591 pb = *((struct je **) b); | |
592 tmp = yStrcmp (pa->yomi, pb->yomi); | |
593 if (tmp) | |
594 return (tmp); | |
595 /* Changed the order to sort, from yomi->kanji->hinsi | |
596 * to yomi->hinsi->kanji, in order to separate (struct jdata) by | |
597 * hinsi'es. | |
598 */ | |
599 if (pa->hinsi != pb->hinsi) | |
600 return ((int) (pa->hinsi) - (int) (pb->hinsi)); | |
601 return (wnn_Strcmp (pa->kan, pb->kan)); | |
602 } | |
603 | |
604 | |
605 static void | |
606 sdic_sort (void) | |
607 { | |
608 if (!Sorted ((char *) jeary, (int) jt.maxserial, sizeof (struct je *), sort_func_sdic)) | |
609 { | |
610 qsort ((char *) jeary, (int) jt.maxserial, sizeof (struct je *), sort_func_sdic); | |
611 } | |
612 } | |
613 | |
614 | |
615 static w_char chartable[YOMI_KINDS]; | |
616 static w_char numtable1[YOMI_KINDS]; | |
617 static w_char *numtable = numtable1 + 1; | |
618 static int endt = 0; | |
619 | |
620 int | |
621 analize_size (int start_je, int level, | |
622 int* statep, int* end_jep, int* mid_jep) | |
623 { | |
624 w_char *c = jeary[start_je]->yomi; | |
625 int je; | |
626 int level1 = level + 1; | |
627 int end_je, mid_je; | |
628 w_char y1, y2; | |
629 int je1, je2; | |
630 | |
631 for (; endt-- > 0;) | |
632 { | |
633 chartable[endt] = numtable[endt] = 0; | |
634 } | |
635 endt = 0; /* This line is needed when endt is originally 0 */ | |
636 for (je = start_je; je < jt.maxserial && wnn_Strncmp (c, jeary[je]->yomi, level) == 0 && jeary[je]->yomi[level1] == 0; je++); | |
637 *mid_jep = mid_je = je; | |
638 for (je = start_je; je < jt.maxserial && wnn_Strncmp (c, jeary[je]->yomi, level) == 0; je++); | |
639 *end_jep = end_je = je; | |
640 | |
641 je1 = start_je; | |
642 je2 = mid_je; | |
643 y1 = (je1 >= mid_je) ? 0xffff : jeary[je1]->yomi[level]; | |
644 y2 = (je2 >= end_je) ? 0xffff : jeary[je2]->yomi[level]; | |
645 for (;;) | |
646 { | |
647 if (y1 > y2) | |
648 { | |
649 chartable[endt] = y2; | |
650 for (numtable[endt] = numtable[endt - 1]; je2 < end_je && jeary[je2]->yomi[level] == y2; je2++); | |
651 y2 = (je2 >= end_je) ? 0xffff : jeary[je2]->yomi[level]; | |
652 endt++; | |
653 } | |
654 else if (y1 < y2) | |
655 { | |
656 chartable[endt] = y1; | |
657 for (numtable[endt] = numtable[endt - 1]; je1 < end_je && jeary[je1]->yomi[level] == y1; je1++, numtable[endt]++); | |
658 y1 = (je1 >= mid_je) ? 0xffff : jeary[je1]->yomi[level]; | |
659 endt++; | |
660 } | |
661 else | |
662 { | |
663 if (y1 >= 0xffff && y2 >= 0xffff) | |
664 break; | |
665 chartable[endt] = y1; | |
666 for (; je2 < end_je && jeary[je2]->yomi[level] == y2; je2++); | |
667 for (numtable[endt] = numtable[endt - 1]; je1 < mid_je && jeary[je1]->yomi[level] == y1; je1++, numtable[endt]++); | |
668 y2 = (je2 >= end_je) ? 0xffff : jeary[je2]->yomi[level]; | |
669 y1 = (je1 >= mid_je) ? 0xffff : jeary[je1]->yomi[level]; | |
670 endt++; | |
671 } | |
672 } | |
673 if (mid_je == start_je) | |
674 { | |
675 if (endt == 1) | |
676 *statep = ST_SMALL; | |
677 else | |
678 *statep = ST_NOENT; | |
679 } | |
680 else if (mid_je == end_je) | |
681 *statep = ST_NOPTER; | |
682 else | |
683 *statep = ST_NORMAL; | |
684 | |
685 return (endt); | |
686 } | |
687 | |
688 | |
689 | |
690 static void | |
691 ujistosd (int start_je, int level) | |
692 { | |
693 int state; | |
694 int tsize; | |
695 w_char *charst; | |
696 w_char *sumst; | |
697 int *ptrst; | |
698 int mid_je, end_je; | |
699 int je; | |
700 int k; | |
701 | |
702 node_count++; | |
703 | |
704 tsize = analize_size (start_je, level, &state, &end_je, &mid_je); | |
705 | |
706 *(w_char *) hopter = state; | |
707 hopter += 2; | |
708 switch (state) | |
709 { | |
710 case ST_NORMAL: | |
711 if (hopter + tsize * 8 + 12 + 16 >= hoend) | |
712 not_enough_area (); | |
713 *(w_char *) hopter = tsize; | |
714 hopter += 2; | |
715 *(int *) hopter = start_je; | |
716 hopter += 4; | |
717 *(int *) hopter = kanjicount; | |
718 hopter += 4; | |
719 charst = (w_char *) hopter; | |
720 sumst = ((w_char *) hopter + tsize + 2); /* + 2 keeps two zero words */ | |
721 charst[tsize] = charst[tsize + 1] = 0; | |
722 ptrst = (int *) ((w_char *) sumst + tsize); | |
723 hopter = (UCHAR *) (ptrst + tsize); | |
724 for (k = 0; k < tsize; k++) | |
725 { | |
726 charst[k] = chartable[k]; | |
727 sumst[k] = numtable[k]; | |
728 } | |
729 for (k = start_je; k < mid_je; k++) | |
730 { | |
731 upd_kanjicount (k); | |
732 } | |
733 for (je = mid_je, k = 0; je < end_je;) | |
734 { | |
735 for (; k < tsize && charst[k] < jeary[je]->yomi[level]; k++) | |
736 ptrst[k] = ENDPTR; | |
737 if (k == tsize) | |
738 fprintf (stderr, "Error\n"); | |
739 ptrst[k] = (char *) hopter - (char *) hostart; | |
740 ujistosd (je, level + 1); | |
741 for (; je < end_je && jeary[je]->yomi[level] == charst[k]; je++); | |
742 k++; | |
743 } | |
744 break; | |
745 case ST_NOENT: | |
746 if (hopter + tsize * 8 + 4 + 16 >= hoend) | |
747 not_enough_area (); | |
748 *(w_char *) hopter = tsize; | |
749 hopter += 2; | |
750 charst = (w_char *) hopter; | |
751 ptrst = (int *) AL_INT ((w_char *) charst + tsize); | |
752 hopter = (UCHAR *) (ptrst + tsize); | |
753 for (k = 0; k < tsize; k++) | |
754 { | |
755 charst[k] = chartable[k]; | |
756 } | |
757 for (je = mid_je, k = 0; je < end_je;) | |
758 { | |
759 for (; k < tsize && charst[k] < (jeary[je]->yomi)[level]; k++) | |
760 ptrst[k] = ENDPTR; | |
761 if (k == tsize) | |
762 fprintf (stderr, "Error\n"); | |
763 ptrst[k] = (char *) hopter - (char *) hostart; | |
764 ujistosd (je, level + 1); | |
765 for (; je < end_je && (jeary[je]->yomi)[level] == charst[k]; je++); | |
766 k++; | |
767 } | |
768 break; | |
769 case ST_NOPTER: | |
770 if (hopter + tsize * 4 + 12 + 16 >= hoend) | |
771 not_enough_area (); | |
772 *(w_char *) hopter = tsize; | |
773 hopter += 2; | |
774 *(int *) hopter = start_je; | |
775 hopter += 4; | |
776 *(int *) hopter = kanjicount; | |
777 hopter += 4; | |
778 charst = (w_char *) hopter; | |
779 sumst = ((w_char *) hopter + tsize + 2); /* + 2 keeps two zero words */ | |
780 charst[tsize] = charst[tsize + 1] = 0; | |
781 hopter = (UCHAR *) ((w_char *) sumst + tsize); | |
782 for (k = 0; k < tsize; k++) | |
783 { | |
784 charst[k] = chartable[k]; | |
785 sumst[k] = numtable[k]; | |
786 } | |
787 for (k = start_je; k < mid_je; k++) | |
788 { | |
789 upd_kanjicount (k); | |
790 } | |
791 break; | |
792 case ST_SMALL: | |
793 if (hopter + 4 + 16 >= hoend) | |
794 not_enough_area (); | |
795 *(w_char *) hopter = chartable[0]; | |
796 hopter += 2; | |
797 ujistosd (start_je, level + 1); | |
798 break; | |
799 } | |
800 } | |
801 | |
802 #define INCR_HO 150 | |
803 | |
804 static void | |
805 not_enough_area (void) | |
806 { | |
807 /* | |
808 UCHAR *oldstart = hostart; | |
809 int size = hoend - hostart + INCR_HO * HONTAI_PER_ENTRY; | |
810 */ | |
811 fprintf (stderr, "Sorry allocated area is exhausted.node_count = %d\n", node_count); | |
812 fprintf (stderr, "Retry with option -S <dict_size>.\n"); | |
813 exit (1); | |
814 | |
815 /* | |
816 * Only for Sdic | |
817 * Can't Realloc!! many pointeres exist on the stack!! | |
818 */ | |
819 | |
820 /* | |
821 fprintf(stderr, "Realloc.\n"); | |
822 if((hostart = (char *)realloc(hostart, size)) == NULL){ | |
823 fprintf(stderr, "Ralloc Failed\n"); | |
824 exit(1); | |
825 } | |
826 hopter = hostart + (hopter - oldstart); | |
827 hoend = (char *)((char *)hostart + size); | |
828 */ | |
829 } | |
830 | |
831 | |
832 static void | |
833 get_pwd (char* fname, char* crypted) | |
834 { | |
835 char pwd[WNN_PASSWD_LEN]; | |
836 FILE *fp; | |
837 | |
838 if ((fp = fopen (fname, "r")) == NULL) | |
839 { | |
840 fprintf (stderr, "No password_file %s.\n", fname); | |
841 exit (1); | |
842 } | |
843 fgets (pwd, WNN_PASSWD_LEN, fp); | |
844 fclose (fp); | |
845 new_pwd (pwd, crypted); | |
846 } | |
847 | |
848 /* output dict routine's */ | |
849 static void | |
850 output_comment (FILE* fp) | |
851 { | |
852 put_n_EU_str (fp, file_comment, jt.maxcomment); | |
853 } | |
854 | |
855 static void | |
856 output_hinsi_list (FILE* fp) | |
857 { | |
858 put_n_EU_str (fp, hinsi_list, jt.maxhinsi_list); | |
859 } | |
860 | |
861 static void | |
862 output_hindo (FILE* ofpter) | |
863 { | |
864 register int i; | |
865 for (i = 0; i < jt.maxserial; i++) | |
866 { | |
867 putc (asshuku (jeary[i]->hindo), ofpter); | |
868 } | |
869 } | |
870 | |
871 static void | |
872 output_hinsi (FILE* ofpter) | |
873 { | |
874 int i; | |
875 short k; | |
876 int little_endianp = little_endian (); | |
877 /* hinsi ha koko de hikkuri kaesu */ | |
878 | |
879 for (i = 0; i < jt.maxserial; i++) | |
880 { | |
881 k = jeary[i]->hinsi; | |
882 if (little_endianp) | |
883 { | |
884 rev_short_fun (&k); | |
885 } | |
886 fwrite (&k, 1, 2, ofpter); | |
887 } | |
888 } | |
889 | |
890 static void | |
891 output_kanji (FILE* ofpter) | |
892 { | |
893 int i; | |
894 | |
895 for (i = 0; i < jt.maxserial; i++) | |
896 { | |
897 fwrite (jeary[i]->kanji, 1, *(jeary[i]->kanji), ofpter); | |
898 } | |
899 } | |
900 | |
901 static void | |
902 rev_dic_data (void) | |
903 { | |
904 int i; | |
905 | |
906 /* Comment and Hinsi list do not need to reverse. */ | |
907 for (i = 0; i < jt.maxserial; i++) | |
908 { | |
909 rev_w_char ((w_char *) (jeary[i]->kanji + 2), *(jeary[i]->kanji) / 2 - 1); | |
910 } | |
911 } | |
912 | |
913 #ifdef CONVERT_with_SiSheng | |
914 extern void put_short (); | |
915 | |
916 static void | |
917 output_sisheng (FILE* ofpter) | |
918 { | |
919 int i; | |
920 | |
921 for (i = 0; i < jt.maxserial; i++) | |
922 { | |
923 put_short (ofpter, jeary[i]->ss); | |
924 } | |
925 } | |
926 #endif /* CONVERT_with_SiSheng */ |