0
|
1 /*
|
|
2 * $Id: do_dic_env.c,v 1.5 2001/06/14 18:28:53 ura 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
|
|
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 * Do Dic operation for Env
|
|
34 */
|
|
35
|
|
36 #include <stdio.h>
|
|
37
|
|
38 #include "commonhd.h"
|
|
39 #include "demcom.h"
|
|
40 #include "de_header.h"
|
|
41 #include "jdata.h"
|
|
42
|
|
43
|
|
44 static void del_dic_from_env (), dic_delete ();
|
|
45
|
|
46 /*
|
|
47 Dic. OPE for Env
|
|
48 */
|
|
49
|
|
50 /* js_dic_add */
|
|
51 void
|
|
52 js_dic_add ()
|
|
53 {
|
|
54 int eid, fid, hfid, nice, rw, hrw, dic_no, d, rev;
|
|
55 char pw[WNN_PASSWD_LEN], pw1[WNN_PASSWD_LEN];
|
|
56 eid = get4_cur ();
|
|
57 fid = get4_cur ();
|
|
58 hfid = get4_cur ();
|
|
59 nice = get4_cur ();
|
|
60 rw = get4_cur ();
|
|
61 hrw = get4_cur ();
|
|
62 gets_cur (pw, WNN_PASSWD_LEN);
|
|
63 gets_cur (pw1, WNN_PASSWD_LEN);
|
|
64 rev = get4_cur (); /* rev is to add it as reverse dict */
|
|
65
|
|
66 error1 ("dic_add: eid=%d,fid=%d,hfid=%d", eid, fid, hfid);
|
|
67 c_env = env[eid];
|
|
68 if (find_fid_in_env (eid, fid) == -1)
|
|
69 {
|
|
70 wnn_errorno = WNN_FID_ERROR;
|
|
71 error_ret ();
|
|
72 putc_purge ();
|
|
73 return;
|
|
74 }
|
|
75 if (files[fid].file_type != WNN_FT_DICT_FILE)
|
|
76 {
|
|
77 wnn_errorno = WNN_NOT_A_DICT;
|
|
78 error_ret ();
|
|
79 putc_purge ();
|
|
80 return;
|
|
81 }
|
|
82 if (rev &&
|
|
83 #ifdef CONVERT_by_STROKE
|
|
84 ((struct JT *) (files[fid].area))->syurui != BWNN_REV_DICT &&
|
|
85 #endif /* CONVERT_by_STROKE */
|
|
86 #ifdef CONVERT_with_SiSheng
|
|
87 ((struct JT *) (files[fid].area))->syurui != CWNN_REV_DICT &&
|
|
88 #endif /* CONVERT_with_SiSheng */
|
|
89 ((struct JT *) (files[fid].area))->syurui != WNN_REV_DICT)
|
|
90 {
|
|
91 wnn_errorno = WNN_NOT_A_REV;
|
|
92 error_ret ();
|
|
93 putc_purge ();
|
|
94 return;
|
|
95 }
|
|
96
|
|
97 if (rw == WNN_DIC_RW && ((struct JT *) (files[fid].area))->syurui != WNN_UD_DICT &&
|
|
98 #ifdef CONVERT_by_STROKE
|
|
99 ((struct JT *) (files[fid].area))->syurui != BWNN_REV_DICT &&
|
|
100 #endif /* CONVERT_by_STROKE */
|
|
101 #ifdef CONVERT_with_SiSheng
|
|
102 ((struct JT *) (files[fid].area))->syurui != CWNN_REV_DICT &&
|
|
103 #endif /* CONVERT_with_SiSheng */
|
|
104 ((struct JT *) (files[fid].area))->syurui != WNN_REV_DICT)
|
|
105 {
|
|
106 wnn_errorno = WNN_NOT_A_UD;
|
|
107 error_ret ();
|
|
108 putc_purge ();
|
|
109 return;
|
|
110 }
|
|
111 if (hfid != -1)
|
|
112 { /* hindo file selected */
|
|
113 if (find_fid_in_env (eid, hfid) == -1)
|
|
114 {
|
|
115 wnn_errorno = WNN_FID_ERROR;
|
|
116 error_ret ();
|
|
117 putc_purge ();
|
|
118 return;
|
|
119 }
|
|
120 if (files[hfid].file_type != WNN_FT_HINDO_FILE)
|
|
121 {
|
|
122 wnn_errorno = WNN_NOT_A_HINDO_FILE;
|
|
123 error_ret ();
|
|
124 putc_purge ();
|
|
125 return;
|
|
126 }
|
|
127 if (!match_dic_and_hindo_p (&files[fid], &files[hfid]))
|
|
128 {
|
|
129 wnn_errorno = WNN_HINDO_NO_MATCH;
|
|
130 error_ret ();
|
|
131 putc_purge ();
|
|
132 return;
|
|
133 }
|
|
134 if (hrw == WNN_DIC_RW && !check_pwd (pw1, files[hfid].passwd))
|
|
135 {
|
|
136 wnn_errorno = WNN_INCORRECT_PASSWD;
|
|
137 error_ret ();
|
|
138 putc_purge ();
|
|
139 return;
|
|
140 }
|
|
141 }
|
|
142
|
|
143 if (rw == WNN_DIC_RW && !check_pwd (pw, files[fid].passwd))
|
|
144 {
|
|
145 wnn_errorno = WNN_INCORRECT_PASSWD;
|
|
146 error_ret ();
|
|
147 putc_purge ();
|
|
148 return;
|
|
149 }
|
|
150 if (hfid == -1 && hrw == WNN_DIC_RW && !check_pwd (pw1, ((struct JT *) (files[fid].area))->hpasswd))
|
|
151 {
|
|
152 wnn_errorno = WNN_INCORRECT_PASSWD;
|
|
153 error_ret ();
|
|
154 putc_purge ();
|
|
155 return;
|
|
156 }
|
|
157 if ((d = chk_dic (eid, fid)) != -1)
|
|
158 { /* already added that file */
|
|
159 dic_table[d].enablef = 1;
|
|
160 dic_table[d].rw = rw;
|
|
161
|
|
162 if (hfid != -1)
|
|
163 { /* change hindo file */
|
|
164 dic_table[d].hindo = hfid;
|
|
165 hindo_file_size_justify (&files[fid], &files[hfid]);
|
|
166 }
|
|
167 else
|
|
168 {
|
|
169 dic_table[d].hindo = -1;
|
|
170 }
|
|
171 dic_table[d].hindo_rw = hrw;
|
|
172 dic_table[d].nice = nice;
|
|
173 dic_table[d].rev = rev;
|
|
174 put4_cur (d);
|
|
175 putc_purge ();
|
|
176 return;
|
|
177 }
|
|
178
|
|
179 /* add new dic */
|
|
180 if ((dic_no = get_new_dic ()) == -1)
|
|
181 { /* no more dic */
|
|
182 wnn_errorno = WNN_JISHOTABLE_FULL;
|
|
183 error_ret ();
|
|
184 putc_purge ();
|
|
185 return;
|
|
186 }
|
|
187 if (add_dic_to_env (eid, dic_no))
|
|
188 { /* no more jisho */
|
|
189 wnn_errorno = WNN_JISHOTABLE_FULL;
|
|
190 error_ret ();
|
|
191 putc_purge ();
|
|
192 return;
|
|
193 }
|
|
194 if (hfid != -1)
|
|
195 {
|
|
196 hindo_file_size_justify (&files[fid], &files[hfid]);
|
|
197 }
|
|
198 dic_table[dic_no].body = fid;
|
|
199 dic_table[dic_no].hindo = hfid;
|
|
200 dic_table[dic_no].rw = rw;
|
|
201 dic_table[dic_no].hindo_rw = hrw;
|
|
202 dic_table[dic_no].enablef = 1;
|
|
203 dic_table[dic_no].nice = nice;
|
|
204 dic_table[dic_no].rev = rev;
|
|
205 put4_cur (dic_no);
|
|
206 putc_purge ();
|
|
207 }
|
|
208
|
|
209 int
|
|
210 add_dic_to_env (eid, dic_no)
|
|
211 int eid, dic_no;
|
|
212 {
|
|
213 int off_env;
|
|
214 struct cnv_env *cenv;
|
|
215 cenv = env[eid];
|
|
216 off_env = cenv->jishomax;
|
|
217 if (off_env >= WNN_MAX_JISHO_OF_AN_ENV)
|
|
218 { /* no more jisho */
|
|
219 wnn_errorno = WNN_JISHOTABLE_FULL;
|
|
220 return -1;
|
|
221 }
|
|
222 (cenv->jisho)[off_env] = dic_no;
|
|
223 cenv->jishomax = off_env + 1;
|
|
224 return 0;
|
|
225 }
|
|
226
|
|
227 int
|
|
228 chk_dic (eid, fid)
|
|
229 int eid, fid;
|
|
230 {
|
|
231 int i, dic, max;
|
|
232 max = env[eid]->jishomax;
|
|
233 for (i = 0; i < max; i++)
|
|
234 {
|
|
235 dic = (env[eid]->jisho)[i];
|
|
236 if (dic_table[dic].body == fid)
|
|
237 return dic;
|
|
238 }
|
|
239 return -1;
|
|
240 }
|
|
241
|
|
242 int
|
|
243 chk_hindo (eid, fid)
|
|
244 int eid, fid;
|
|
245 {
|
|
246 int i, dic, max;
|
|
247 max = env[eid]->jishomax;
|
|
248 for (i = 0; i < max; i++)
|
|
249 {
|
|
250 dic = (env[eid]->jisho)[i];
|
|
251 if (dic_table[dic].hindo == fid)
|
|
252 return dic;
|
|
253 }
|
|
254 return -1;
|
|
255 }
|
|
256
|
|
257 int
|
|
258 get_new_dic ()
|
|
259 {
|
|
260 int i;
|
|
261 for (i = 0; i < MAX_DIC; i++)
|
|
262 {
|
|
263 if (dic_table[i].body == -1)
|
|
264 return i;
|
|
265 }
|
|
266 return -1;
|
|
267 }
|
|
268
|
|
269 /* search jisho of an env (dic_no == -1 then new dic) */
|
|
270 int
|
|
271 find_dic_in_env (eid, dic_no)
|
|
272 int eid, dic_no;
|
|
273 {
|
|
274 int i, max;
|
|
275 max = env[eid]->jishomax;
|
|
276 for (i = 0; i < max; i++)
|
|
277 {
|
|
278 if ((env[eid]->jisho)[i] == dic_no)
|
|
279 return i;
|
|
280 }
|
|
281 return -1;
|
|
282 }
|
|
283
|
|
284 /* js_dic_delete */
|
|
285 void
|
|
286 js_dic_delete ()
|
|
287 {
|
|
288 int eid, off_env, dic_no;
|
|
289 eid = get4_cur ();
|
|
290 c_env = env[eid];
|
|
291 dic_no = get4_cur ();
|
|
292 if ((off_env = find_dic_in_env (eid, dic_no)) == -1)
|
|
293 { /* no such dic */
|
|
294 wnn_errorno = WNN_DICT_NOT_USED;
|
|
295 error_ret ();
|
|
296 putc_purge ();
|
|
297 return;
|
|
298 }
|
|
299 dic_table[dic_no].body = -1;
|
|
300 dic_table[dic_no].hindo = -1;
|
|
301
|
|
302 del_dic_from_env (eid, off_env);
|
|
303 put4_cur (0);
|
|
304 putc_purge ();
|
|
305 }
|
|
306
|
|
307
|
|
308 static void
|
|
309 del_dic_from_env (eid, off_env)
|
|
310 int eid, off_env;
|
|
311 {
|
|
312 int *jisho, max, i;
|
|
313 struct cnv_env *cenv;
|
|
314
|
|
315 cenv = env[eid];
|
|
316 jisho = cenv->jisho;
|
|
317 max = --(cenv->jishomax);
|
|
318 for (i = off_env; i < max; i++)
|
|
319 {
|
|
320 jisho[i] = jisho[i + 1];
|
|
321 }
|
|
322 }
|
|
323
|
|
324 /* delete all Dic. in an Env , when disconnect */
|
|
325 void
|
|
326 del_all_dic_in_env (eid)
|
|
327 int eid;
|
|
328 {
|
|
329 int *jisho, max, i;
|
|
330
|
|
331 jisho = env[eid]->jisho;
|
|
332 max = env[eid]->jishomax;
|
|
333 for (i = 0; i < max; i++)
|
|
334 {
|
|
335 dic_table[jisho[i]].body = -1;
|
|
336 dic_table[jisho[i]].hindo = -1;
|
|
337 }
|
|
338 env[eid]->jishomax = 0;
|
|
339 }
|
|
340
|
|
341
|
|
342 /* js_dic_list_all */
|
|
343 void
|
|
344 js_dic_list_all ()
|
|
345 {
|
|
346 int c, i, dic_no;
|
|
347
|
|
348 for (c = i = 0; i < MAX_DIC; i++)
|
|
349 {
|
|
350 if (dic_table[i].body == -1)
|
|
351 continue;
|
|
352 c++;
|
|
353 }
|
|
354 put4_cur (c);
|
|
355
|
|
356 for (dic_no = 0; dic_no < MAX_DIC; dic_no++)
|
|
357 {
|
|
358 if (dic_table[dic_no].body == -1)
|
|
359 continue;
|
|
360 put_dic_info (dic_no);
|
|
361 }
|
|
362 putc_purge ();
|
|
363 }
|
|
364
|
|
365 /* js_dic_list */
|
|
366 void
|
|
367 js_dic_list ()
|
|
368 {
|
|
369 int eid, i, dic_no, max;
|
|
370 eid = get4_cur ();
|
|
371 c_env = env[eid];
|
|
372 max = env[eid]->jishomax;
|
|
373 put4_cur (max);
|
|
374 for (i = 0; i < max; i++)
|
|
375 {
|
|
376 dic_no = (env[eid]->jisho)[i];
|
|
377 put_dic_info (dic_no);
|
|
378 }
|
|
379 putc_purge ();
|
|
380 }
|
|
381
|
|
382 /* js_dic_use */
|
|
383 void
|
|
384 js_dic_use ()
|
|
385 {
|
|
386 int eid, dic_no, enable;
|
|
387 eid = get4_cur ();
|
|
388 c_env = env[eid];
|
|
389 dic_no = get4_cur ();
|
|
390 enable = get4_cur ();
|
|
391 if (find_dic_in_env (eid, dic_no) == -1)
|
|
392 { /* no such dic */
|
|
393 wnn_errorno = WNN_DICT_NOT_USED;
|
|
394 error_ret ();
|
|
395 putc_purge ();
|
|
396 return;
|
|
397 }
|
|
398 if (enable < 0 || enable > 1)
|
|
399 {
|
|
400 error_ret ();
|
|
401 return;
|
|
402 }
|
|
403 dic_table[dic_no].enablef = enable;
|
|
404 put4_cur (0);
|
|
405 putc_purge ();
|
|
406 }
|
|
407
|
|
408 /* js_fuzokugo_set */
|
|
409 void
|
|
410 js_fuzokugo_set ()
|
|
411 {
|
|
412 int eid, fid;
|
|
413
|
|
414 eid = get4_cur ();
|
|
415 c_env = env[eid];
|
|
416 fid = get4_cur ();
|
|
417 if (find_fid_in_env (eid, fid) == -1)
|
|
418 { /* valid */
|
|
419 wnn_errorno = WNN_FID_ERROR;
|
|
420 error_ret ();
|
|
421 putc_purge ();
|
|
422 return;
|
|
423 }
|
|
424 if (files[fid].file_type != WNN_FT_FUZOKUGO_FILE)
|
|
425 {
|
|
426 wnn_errorno = WNN_NOT_A_FUZOKUGO_FILE;
|
|
427 error_ret ();
|
|
428 putc_purge ();
|
|
429 return;
|
|
430 }
|
|
431 if (find_fid_in_env (eid, fid) == -1)
|
|
432 { /* H.T. */
|
|
433 wnn_errorno = WNN_FID_ERROR;
|
|
434 error_ret ();
|
|
435 putc_purge ();
|
|
436 return;
|
|
437 }
|
|
438 env[eid]->fzk_fid = fid;
|
|
439 put4_cur (0);
|
|
440 putc_purge ();
|
|
441 }
|
|
442
|
|
443 /* js_fuzokugo_get */
|
|
444 void
|
|
445 js_fuzokugo_get ()
|
|
446 {
|
|
447 int eid;
|
|
448
|
|
449 eid = get4_cur ();
|
|
450 c_env = env[eid];
|
|
451
|
|
452 if (env[eid]->fzk_fid == -1)
|
|
453 {
|
|
454 wnn_errorno = WNN_FZK_FILE_NO_LOAD;
|
|
455 error_ret ();
|
|
456 putc_purge ();
|
|
457 return;
|
|
458 }
|
|
459 put4_cur (env[eid]->fzk_fid);
|
|
460 putc_purge ();
|
|
461 }
|
|
462
|
|
463
|
|
464 /* Delete Used Dicts and Fuzokugo's H. T. */
|
|
465 void
|
|
466 used_dic_fuzoku_delete (eid, fid)
|
|
467 int eid;
|
|
468 int fid;
|
|
469 {
|
|
470 int i, max;
|
|
471 register int dic_no;
|
|
472 max = env[eid]->jishomax;
|
|
473 if (env[eid]->fzk_fid == fid)
|
|
474 {
|
|
475 env[eid]->fzk_fid = -1;
|
|
476 return;
|
|
477 }
|
|
478 for (i = 0; i < max; i++)
|
|
479 {
|
|
480 dic_no = (env[eid]->jisho)[i];
|
|
481 if (dic_table[dic_no].body == fid || dic_table[dic_no].hindo == fid)
|
|
482 {
|
|
483 dic_delete (eid, dic_no, i);
|
|
484 return;
|
|
485 }
|
|
486 }
|
|
487 }
|
|
488
|
|
489
|
|
490 static void
|
|
491 dic_delete (eid, dic_no, off_env)
|
|
492 int eid;
|
|
493 int dic_no;
|
|
494 int off_env;
|
|
495 {
|
|
496 dic_table[dic_no].body = -1;
|
|
497 dic_table[dic_no].hindo = -1;
|
|
498 del_dic_from_env (eid, off_env);
|
|
499 }
|