|
0
|
1 /*
|
|
|
2 * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
|
|
|
3 * This file is part of FreeWnn.
|
|
|
4 *
|
|
|
5 * Copyright Kyoto University Research Institute for Mathematical Sciences
|
|
|
6 * 1987, 1988, 1989, 1990, 1991, 1992
|
|
|
7 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
|
|
|
8 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992
|
|
|
9 * Copyright FreeWnn Project 1999, 2000, 2002, 2003
|
|
|
10 *
|
|
|
11 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp>
|
|
|
12 *
|
|
|
13 * This program is free software; you can redistribute it and/or modify
|
|
|
14 * it under the terms of the GNU General Public License as published by
|
|
|
15 * the Free Software Foundation; either version 2 of the License, or
|
|
|
16 * (at your option) any later version.
|
|
|
17 *
|
|
|
18 * This program is distributed in the hope that it will be useful,
|
|
|
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
21 * GNU General Public License for more details.
|
|
|
22 *
|
|
|
23 * You should have received a copy of the GNU General Public License
|
|
|
24 * along with this program; if not, write to the Free Software
|
|
|
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
26 */
|
|
|
27
|
|
|
28 /*
|
|
|
29 (Updatable, Stable) dictionary read routine.
|
|
|
30 */
|
|
|
31
|
|
|
32 #if defined(HAVE_CONFIG_H)
|
|
|
33 #include <config.h>
|
|
|
34 #endif
|
|
|
35
|
|
|
36 #include <stdio.h>
|
|
|
37 #if STDC_HEADERS
|
|
|
38 # include <stdlib.h>
|
|
|
39 # include <string.h>
|
|
|
40 #else
|
|
|
41 # if HAVE_MALLOC_H
|
|
|
42 # include <malloc.h>
|
|
|
43 # endif
|
|
|
44 # if HAVE_STRINGS_H
|
|
|
45 # include <strings.h>
|
|
|
46 # endif
|
|
|
47 #endif /* STDC_HEADERS */
|
|
|
48
|
|
|
49 #if defined(HAVE_SYS_TYPES_H)
|
|
|
50 #include <sys/types.h>
|
|
|
51 #endif
|
|
|
52
|
|
|
53 #include "commonhd.h"
|
|
|
54 #include "de_header.h"
|
|
|
55 #include "jdata.h"
|
|
|
56
|
|
|
57 #ifdef WRITE_CHECK
|
|
|
58 static int vfwrite (void*, int, int, FILE *);
|
|
|
59 #endif
|
|
|
60 static struct JT *readdict (FILE *);
|
|
|
61 static struct JT *copy_dict (struct JT *);
|
|
|
62 static int write_file_real (struct wnn_file *, FILE *, int);
|
|
|
63 static int writedict (struct JT *, FILE *);
|
|
|
64 static int write_hindo_of_dict (struct JT *, FILE *);
|
|
|
65 static struct JT * free_dict (struct JT *);
|
|
|
66 static struct HJT *readhindo (FILE *);
|
|
|
67 static int writehindo (struct HJT *, FILE *);
|
|
|
68 static struct HJT * free_hindo (struct HJT *);
|
|
|
69 static int alloc_dict (struct JT *);
|
|
|
70 static int check_and_change_pwd (char *, char *, char *);
|
|
|
71
|
|
|
72 #define vfread(A, B, C, fp) ((fp)?fread((A),(B),(C),(fp)):fread_cur((A),(B),(C)))
|
|
|
73 #ifndef WRITE_CHECK
|
|
|
74 #define vfwrite(A, B, C, fp) {if(fp) {fwrite((A),(B),(C),(fp));}else\
|
|
|
75 {fwrite_cur((A),(B),(C));}}
|
|
|
76 #endif
|
|
|
77 #define vclose(fp) {if(fp) {fclose(fp);}else{fclose_cur();}}
|
|
|
78
|
|
|
79 #ifdef WRITE_CHECK
|
|
|
80 static int
|
|
|
81 vfwrite (void *ptr, int size, int nitems, FILE *fp)
|
|
|
82 {
|
|
|
83 if (fp)
|
|
|
84 {
|
|
|
85 if (fwrite (ptr, size, nitems, fp) != nitems)
|
|
|
86 return (-1);
|
|
|
87 }
|
|
|
88 else
|
|
|
89 {
|
|
|
90 fwrite_cur (ptr, size, nitems);
|
|
|
91 }
|
|
|
92 return (0);
|
|
|
93 }
|
|
|
94 #endif
|
|
|
95
|
|
|
96 int
|
|
|
97 read_file (struct wnn_file *wf)
|
|
|
98 {
|
|
|
99 FILE *fp;
|
|
|
100 struct wnn_file_head fh;
|
|
|
101 if (wf->localf == REMOTE)
|
|
|
102 {
|
|
1
|
103 if (!fopen_read_cur (wf->name))
|
|
0
|
104 {
|
|
|
105 wnn_errorno = WNN_FILE_READ_ERROR;
|
|
|
106 log_err ("read_file:could not open file %s.", wf->name);
|
|
|
107 return (-1);
|
|
|
108 }
|
|
|
109 fp = NULL;
|
|
|
110 }
|
|
|
111 else
|
|
|
112 {
|
|
|
113 #ifdef WRITE_CHECK
|
|
|
114 check_backup (wf->name);
|
|
|
115 #endif
|
|
1
|
116 if (!(fp = fopen (wf->name, "r")))
|
|
0
|
117 {
|
|
|
118 wnn_errorno = WNN_FILE_READ_ERROR;
|
|
|
119 log_err("read_file:could not open file %s.", wf->name);
|
|
|
120 return (-1);
|
|
|
121 }
|
|
|
122 }
|
|
|
123 if (input_file_header (fp, &fh) == -1)
|
|
|
124 {
|
|
|
125 wnn_errorno = WNN_NOT_A_FILE;
|
|
|
126 goto ERROR_RET;
|
|
|
127 }
|
|
|
128 bcopy ((char *) &(fh.file_uniq), (char *) &(wf->f_uniq), WNN_F_UNIQ_LEN);
|
|
|
129 bcopy ((char *) &(fh.file_uniq_org), (char *) &(wf->f_uniq_org), WNN_F_UNIQ_LEN);
|
|
|
130 strncpy (wf->passwd, fh.file_passwd, WNN_PASSWD_LEN);
|
|
|
131 wf->file_type = fh.file_type;
|
|
|
132 wf->ref_count = 0;
|
|
|
133
|
|
|
134 switch (fh.file_type)
|
|
|
135 {
|
|
|
136 case WNN_FT_DICT_FILE:
|
|
|
137 wf->area = (char *) readdict (fp);
|
|
|
138 if (wf->area == NULL)
|
|
|
139 goto ERROR_RET;
|
|
|
140 break;
|
|
|
141 case WNN_FT_HINDO_FILE:
|
|
|
142 wf->area = (char *) readhindo (fp);
|
|
|
143 if (wf->area == NULL)
|
|
|
144 goto ERROR_RET;
|
|
|
145 break;
|
|
|
146 case WNN_FT_FUZOKUGO_FILE:
|
|
|
147 wf->area = (char *) fzk_read (fp);
|
|
|
148 if (wf->area == NULL)
|
|
|
149 goto ERROR_RET;
|
|
|
150 break;
|
|
|
151 }
|
|
|
152 vclose (fp);
|
|
|
153 return (0);
|
|
|
154 ERROR_RET:
|
|
|
155 vclose (fp);
|
|
|
156 return (-1);
|
|
|
157 }
|
|
|
158
|
|
|
159 static struct JT *
|
|
|
160 readdict (FILE *fp)
|
|
|
161 {
|
|
|
162 struct JT *jt1;
|
|
|
163 long x;
|
|
|
164
|
|
|
165 jt1 = (struct JT *) malloc (sizeof (struct JT));
|
|
|
166 jt1->node = 0;
|
|
|
167 if (input_header_jt (fp, jt1) == -1)
|
|
|
168 {
|
|
|
169 wnn_errorno = WNN_NOT_A_FILE;
|
|
|
170 free (jt1);
|
|
|
171 return (NULL);
|
|
|
172 }
|
|
|
173 if (jt1->syurui == WNN_UD_DICT)
|
|
|
174 {
|
|
|
175 jt1->bufsize_serial = (jt1->maxserial + MAXSERIAL);
|
|
|
176 jt1->bufsize_kanji = (jt1->maxkanji + MAXKANJI);
|
|
|
177 jt1->bufsize_hontai = (jt1->maxhontai + MAXHONTAI);
|
|
|
178 jt1->bufsize_table = (jt1->maxtable + MAXTABLE);
|
|
|
179 jt1->bufsize_ri1[D_YOMI] = 0;
|
|
|
180 jt1->bufsize_ri1[D_KANJI] = 0;
|
|
|
181 #if defined(CONVERT_by_STROKE) || defined(CONVERT_with_SiSheng)
|
|
|
182 }
|
|
|
183 else if ((jt1->syurui & 0xff) == WNN_REV_DICT)
|
|
|
184 {
|
|
|
185 #else
|
|
|
186 }
|
|
|
187 else if (jt1->syurui == WNN_REV_DICT)
|
|
|
188 {
|
|
|
189 #endif /* CONVERT_by_STROKE || CONVERT_with_SiSheng */
|
|
|
190 jt1->bufsize_serial = (jt1->maxserial + MAXSERIAL);
|
|
|
191 jt1->bufsize_kanji = (jt1->maxkanji + MAXKANJI);
|
|
|
192 jt1->bufsize_hontai = (jt1->maxhontai + MAXHONTAI);
|
|
|
193 jt1->bufsize_table = 0;
|
|
|
194 jt1->bufsize_ri1[D_YOMI] = (jt1->maxri1[D_YOMI] + MAXTABLE);
|
|
|
195 jt1->bufsize_ri1[D_KANJI] = (jt1->maxri1[D_KANJI] + MAXTABLE);
|
|
|
196 }
|
|
|
197 else if (jt1->syurui == WNN_STATIC_DICT)
|
|
|
198 { /* WNN_STATIC_DICT */
|
|
|
199 jt1->bufsize_serial = jt1->maxserial;
|
|
|
200 jt1->bufsize_kanji = jt1->maxkanji;
|
|
|
201 jt1->bufsize_hontai = jt1->maxhontai;
|
|
|
202 jt1->bufsize_table = 0;
|
|
|
203 jt1->bufsize_ri1[D_YOMI] = 0;
|
|
|
204 jt1->bufsize_ri1[D_KANJI] = 0;
|
|
|
205 }
|
|
|
206 else
|
|
|
207 {
|
|
|
208 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
209 log_err ("not a correct dictionary.");
|
|
|
210 free (jt1);
|
|
|
211 return (NULL);
|
|
|
212 }
|
|
|
213 if (alloc_dict (jt1) == -1)
|
|
|
214 {
|
|
|
215 free (jt1);
|
|
|
216 return (NULL);
|
|
|
217 }
|
|
|
218 if (vfread (jt1->comment, 2, jt1->maxcomment, fp) != jt1->maxcomment)
|
|
|
219 {
|
|
|
220 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
221 log_err ("not a correct dictionary.");
|
|
|
222 goto error;
|
|
|
223 }
|
|
|
224
|
|
|
225 if (vfread (jt1->hinsi_list, 2, jt1->maxhinsi_list, fp) != jt1->maxhinsi_list)
|
|
|
226 {
|
|
|
227 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
228 log_err ("not a correct dictionary.");
|
|
|
229 goto error;
|
|
|
230 }
|
|
|
231
|
|
|
232 if (vfread (jt1->hindo, 1, jt1->maxserial, fp) != jt1->maxserial)
|
|
|
233 {
|
|
|
234 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
235 log_err ("not a correct dictionary.");
|
|
|
236 goto error;
|
|
|
237 }
|
|
|
238 if (vfread (jt1->hinsi, 2, jt1->maxserial, fp) != jt1->maxserial)
|
|
|
239 {
|
|
|
240 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
241 log_err ("not a correct dictionary.");
|
|
|
242 goto error;
|
|
|
243 }
|
|
|
244 #ifdef CONVERT_with_SiSheng
|
|
|
245 if (jt1->syurui == CWNN_REV_DICT)
|
|
|
246 if (vfread (jt1->sisheng, 2, jt1->maxserial, fp) != jt1->maxserial)
|
|
|
247 {
|
|
|
248 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
249 log_err ("not a correct dictionary.");
|
|
|
250 goto error;
|
|
|
251 }
|
|
|
252 #endif /* CONVERT_with_SiSheng */
|
|
|
253 if (vfread (jt1->kanji, 1, jt1->maxkanji, fp) != jt1->maxkanji)
|
|
|
254 {
|
|
|
255 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
256 log_err ("not a correct dictionary.");
|
|
|
257 goto error;
|
|
|
258 }
|
|
|
259 if (vfread (jt1->table, sizeof (struct uind1), jt1->maxtable, fp) != jt1->maxtable)
|
|
|
260 {
|
|
|
261 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
262 log_err ("not a correct dictionary.");
|
|
|
263 goto error;
|
|
|
264 }
|
|
|
265 if (vfread (jt1->ri1[D_YOMI], sizeof (struct rind1), jt1->maxri1[D_YOMI], fp) != jt1->maxri1[D_YOMI])
|
|
|
266 {
|
|
|
267 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
268 log_err ("not a correct dictionary.");
|
|
|
269 goto error;
|
|
|
270 }
|
|
|
271 if (vfread (jt1->ri1[D_KANJI], sizeof (struct rind1), jt1->maxri1[D_KANJI], fp) != jt1->maxri1[D_KANJI])
|
|
|
272 {
|
|
|
273 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
274 log_err ("not a correct dictionary.");
|
|
|
275 goto error;
|
|
|
276 }
|
|
|
277 if (vfread (jt1->hontai, 1, jt1->maxhontai, fp) != jt1->maxhontai)
|
|
|
278 {
|
|
|
279 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
280 log_err ("not a correct dictionary.");
|
|
|
281 goto error;
|
|
|
282 }
|
|
|
283 if (vfread (jt1->ri2, sizeof (struct rind2), jt1->maxri2, fp) != jt1->maxri2)
|
|
|
284 {
|
|
|
285 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
286 log_err ("not a correct dictionary.");
|
|
|
287 goto error;
|
|
|
288 }
|
|
|
289
|
|
|
290 if (fp != NULL)
|
|
|
291 {
|
|
|
292 x = ftell (fp);
|
|
|
293 fseek (fp, 0, 2);
|
|
|
294 if (x != ftell (fp))
|
|
|
295 {
|
|
|
296 wnn_errorno = WNN_NOT_A_DICT;
|
|
|
297 log_err ("not a correct dictionary.");
|
|
|
298 goto error;
|
|
|
299 }
|
|
|
300 }
|
|
|
301
|
|
|
302 make_hinsi_list (jt1);
|
|
|
303
|
|
|
304 if (jt1->maxhontai == 0 && (jt1->syurui == WNN_UD_DICT || jt1->syurui == WNN_STATIC_DICT))
|
|
|
305 {
|
|
|
306 jt1->maxhontai = 4;
|
|
|
307 }
|
|
|
308 if (little_endian ())
|
|
|
309 {
|
|
|
310 revdic (jt1, 0);
|
|
|
311 }
|
|
|
312 jt1->dirty = 0;
|
|
|
313 jt1->hdirty = 0;
|
|
|
314 #ifdef CONVERT_by_STROKE
|
|
|
315 if (jt1->syurui == BWNN_REV_DICT)
|
|
|
316 if ((jt1->max_bnode = create_b_index (jt1)) == -1)
|
|
|
317 {
|
|
|
318 goto error;
|
|
|
319 }
|
|
|
320 #endif /* CONVERT_by_STROKE */
|
|
|
321 return (jt1);
|
|
|
322 error:
|
|
|
323 jt1 = free_dict (jt1);
|
|
|
324 return (NULL);
|
|
|
325 }
|
|
|
326
|
|
|
327 /*
|
|
|
328 * user_jisho_realloc: ¥æ¡¼¥¶¡¼¼½ñ¤Ë¸ì¤òÅÐÏ¿¤·²á¤®¤Æ°ìÇդˤʤä¿»þrealloc¤¹¤ë
|
|
|
329 * return value: success:SUCCESS (non zero), failure:NULL
|
|
|
330 */
|
|
|
331 int
|
|
|
332 ud_realloc_hontai (struct JT *jt)
|
|
|
333 {
|
|
|
334 size_t new_bufsize;
|
|
|
335 UCHAR *tp;
|
|
|
336
|
|
|
337 log_debug ("hontai realloc occured.");
|
|
|
338 new_bufsize = jt->maxhontai + MAXHONTAI;
|
|
|
339 if ((tp = (UCHAR *) realloc (jt->hontai, new_bufsize)) == NULL)
|
|
|
340 {
|
|
|
341 wnn_errorno = WNN_MALLOC_ERR;
|
|
|
342 log_err ("could not make the jisho area bigger.");
|
|
1
|
343 return (FAILURE);
|
|
0
|
344 }
|
|
|
345 jt->bufsize_hontai = new_bufsize;
|
|
|
346 jt->hontai = tp;
|
|
|
347 return (SUCCESS);
|
|
|
348 }
|
|
|
349
|
|
|
350 int
|
|
|
351 ud_realloc_kanji (struct JT *jt) /* Also for rd */
|
|
|
352 {
|
|
|
353 size_t new_bufsize;
|
|
|
354 UCHAR *tp;
|
|
|
355
|
|
|
356 log_debug ("kanji realloc occured.");
|
|
|
357 new_bufsize = jt->maxkanji + MAXKANJI;
|
|
|
358 if ((tp = (UCHAR *) realloc (jt->kanji, new_bufsize)) == NULL)
|
|
|
359 {
|
|
|
360 wnn_errorno = WNN_MALLOC_ERR;
|
|
|
361 log_err ("could not make the jisho area bigger.");
|
|
1
|
362 return (FAILURE);
|
|
0
|
363 }
|
|
|
364 jt->bufsize_kanji = new_bufsize;
|
|
|
365 jt->kanji = tp;
|
|
|
366 return (SUCCESS);
|
|
|
367 }
|
|
|
368
|
|
|
369 int
|
|
|
370 ud_realloc_serial (struct JT *jt) /* Also for rd */
|
|
|
371 {
|
|
|
372 size_t new_bufsize;
|
|
|
373 UCHAR *tp_hindo;
|
|
|
374 unsigned short *tp_hinsi;
|
|
|
375 #ifdef CONVERT_with_SiSheng
|
|
|
376 unsigned short *tp_sisheng;
|
|
|
377 #endif
|
|
|
378 struct rind2 *tp_ri2;
|
|
|
379
|
|
|
380 log_debug ("serial realloc occured.");
|
|
|
381 new_bufsize = jt->maxserial + MAXSERIAL;
|
|
|
382
|
|
|
383 tp_hindo = (UCHAR *) realloc (jt->hindo, new_bufsize * sizeof (*jt->hindo));
|
|
|
384 tp_hinsi = (unsigned short *) realloc (jt->hinsi, new_bufsize * sizeof (*jt->hinsi));
|
|
|
385
|
|
|
386 #ifdef CONVERT_with_SiSheng
|
|
|
387 tp_sisheng = (unsigned short *) realloc (jt->sisheng,
|
|
|
388 new_bufsize * sizeof (*jt->sisheng));
|
|
|
389 #endif /* CONVERT_with_SiSheng */
|
|
|
390
|
|
|
391 if (tp_hindo == NULL || tp_hinsi == NULL
|
|
|
392 #ifdef CONVERT_with_SiSheng
|
|
|
393 || tp_sisheng == NULL
|
|
|
394 #endif /* CONVERT_with_SiSheng */
|
|
|
395 )
|
|
|
396 {
|
|
|
397 free (tp_hindo);
|
|
|
398 free (tp_hinsi);
|
|
|
399 #ifdef CONVERT_with_SiSheng
|
|
|
400 free (tp_sisheng);
|
|
|
401 #endif /* CONVERT_with_SiSheng */
|
|
|
402
|
|
|
403 wnn_errorno = WNN_MALLOC_ERR;
|
|
|
404 log_err ("could notmake the jisho area bigger.");
|
|
1
|
405 return (FAILURE);
|
|
0
|
406 }
|
|
|
407 jt->bufsize_serial = new_bufsize;
|
|
|
408 jt->hindo = tp_hindo;
|
|
|
409 jt->hinsi = tp_hinsi;
|
|
|
410 #ifdef CONVERT_with_SiSheng
|
|
|
411 jt->sisheng = tp_sisheng;
|
|
|
412 #endif /* CONVERT_with_SiSheng */
|
|
|
413
|
|
|
414
|
|
|
415 #if defined(CONVERT_by_STROKE) || defined(CONVERT_with_SiSheng)
|
|
|
416 if ((jt->syurui & 0xff) == WNN_REV_DICT)
|
|
|
417 #else
|
|
|
418 if (jt->syurui == WNN_REV_DICT)
|
|
|
419 #endif /* CONVERT_by_STROKE || CONVERT_with_SiSheng */
|
|
|
420 {
|
|
|
421 tp_ri2 = (struct rind2 *) realloc (jt->ri2,
|
|
|
422 new_bufsize * sizeof (struct rind2));
|
|
|
423 if (tp_ri2 == NULL)
|
|
|
424 {
|
|
|
425 wnn_errorno = WNN_MALLOC_ERR;
|
|
|
426 log_err ("could not make the jisho area bigger.");
|
|
1
|
427 return (FAILURE);
|
|
0
|
428 }
|
|
|
429 jt->ri2 = tp_ri2;
|
|
|
430 }
|
|
|
431
|
|
|
432 return (SUCCESS);
|
|
|
433 }
|
|
|
434
|
|
|
435 int
|
|
|
436 ud_realloc_table (struct JT *jt)
|
|
|
437 {
|
|
|
438 size_t new_bufsize;
|
|
|
439 struct uind1 *tp;
|
|
|
440
|
|
|
441 log_debug ("table realloc occured.");
|
|
|
442 new_bufsize = jt->maxtable + MAXTABLE;
|
|
|
443 tp = (struct uind1 *) realloc (jt->table, new_bufsize * sizeof (struct uind1));
|
|
|
444 if (tp == NULL)
|
|
|
445 {
|
|
|
446 wnn_errorno = WNN_MALLOC_ERR;
|
|
|
447 log_err ("could not make the jisho area bigger.");
|
|
1
|
448 return (FAILURE);
|
|
0
|
449 }
|
|
|
450 jt->bufsize_table = new_bufsize;
|
|
|
451 jt->table = tp;
|
|
|
452 return (SUCCESS);
|
|
|
453 }
|
|
|
454
|
|
|
455 int
|
|
|
456 rd_realloc_ri1 (struct JT *jt, int which)
|
|
|
457 {
|
|
|
458 size_t new_bufsize;
|
|
|
459 struct rind1 *tp;
|
|
|
460
|
|
|
461 log_debug ("ri1 reallocation occured.");
|
|
|
462 new_bufsize = jt->maxri1[which] + MAXTABLE;
|
|
|
463 tp = (struct rind1 *) realloc (jt->ri1[which],
|
|
|
464 new_bufsize * sizeof (struct rind1));
|
|
|
465 if (tp == NULL)
|
|
|
466 {
|
|
|
467 wnn_errorno = WNN_MALLOC_ERR;
|
|
|
468 log_err ("could not make the jisho area bigger.");
|
|
1
|
469 return (FAILURE);
|
|
0
|
470 }
|
|
|
471 jt->bufsize_ri1[which] = new_bufsize;
|
|
|
472 jt->ri1[which] = tp;
|
|
|
473 return (SUCCESS);
|
|
|
474 }
|
|
|
475
|
|
|
476
|
|
|
477 int
|
|
|
478 hindo_file_realloc (struct HJT *hjt)
|
|
|
479 {
|
|
|
480 size_t new_bufsize;
|
|
|
481 UCHAR *tp;
|
|
|
482
|
|
|
483 log_debug ("hindo file reallocation occured.");
|
|
|
484 new_bufsize = hjt->maxserial + MAXSERIAL;
|
|
|
485 tp = (UCHAR *) realloc (hjt->hindo, new_bufsize * sizeof (*hjt->hindo));
|
|
|
486 if (tp == NULL)
|
|
|
487 {
|
|
|
488 wnn_errorno = WNN_MALLOC_ERR;
|
|
|
489 log_err ("could not make the hindo file area bigger.");
|
|
1
|
490 return (FAILURE);
|
|
0
|
491 }
|
|
|
492 hjt->bufsize_serial = new_bufsize;
|
|
|
493 hjt->hindo = tp;
|
|
|
494 return (SUCCESS);
|
|
|
495 }
|
|
|
496
|
|
|
497 #ifdef CONVERT_by_STROKE
|
|
|
498 int
|
|
|
499 rd_realloc_bind (struct JT *jt)
|
|
|
500 {
|
|
|
501 size_t new_bufsize;
|
|
|
502 struct b_node *tp;
|
|
|
503
|
|
|
504 log_debug ("jt->bind reallocation occured.");
|
|
|
505 new_bufsize = jt->bufsize_bnode + MAXBIND;
|
|
|
506 tp = (struct b_node *) realloc (jt->bind, new_bufsize * sizeof (struct b_node));
|
|
|
507 if (tp == NULL)
|
|
|
508 {
|
|
|
509 wnn_errorno = WNN_MALLOC_ERR;
|
|
|
510 log_err ("could not make the jisho area bigger.");
|
|
1
|
511 return (FAILURE);
|
|
0
|
512 }
|
|
|
513 jt->bufsize_bnode = new_bufsize;
|
|
|
514 jt->bind = tp;
|
|
|
515 return (SUCCESS);
|
|
|
516 }
|
|
|
517 #endif /* CONVERT_by_STROKE */
|
|
|
518
|
|
|
519 static struct JT *
|
|
|
520 copy_dict (struct JT *jt1)
|
|
|
521 {
|
|
|
522 struct JT *jt2;
|
|
|
523
|
|
|
524 jt2 = (struct JT *) malloc (sizeof (struct JT));
|
|
|
525 *jt2 = *jt1;
|
|
|
526
|
|
|
527 if (alloc_dict (jt2) == -1)
|
|
|
528 {
|
|
|
529 free (jt2);
|
|
|
530 return (NULL);
|
|
|
531 }
|
|
|
532 bcopy (jt1->hindo, jt2->hindo, jt1->maxserial);
|
|
|
533 bcopy (jt1->hinsi, jt2->hinsi, jt1->maxserial * 2);
|
|
|
534 #ifdef CONVERT_with_SiSheng
|
|
|
535 if (jt1->syurui == CWNN_REV_DICT) /* Chinese PinYin dic only */
|
|
|
536 bcopy (jt1->sisheng, jt2->sisheng, jt1->maxserial * 2);
|
|
|
537 #endif /* CONVERT_with_SiSheng */
|
|
|
538 bcopy (jt1->kanji, jt2->kanji, jt1->maxkanji);
|
|
|
539 bcopy (jt1->table, jt2->table, jt1->maxtable * sizeof (struct uind1));
|
|
|
540 bcopy (jt1->hontai, jt2->hontai, jt1->maxhontai);
|
|
|
541 bcopy (jt1->comment, jt2->comment, jt1->maxcomment * sizeof (w_char));
|
|
|
542 bcopy (jt1->hinsi_list, jt2->hinsi_list, jt1->maxhinsi_list * sizeof (w_char));
|
|
|
543 bcopy (jt1->ri2, jt2->ri2, jt1->maxri2 * sizeof (struct rind2));
|
|
|
544 bcopy (jt1->ri1[D_YOMI], jt2->ri1[D_YOMI], jt1->maxri1[D_YOMI] * sizeof (struct rind1));
|
|
|
545 bcopy (jt1->ri1[D_KANJI], jt2->ri1[D_KANJI], jt1->maxri1[D_KANJI] * sizeof (struct rind1));
|
|
|
546 return (jt2);
|
|
|
547 }
|
|
|
548
|
|
|
549
|
|
|
550 int
|
|
|
551 must_write_file (struct wnn_file *wf, struct wnn_file_uniq *uniq)
|
|
|
552 {
|
|
|
553 if (f_uniq_cmp (&(wf->f_uniq), uniq))
|
|
|
554 return (3);
|
|
|
555 /* The File to write is not read. */
|
|
|
556 switch (wf->file_type)
|
|
|
557 {
|
|
|
558 case WNN_FT_DICT_FILE:
|
|
|
559 {
|
|
|
560 struct JT *jt = (struct JT *) wf->area;
|
|
|
561 if (jt->dirty)
|
|
|
562 return 1;
|
|
|
563 if (jt->hdirty)
|
|
|
564 return 2;
|
|
|
565 return 0;
|
|
|
566 }
|
|
|
567 case WNN_FT_HINDO_FILE:
|
|
|
568 {
|
|
|
569 struct HJT *hjt = (struct HJT *) wf->area;
|
|
|
570 if (!(hjt->hdirty))
|
|
|
571 return (0);
|
|
|
572 else
|
|
|
573 return 1;
|
|
|
574 }
|
|
|
575 case WNN_FT_FUZOKUGO_FILE:
|
|
|
576 wnn_errorno = NOT_SUPPORTED_OPERATION;
|
|
|
577 return (-1);
|
|
|
578 }
|
|
|
579 return (-1);
|
|
|
580 }
|
|
|
581
|
|
|
582 void
|
|
|
583 clear_dirty_bit (struct wnn_file *wf)
|
|
|
584 {
|
|
|
585 switch (wf->file_type)
|
|
|
586 {
|
|
|
587 case WNN_FT_DICT_FILE:
|
|
|
588 {
|
|
|
589 struct JT *jt = (struct JT *) wf->area;
|
|
|
590 jt->dirty = 0;
|
|
|
591 jt->hdirty = 0;
|
|
|
592 }
|
|
|
593 break;
|
|
|
594 case WNN_FT_HINDO_FILE:
|
|
|
595 {
|
|
|
596 struct HJT *hjt = (struct HJT *) wf->area;
|
|
|
597 hjt->hdirty = 0;
|
|
|
598 }
|
|
|
599 break;
|
|
|
600 case WNN_FT_FUZOKUGO_FILE:
|
|
|
601 break;
|
|
|
602 }
|
|
|
603 }
|
|
|
604
|
|
|
605
|
|
|
606 int
|
|
|
607 rcv_file (struct wnn_file *wf, int mode)
|
|
|
608 {
|
|
|
609 FILE *fp;
|
|
|
610 int x;
|
|
|
611
|
|
|
612 /* if(wf->localf == REMOTE){
|
|
|
613 }
|
|
|
614 */
|
|
1
|
615 if (!fopen_write_cur (wf->name))
|
|
0
|
616 {
|
|
|
617 log_err ("receive_file:No file %s.", wf->name);
|
|
|
618 wnn_errorno = WNN_FILE_WRITE_ERROR;
|
|
|
619 return (-1);
|
|
|
620 }
|
|
|
621 fp = NULL;
|
|
|
622 x = write_file_real (wf, fp, mode);
|
|
|
623 vclose (fp);
|
|
|
624 return (x);
|
|
|
625 }
|
|
|
626
|
|
|
627 int
|
|
|
628 write_file (struct wnn_file *wf, char *n)
|
|
|
629 {
|
|
|
630 FILE *fp;
|
|
|
631 int mode = 3;
|
|
|
632 struct wnn_file_head fh;
|
|
|
633 #ifdef WRITE_CHECK
|
|
|
634 char *tmp = NULL, *backup = NULL;
|
|
|
635
|
|
|
636 check_backup (n);
|
|
|
637 #endif
|
|
|
638 if ((fp = fopen (n, "r")) != NULL)
|
|
|
639 { /* Old File Exist */
|
|
|
640 if (input_file_header (fp, &fh) == -1)
|
|
|
641 {
|
|
|
642 wnn_errorno = WNN_NOT_A_FILE;
|
|
|
643 fclose (fp);
|
|
|
644 return (-1);
|
|
|
645 }
|
|
|
646 mode = must_write_file (wf, &(fh.file_uniq));
|
|
|
647 fclose (fp);
|
|
|
648 if (mode == -1)
|
|
|
649 return -1;
|
|
|
650 }
|
|
|
651
|
|
|
652 if (mode == 0)
|
|
|
653 {
|
|
|
654 return (0); /* Need Not Write */
|
|
|
655 }
|
|
|
656 else if (mode == 1 || mode == 3)
|
|
|
657 { /* 3 when the file is not the one to be read. */
|
|
|
658 #ifdef WRITE_CHECK
|
|
|
659 backup = make_backup_file (n);
|
|
|
660 if ((tmp = make_tmp_file (n, 0, &fp)) == NULL)
|
|
|
661 {
|
|
|
662 delete_tmp_file (backup);
|
|
|
663 #else /* WRITE_CHECK */
|
|
|
664 if ((fp = fopen (n, "w+")) == NULL)
|
|
|
665 {
|
|
|
666 #endif /* WRITE_CHECK */
|
|
|
667 wnn_errorno = WNN_FILE_WRITE_ERROR;
|
|
|
668 return (-1);
|
|
|
669 }
|
|
|
670 }
|
|
|
671 else if (mode == 2)
|
|
|
672 {
|
|
|
673 #ifdef WRITE_CHECK
|
|
|
674 backup = make_backup_file (n);
|
|
|
675 if ((tmp = make_tmp_file (n, 1, &fp)) == NULL)
|
|
|
676 {
|
|
|
677 delete_tmp_file (backup);
|
|
|
678 #else /* WRITE_CHECK */
|
|
|
679 if ((fp = fopen (n, "r+")) == NULL)
|
|
|
680 { /* New File */
|
|
|
681 #endif /* WRITE_CHECK */
|
|
|
682 wnn_errorno = WNN_FILE_WRITE_ERROR;
|
|
|
683 return (-1);
|
|
|
684 }
|
|
|
685 }
|
|
|
686 if (write_file_real (wf, fp, mode) == -1)
|
|
|
687 {
|
|
|
688 fclose (fp);
|
|
|
689 #ifdef WRITE_CHECK
|
|
|
690 delete_tmp_file (tmp);
|
|
|
691 delete_tmp_file (backup);
|
|
|
692 #endif /* WRITE_CHECK */
|
|
|
693 return -1;
|
|
|
694 }
|
|
|
695 fclose (fp);
|
|
|
696 #ifdef WRITE_CHECK
|
|
|
697 move_tmp_to_org (tmp, n, 1);
|
|
|
698 delete_tmp_file (backup);
|
|
|
699 #endif /* WRITE_CHECK */
|
|
|
700 if ((mode == 1) || (mode == 2))
|
|
|
701 {
|
|
|
702 clear_dirty_bit (wf);
|
|
|
703 }
|
|
|
704 return (0);
|
|
|
705 }
|
|
|
706
|
|
|
707 static int
|
|
|
708 write_file_real (struct wnn_file *wf,
|
|
|
709 FILE *fp,
|
|
|
710 int mode /* 1 For All, 2 For only hindo */ )
|
|
|
711 {
|
|
|
712 struct wnn_file_head fh;
|
|
|
713
|
|
|
714 if (fp)
|
|
|
715 rewind (fp);
|
|
|
716 bcopy ((char *) &wf->f_uniq, (char *) &(fh.file_uniq), WNN_F_UNIQ_LEN);
|
|
|
717 bcopy ((char *) &wf->f_uniq_org, (char *) &(fh.file_uniq_org), WNN_F_UNIQ_LEN);
|
|
|
718 bcopy (wf->passwd, fh.file_passwd, WNN_PASSWD_LEN);
|
|
|
719 fh.file_type = wf->file_type;
|
|
|
720
|
|
|
721 if (output_file_header (fp, &fh) == -1)
|
|
|
722 {
|
|
|
723 wnn_errorno = WNN_FILE_WRITE_ERROR;
|
|
|
724 goto ERROR_RET;
|
|
|
725 }
|
|
|
726 switch (fh.file_type)
|
|
|
727 {
|
|
|
728 case WNN_FT_DICT_FILE:
|
|
|
729 {
|
|
|
730 struct JT *jt2;
|
|
|
731 struct JT *jt = (struct JT *) wf->area;
|
|
|
732 if (little_endian () && jt->dirty)
|
|
|
733 {
|
|
|
734 if ((jt2 = copy_dict ((struct JT *) wf->area)) == NULL)
|
|
|
735 goto ERROR_RET;
|
|
|
736 revdic (jt2, 1);
|
|
|
737 if (writedict (jt2, fp) == -1)
|
|
|
738 goto ERROR_RET;
|
|
|
739 jt2 = free_dict (jt2);
|
|
|
740 }
|
|
|
741 else
|
|
|
742 {
|
|
|
743 /* if(writedict(wf->area, fp) == -1)goto ERROR_RET; */
|
|
|
744 if (mode == 2)
|
|
|
745 {
|
|
|
746 if (write_hindo_of_dict (wf->area, fp) == -1)
|
|
|
747 goto ERROR_RET;
|
|
|
748 }
|
|
|
749 else
|
|
|
750 {
|
|
|
751 if (writedict (wf->area, fp) == -1)
|
|
|
752 goto ERROR_RET;
|
|
|
753 }
|
|
|
754 }
|
|
|
755 }
|
|
|
756 break;
|
|
|
757 case WNN_FT_HINDO_FILE:
|
|
|
758 if (writehindo (wf->area, fp) == -1)
|
|
|
759 goto ERROR_RET;
|
|
|
760 break;
|
|
|
761 case WNN_FT_FUZOKUGO_FILE:
|
|
|
762 wnn_errorno = NOT_SUPPORTED_OPERATION;
|
|
|
763 goto ERROR_RET;
|
|
|
764 }
|
|
|
765 return (0);
|
|
|
766 ERROR_RET:
|
|
|
767 return (-1);
|
|
|
768 }
|
|
|
769
|
|
|
770 static int
|
|
|
771 writedict (struct JT *jt1, FILE *fp)
|
|
|
772 {
|
|
|
773
|
|
|
774 if (output_header_jt (fp, jt1) == -1)
|
|
|
775 return (-1);
|
|
|
776 #ifdef WRITE_CHECK
|
|
|
777 if ((vfwrite (jt1->comment, 2, jt1->maxcomment, fp) == -1) ||
|
|
|
778 (vfwrite (jt1->hinsi_list, 2, jt1->maxhinsi_list, fp) == -1) || (vfwrite (jt1->hindo, 1, jt1->maxserial, fp) == -1) || (vfwrite (jt1->hinsi, 2, jt1->maxserial, fp) == -1))
|
|
|
779 return (-1);
|
|
|
780 #ifdef CONVERT_with_SiSheng
|
|
|
781 if (jt1->syurui == CWNN_REV_DICT) /* for Chinese PinYin dic only */
|
|
|
782 if (vfwrite (jt1->sisheng, 2, jt1->maxserial, fp) == -1)
|
|
|
783 return (-1);
|
|
|
784 #endif /* CONVERT_with_SiSheng */
|
|
|
785 if ((vfwrite (jt1->kanji, 1, jt1->maxkanji, fp) == -1) ||
|
|
|
786 (vfwrite (jt1->table, sizeof (struct uind1), jt1->maxtable, fp) == -1) ||
|
|
|
787 (vfwrite (jt1->ri1[D_YOMI], sizeof (struct rind1),
|
|
|
788 jt1->maxri1[D_YOMI], fp) == -1) ||
|
|
|
789 (vfwrite (jt1->ri1[D_KANJI], sizeof (struct rind1),
|
|
|
790 jt1->maxri1[D_KANJI], fp) == -1) || (vfwrite (jt1->hontai, 1, jt1->maxhontai, fp) == -1) || (vfwrite (jt1->ri2, sizeof (struct rind2), jt1->maxri2, fp) == -1))
|
|
|
791 return (-1);
|
|
|
792 #else /* WRITE_CHECK */
|
|
|
793 vfwrite (jt1->comment, 2, jt1->maxcomment, fp);
|
|
|
794 vfwrite (jt1->hinsi_list, 2, jt1->maxhinsi_list, fp);
|
|
|
795 vfwrite (jt1->hindo, 1, jt1->maxserial, fp);
|
|
|
796 vfwrite (jt1->hinsi, 2, jt1->maxserial, fp);
|
|
|
797 #ifdef CONVERT_with_SiSheng
|
|
|
798 if (jt1->syurui == CWNN_REV_DICT) /* for Chinese PinYin dic only */
|
|
|
799 vfwrite (jt1->sisheng, 2, jt1->maxserial, fp);
|
|
|
800 #endif /* CONVERT_with_SiSheng */
|
|
|
801 vfwrite (jt1->kanji, 1, jt1->maxkanji, fp);
|
|
|
802 vfwrite (jt1->table, sizeof (struct uind1), jt1->maxtable, fp);
|
|
|
803 vfwrite (jt1->ri1[D_YOMI], sizeof (struct rind1), jt1->maxri1[D_YOMI], fp);
|
|
|
804 vfwrite (jt1->ri1[D_KANJI], sizeof (struct rind1), jt1->maxri1[D_KANJI], fp);
|
|
|
805 vfwrite (jt1->hontai, 1, jt1->maxhontai, fp);
|
|
|
806 vfwrite (jt1->ri2, sizeof (struct rind2), jt1->maxri2, fp);
|
|
|
807 #endif /* WRITE_CHECK */
|
|
|
808
|
|
|
809 return (0);
|
|
|
810 }
|
|
|
811
|
|
|
812 static int
|
|
|
813 write_hindo_of_dict (struct JT *jt1, FILE *fp)
|
|
|
814 {
|
|
|
815 if (output_header_jt (fp, jt1) == -1)
|
|
|
816 return (-1);
|
|
|
817 #ifdef WRITE_CHECK
|
|
|
818 if ((vfwrite (jt1->comment, 2, jt1->maxcomment, fp) == -1) || (vfwrite (jt1->hindo, 1, jt1->maxserial, fp) == -1))
|
|
|
819 return (-1);
|
|
|
820 #else /* WRITE_CHECK */
|
|
|
821 vfwrite (jt1->comment, 2, jt1->maxcomment, fp);
|
|
|
822 vfwrite (jt1->hindo, 1, jt1->maxserial, fp);
|
|
|
823 #endif /* WRITE_CHECK */
|
|
|
824 return (0);
|
|
|
825 }
|
|
|
826
|
|
|
827
|
|
|
828
|
|
|
829 int
|
|
|
830 discardfile (struct wnn_file *wf)
|
|
|
831 {
|
|
|
832 #ifdef nodef
|
|
|
833 FILE *fp;
|
|
|
834 if (wf->localf == LOCAL)
|
|
|
835 {
|
|
|
836 if ((fp = fopen (wf->name, "r")) == NULL)
|
|
|
837 {
|
|
|
838 log_err ("discardfile:No file %s.", wf->name);
|
|
|
839 return (-1);
|
|
|
840 }
|
|
|
841 fclose (fp);
|
|
|
842 }
|
|
|
843 #endif
|
|
|
844 switch (wf->file_type)
|
|
|
845 {
|
|
|
846 case WNN_FT_DICT_FILE:
|
|
|
847 wf->area = free_dict (wf->area);
|
|
|
848 break;
|
|
|
849 case WNN_FT_HINDO_FILE:
|
|
|
850 wf->area = free_hindo (wf->area);
|
|
|
851 break;
|
|
|
852 case WNN_FT_FUZOKUGO_FILE:
|
|
|
853 /*
|
|
|
854 fzk_discard(wf->area);
|
|
|
855 */
|
|
|
856 break;
|
|
|
857 }
|
|
|
858 return (0);
|
|
|
859 }
|
|
|
860
|
|
|
861 static struct JT *
|
|
|
862 free_dict (struct JT *jt)
|
|
|
863 {
|
|
|
864 if (jt)
|
|
|
865 {
|
|
|
866 free (jt->hindo);
|
|
|
867 free (jt->hinsi);
|
|
|
868 #ifdef CONVERT_with_SiSheng
|
|
|
869 free (jt->sisheng);
|
|
|
870 #endif /* CONVERT_with_SiSheng */
|
|
|
871 free (jt->kanji);
|
|
|
872 free (jt->table);
|
|
|
873 free (jt->hontai);
|
|
|
874 free (jt->comment);
|
|
|
875 free (jt->hinsi_list);
|
|
|
876 free (jt->ri1[D_YOMI]);
|
|
|
877 free (jt->ri1[D_KANJI]);
|
|
|
878 free (jt->ri2);
|
|
|
879 free (jt->node);
|
|
|
880 #ifdef CONVERT_by_STROKE
|
|
|
881 free (jt->bind);
|
|
|
882 #endif /* CONVERT_by_STROKE */
|
|
|
883 free (jt);
|
|
|
884 }
|
|
|
885 return (NULL);
|
|
|
886 }
|
|
|
887
|
|
|
888
|
|
|
889
|
|
|
890 static struct HJT *
|
|
|
891 readhindo (FILE *fp)
|
|
|
892 {
|
|
|
893 struct HJT *hjt1;
|
|
|
894
|
|
|
895 hjt1 = (struct HJT *) malloc (sizeof (struct HJT));
|
|
|
896 if (input_header_hjt (fp, hjt1) == -1)
|
|
|
897 {
|
|
|
898 wnn_errorno = WNN_NOT_A_FILE;
|
|
|
899 free (hjt1);
|
|
|
900 return (NULL);
|
|
|
901 }
|
|
|
902
|
|
|
903 hjt1->bufsize_serial = (hjt1->maxserial + MAXSERIAL);
|
|
|
904
|
|
|
905 hjt1->hindo = (UCHAR *) NULL;
|
|
|
906 hjt1->comment = (w_char *) NULL;
|
|
|
907 if ((hjt1->hindo = (UCHAR *) malloc (hjt1->bufsize_serial)) == NULL || (hjt1->comment = (w_char *) malloc (hjt1->maxcomment * sizeof (w_char))) == NULL)
|
|
|
908 {
|
|
|
909 wnn_errorno = WNN_MALLOC_ERR;
|
|
|
910 free (hjt1->hindo);
|
|
|
911 free (hjt1->comment);
|
|
|
912 free (hjt1);
|
|
|
913 log_err ("could not allocate hindo area.");
|
|
|
914 return (NULL);
|
|
|
915 }
|
|
|
916
|
|
|
917 if (vfread (hjt1->comment, 2, hjt1->maxcomment, fp) != hjt1->maxcomment)
|
|
|
918 {
|
|
|
919 wnn_errorno = WNN_NOT_HINDO_FILE;
|
|
|
920 log_err ("not a correct hindo file.");
|
|
|
921 goto error;
|
|
|
922 }
|
|
|
923
|
|
|
924 if (vfread (hjt1->hindo, 1, hjt1->maxserial, fp) != hjt1->maxserial)
|
|
|
925 {
|
|
|
926 wnn_errorno = WNN_NOT_HINDO_FILE;
|
|
|
927 log_err ("not a correct hindo file.");
|
|
|
928 goto error;
|
|
|
929 }
|
|
|
930 hjt1->hdirty = 0;
|
|
|
931 return (hjt1);
|
|
|
932 error:
|
|
|
933 hjt1 = free_hindo (hjt1);
|
|
|
934 return (NULL);
|
|
|
935 }
|
|
|
936
|
|
|
937
|
|
|
938 static int
|
|
|
939 writehindo (struct HJT *hjt1, FILE *fp)
|
|
|
940 {
|
|
|
941 if (output_header_hjt (fp, hjt1) == -1)
|
|
|
942 return (-1);
|
|
|
943 #ifdef WRITE_CHECK
|
|
|
944 if (vfwrite (hjt1->hindo, 1, hjt1->maxserial, fp) == -1)
|
|
|
945 return (-1);
|
|
|
946 #else
|
|
|
947 vfwrite (hjt1->hindo, 1, hjt1->maxserial, fp);
|
|
|
948 #endif
|
|
|
949 return (0);
|
|
|
950 }
|
|
|
951
|
|
|
952 static struct HJT *
|
|
|
953 free_hindo (struct HJT *hjt)
|
|
|
954 {
|
|
|
955 if (hjt)
|
|
|
956 {
|
|
|
957 free (hjt->hindo);
|
|
|
958 free (hjt->comment);
|
|
|
959 free (hjt);
|
|
|
960 }
|
|
|
961 return (NULL);
|
|
|
962 }
|
|
|
963
|
|
|
964
|
|
|
965 int
|
|
|
966 create_hindo_file1 (struct wnn_file *wf,
|
|
|
967 char *fn,
|
|
|
968 w_char *comm,
|
|
|
969 char *passwd)
|
|
|
970 {
|
|
|
971
|
|
|
972 return (create_hindo_file (&(wf->f_uniq_org), fn, comm, passwd, ((struct JT *) (wf->area))->maxserial));
|
|
|
973 }
|
|
|
974
|
|
|
975 int
|
|
|
976 match_dic_and_hindo_p (struct wnn_file *wfp, struct wnn_file *whfp)
|
|
|
977 {
|
|
|
978 struct HJT *hjtp;
|
|
|
979 hjtp = (struct HJT *) (whfp->area);
|
|
|
980 if (bcmp ((char *) &wfp->f_uniq_org, (char *) (&(hjtp->dic_file_uniq)), WNN_F_UNIQ_LEN) == 0)
|
|
|
981 return (1);
|
|
|
982 return (0);
|
|
|
983 }
|
|
|
984
|
|
|
985 static int
|
|
|
986 alloc_dict (struct JT *jt1)
|
|
|
987 {
|
|
|
988 jt1->hindo = (UCHAR *) NULL;
|
|
|
989 jt1->hinsi = (unsigned short *) NULL;
|
|
|
990 #ifdef CONVERT_with_SiSheng
|
|
|
991 jt1->sisheng = (unsigned short *) NULL;
|
|
|
992 #endif /* CONVERT_with_SiSheng */
|
|
|
993 jt1->kanji = (UCHAR *) NULL;
|
|
|
994 jt1->table = (struct uind1 *) NULL;
|
|
|
995 jt1->hontai = (UCHAR *) NULL;
|
|
|
996 jt1->comment = (w_char *) NULL;
|
|
|
997 jt1->hinsi_list = (w_char *) NULL;
|
|
|
998 jt1->ri1[D_YOMI] = (struct rind1 *) NULL;
|
|
|
999 jt1->ri1[D_KANJI] = (struct rind1 *) NULL;
|
|
|
1000 jt1->ri2 = (struct rind2 *) NULL;
|
|
|
1001 jt1->node = (struct wnn_hinsi_node *) NULL;
|
|
|
1002 #ifdef CONVERT_by_STROKE
|
|
|
1003 jt1->bind = (struct b_node *) NULL;
|
|
|
1004 #endif /* CONVERT_by_STROKE */
|
|
|
1005 if (((jt1->hindo = (UCHAR *) malloc (jt1->bufsize_serial)) == NULL) || ((jt1->hinsi = (unsigned short *) (malloc (jt1->bufsize_serial * sizeof (short)))) == NULL) ||
|
|
|
1006 #ifdef CONVERT_with_SiSheng
|
|
|
1007 ((jt1->sisheng = (unsigned short *) (malloc (jt1->bufsize_serial * sizeof (short)))) == NULL) ||
|
|
|
1008 #endif /* CONVERT_with_SiSheng */
|
|
|
1009 ((jt1->kanji = (UCHAR *) malloc (jt1->bufsize_kanji)) == NULL) ||
|
|
|
1010 ((jt1->table = (struct uind1 *) malloc (jt1->bufsize_table * sizeof (struct uind1))) == NULL) ||
|
|
|
1011 ((jt1->hontai = (UCHAR *) malloc (jt1->bufsize_hontai)) == NULL) ||
|
|
|
1012 ((jt1->comment = (w_char *) malloc (jt1->maxcomment * sizeof (w_char))) == NULL) ||
|
|
|
1013 ((jt1->hinsi_list = (w_char *) malloc (jt1->maxhinsi_list * sizeof (w_char))) == NULL) ||
|
|
|
1014 ((jt1->ri1[D_YOMI] = (struct rind1 *) malloc (jt1->bufsize_ri1[D_YOMI] * sizeof (struct rind1))) == NULL) ||
|
|
|
1015 ((jt1->ri1[D_KANJI] = (struct rind1 *) malloc (jt1->bufsize_ri1[D_KANJI] * sizeof (struct rind1))) == NULL) ||
|
|
|
1016 ((jt1->ri2 = (struct rind2 *) malloc (jt1->bufsize_serial * sizeof (struct rind2))) == NULL))
|
|
|
1017 {
|
|
|
1018 wnn_errorno = WNN_MALLOC_ERR;
|
|
|
1019 free (jt1->hindo);
|
|
|
1020 free (jt1->hinsi);
|
|
|
1021 #ifdef CONVERT_with_SiSheng
|
|
|
1022 free (jt1->sisheng);
|
|
|
1023 #endif /* CONVERT_with_SiSheng */
|
|
|
1024 free (jt1->kanji);
|
|
|
1025 free (jt1->table);
|
|
|
1026 free (jt1->hontai);
|
|
|
1027 free (jt1->comment);
|
|
|
1028 free (jt1->hinsi_list);
|
|
|
1029 free (jt1->ri1[D_YOMI]);
|
|
|
1030 free (jt1->ri1[D_KANJI]);
|
|
|
1031 free (jt1->ri2);
|
|
|
1032 log_err ("could not allocate jisho area.");
|
|
|
1033 return (-1);
|
|
|
1034 }
|
|
|
1035 return (0);
|
|
|
1036 }
|
|
|
1037
|
|
|
1038 int
|
|
|
1039 file_comment_set (struct wnn_file *wf, w_char *com)
|
|
|
1040 {
|
|
|
1041 struct JT *jt;
|
|
|
1042 struct HJT *hjt;
|
|
|
1043 size_t new_size;
|
|
|
1044 w_char *tp;
|
|
|
1045
|
|
|
1046 switch (wf->file_type)
|
|
|
1047 {
|
|
|
1048 case WNN_FT_DICT_FILE:
|
|
|
1049 jt = (struct JT *) wf->area;
|
|
|
1050 new_size = Strlen (com) + 1;
|
|
|
1051 if ((tp = (w_char *) realloc (jt->comment, jt->maxcomment * sizeof (w_char))) == NULL)
|
|
|
1052 {
|
|
1
|
1053 return (FAILURE);
|
|
0
|
1054 }
|
|
|
1055 jt->maxcomment = new_size;
|
|
|
1056 jt->comment = tp;
|
|
|
1057 Strcpy (jt->comment, com);
|
|
|
1058 jt->dirty = 1;
|
|
|
1059 break;
|
|
|
1060 case WNN_FT_HINDO_FILE:
|
|
|
1061 hjt = (struct HJT *) wf->area;
|
|
|
1062 new_size = Strlen (com) + 1;
|
|
|
1063 if ((tp = (w_char *) realloc (hjt->comment, new_size * sizeof (w_char))) == NULL)
|
|
|
1064 {
|
|
1
|
1065 return (FAILURE);
|
|
0
|
1066 }
|
|
|
1067 hjt->maxcomment = new_size;
|
|
|
1068 hjt->comment = tp;
|
|
|
1069 Strcpy (hjt->comment, com);
|
|
|
1070 hjt->hdirty = 1;
|
|
|
1071 break;
|
|
|
1072 case WNN_FT_FUZOKUGO_FILE:
|
|
|
1073 wnn_errorno = NOT_SUPPORTED_OPERATION;
|
|
1
|
1074 return (FAILURE);
|
|
0
|
1075 }
|
|
|
1076 return (SUCCESS);
|
|
|
1077 }
|
|
|
1078
|
|
|
1079 int
|
|
|
1080 file_password_set (struct wnn_file *wf,
|
|
|
1081 int which,
|
|
|
1082 char *old,
|
|
|
1083 char *new)
|
|
|
1084 {
|
|
|
1085 struct JT *jt;
|
|
|
1086 struct HJT *hjt;
|
|
|
1087
|
|
|
1088 if (which == 0)
|
|
|
1089 which = 3;
|
|
|
1090 if (wf->file_type == WNN_FT_FUZOKUGO_FILE)
|
|
|
1091 {
|
|
|
1092 wnn_errorno = NOT_SUPPORTED_OPERATION;
|
|
|
1093 return (-1);
|
|
|
1094 }
|
|
|
1095 if (which & 0x01 || wf->file_type == WNN_FT_HINDO_FILE)
|
|
|
1096 {
|
|
|
1097 if (check_and_change_pwd (wf->passwd, old, new) == -1)
|
|
|
1098 return (-1);
|
|
|
1099 if (wf->file_type == WNN_FT_DICT_FILE)
|
|
|
1100 {
|
|
|
1101 jt = (struct JT *) wf->area;
|
|
|
1102 jt->dirty = 1;
|
|
|
1103 }
|
|
|
1104 else
|
|
|
1105 {
|
|
|
1106 hjt = (struct HJT *) wf->area;
|
|
|
1107 hjt->hdirty = 1;
|
|
|
1108 }
|
|
|
1109 }
|
|
|
1110 if (wf->file_type == WNN_FT_DICT_FILE && (which & 0x02))
|
|
|
1111 {
|
|
|
1112 jt = (struct JT *) wf->area;
|
|
|
1113 if (check_and_change_pwd (jt->hpasswd, old, new) == -1)
|
|
|
1114 return (-1);
|
|
|
1115 jt->dirty = 1;
|
|
|
1116 }
|
|
|
1117 return (0);
|
|
|
1118 }
|
|
|
1119
|
|
|
1120 static int
|
|
|
1121 check_and_change_pwd (char *pwd, char *old, char *new)
|
|
|
1122 {
|
|
|
1123 if (!check_pwd (old, pwd))
|
|
|
1124 {
|
|
|
1125 wnn_errorno = WNN_INCORRECT_PASSWD;
|
|
|
1126 return (-1);
|
|
|
1127 }
|
|
|
1128 new_pwd (new, pwd);
|
|
|
1129 return (0);
|
|
|
1130 }
|