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