1 /*
2  *  $Id: do_henkan1.c,v 1.7 2003/05/11 18:41:49 hiroo 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, 2003
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 #if defined(HAVE_CONFIG_H)
33 #include <config.h>
34 #endif
35 
36 #include <stdio.h>
37 #include <ctype.h>
38 
39 #if defined(HAVE_SYS_TYPES_H)
40 #include <sys/types.h>
41 #endif
42 
43 #include "demcom.h"
44 #include "commonhd.h"
45 #include "de_header.h"
46 #include "jdata.h"
47 #include "fzk.h"
48 
49 #include "kaiseki.h"
50 
51 #define FZK_L 256
52 #ifdef  putwchar
53 #undef  putwchar
54 #endif
55 
56 static int make_buns_par ();
57 
58 static int bun_pter_;
59 
60 static int
henkan_setup()61 henkan_setup ()
62 {
63   register int index;
64   register w_char c;
65 
66   wnn_loadhinsi (hinsi_file_name);
67 #ifdef  CONVERT_from_TOP
68   index = 1;
69 #else
70   index = maxchg - 1;
71 #endif
72   while ((c = get2_cur ()) != 0)
73     {
74 #ifdef  DEBUG
75       putwchar (c);
76 #endif
77       if (make_buns_par (c, index) == -1)
78         {
79           while ((c = get2_cur ()) != 0);       /* dummy get */
80           return (-1);
81         }
82 #ifdef  CONVERT_from_TOP
83       index++;
84 #else
85       index--;
86 #endif
87     }
88 #ifdef  CONVERT_from_TOP
89   bun_pter_ = index;
90 #else
91   bun_pter_ = index + 1;
92 #endif
93   init_jmt ();
94 #ifdef  DEBUG
95   wsputs ("\n");
96 #endif
97   return (0);
98 }
99 
100 static void
get_fzk_vec(hinsi,fzk,fzk_size,vec,vec1)101 get_fzk_vec (hinsi, fzk, fzk_size, vec, vec1)
102      register int *hinsi;
103      register w_char *fzk;
104      register size_t fzk_size;
105      register int *vec;
106      register int *vec1;
107 {
108   *hinsi = get4_cur ();
109   getws_cur (fzk, fzk_size);
110   *vec = get4_cur ();
111   *vec1 = get4_cur ();
112 }
113 
114 #ifdef CHINESE
115 static void
do_question(daip,zenp)116 do_question (daip, zenp)
117      int daip, zenp;
118 {
119   int b_suu_;
120 
121   b_suu_ = jishobiki_b (1, bun_pter_, 0);
122   if (b_suu_ < 0)
123     {
124       error_ret ();             /* ERROR */
125       return;
126     }
127   if (zenp == WNN_BUN)
128     b_suu_ = (b_suu_ == 0) ? 0 : 1;
129   if (daip == WNN_DAI)
130     ret_daiB (1, bun_pter_, b_suu_, zenp);
131   else
132     ret_B (1, bun_pter_, b_suu_, zenp);
133   putc_purge ();
134 }
135 #endif
136 
137 /* RENBUN */
138 void
do_kanren()139 do_kanren ()
140 {
141   int end, eid;
142   int vec;
143   int vec1;
144   int vec2;
145   w_char fzk[FZK_L];
146   struct DSD_DBN *d_list;
147   register int b_suu_;
148   int hinsi;
149   int err;
150 
151   eid = get4_cur ();
152   c_env = env[eid];
153   end = maxchg - 1;
154   err = henkan_setup ();
155   get_fzk_vec (&hinsi, fzk, FZK_L, &vec, &vec1);
156   vec2 = get4_cur ();
157   if (err == -1)
158     {
159       error_ret ();             /* ERROR */
160       return;
161     }
162 
163 #ifdef CHINESE
164   if (is_bwnn_rev_dict ())
165     {
166       do_question (WNN_DAI, WNN_BUN);
167       return;
168     }
169 #endif /* CHINESE */
170 
171   b_suu_ = renbn_kai (
172 #ifdef  CONVERT_from_TOP
173                        1, bun_pter_,
174 #else
175                        bun_pter_, end + 1,
176 #endif
177                        hinsi,
178 #ifndef NO_FZK
179                        fzk,
180 #endif
181                        vec, vec1, vec2, c_env->nbun, c_env->nshobun, &d_list);
182   if (b_suu_ < 0)
183     {
184       error_ret ();             /* ERROR */
185       return;
186     }
187   ret_dai (d_list, b_suu_);
188   putc_purge ();
189 #ifdef  DEBUG
190   print_dlist (d_list, b_suu_);
191 #endif
192 }
193 
194 /* TANBUN (dai)*/
195 void
do_kantan_dai()196 do_kantan_dai ()
197 {
198   int end, eid;
199   int vec;
200   int vec1;
201   w_char fzk[FZK_L];
202   struct DSD_DBN *d_list;
203   register int b_suu_;
204   int hinsi;
205   int err;
206 
207   eid = get4_cur ();
208   c_env = env[eid];
209   end = maxchg - 1;
210   err = henkan_setup ();
211   get_fzk_vec (&hinsi, fzk, FZK_L, &vec, &vec1);
212   if (err == -1)
213     {
214       error_ret ();             /* ERROR */
215       return;
216     }
217 
218 #ifdef CHINESE
219   if (is_bwnn_rev_dict ())
220     {
221       do_question (WNN_DAI, WNN_BUN);
222       return;
223     }
224 #endif /* CHINESE */
225   b_suu_ = tan_dai (
226 #ifdef  CONVERT_from_TOP
227                      1, bun_pter_,
228 #else
229                      bun_pter_, end + 1,
230 #endif
231                      hinsi,
232 #ifndef NO_FZK
233                      fzk,
234 #endif
235                      vec, vec1, c_env->nshobun, &d_list);
236   if (b_suu_ < 0)
237     {
238       error_ret ();             /* ERROR */
239       return;
240     }
241   ret_dai (d_list, b_suu_);
242   putc_purge ();
243 #ifdef  DEBUG
244   print_dlist (d_list, b_suu_);
245 #endif
246 }
247 
248 /* TANBUN (sho)*/
249 void
do_kantan_sho()250 do_kantan_sho ()
251 {
252   int end, eid;
253   int vec;
254   int vec1;
255   w_char fzk[FZK_L];
256   struct DSD_SBN *d_list1;
257   register int b_suu_;
258   int hinsi;
259   int err;
260 
261   eid = get4_cur ();
262   c_env = env[eid];
263   end = maxchg - 1;
264   err = henkan_setup ();
265   get_fzk_vec (&hinsi, fzk, FZK_L, &vec, &vec1);
266   if (err == -1)
267     {
268       error_ret ();             /* ERROR */
269       return;
270     }
271 
272 #ifdef CHINESE
273   if (is_bwnn_rev_dict ())
274     {
275       do_question (WNN_SHO, WNN_BUN);
276       return;
277     }
278 #endif /* CHINESE */
279   b_suu_ = tan_syo (
280 #ifdef  CONVERT_from_TOP
281                      1, bun_pter_,
282 #else
283                      bun_pter_, end + 1,
284 #endif
285                      hinsi,
286 #ifndef NO_FZK
287                      fzk,
288 #endif
289                      vec, vec1, &d_list1);
290   if (b_suu_ < 0)
291     {
292       error_ret ();             /* ERROR */
293       return;
294     }
295   ret_sho (d_list1, b_suu_);
296   putc_purge ();
297 #ifdef  DEBUG
298   print_dlist1 (d_list1, b_suu_);
299 #endif
300 }
301 
302 /* JIKOUHO (dai)*/
303 void
do_kanzen_dai()304 do_kanzen_dai ()
305 {
306   int end, eid;
307   int vec;
308   int vec1;
309   w_char fzk[FZK_L];
310   struct DSD_DBN *d_list;
311   register int b_suu_;
312   int hinsi;
313   int err;
314 
315   eid = get4_cur ();
316   c_env = env[eid];
317   end = maxchg - 1;
318   err = henkan_setup ();
319   get_fzk_vec (&hinsi, fzk, FZK_L, &vec, &vec1);
320   if (err == -1)
321     {
322       error_ret ();             /* ERROR */
323       return;
324     }
325 
326 #ifdef CHINESE
327   if (is_bwnn_rev_dict ())
328     {
329       do_question (WNN_DAI, WNN_ZENKOUHO);
330       return;
331     }
332 #endif /* CHINESE */
333   b_suu_ = jkt_get_dai (
334 #ifdef  CONVERT_from_TOP
335                          1, bun_pter_,
336 #else
337                          bun_pter_, end + 1,
338 #endif
339                          hinsi,
340 #ifndef NO_FZK
341                          fzk,
342 #endif
343                          vec, vec1, c_env->nshobun, &d_list);
344   if (b_suu_ < 0)
345     {
346       error_ret ();             /* ERROR */
347       return;
348     }
349   ret_dai (d_list, b_suu_);
350   putc_purge ();
351 #ifdef  DEBUG
352   print_dlist (d_list, b_suu_);
353 #endif
354 }
355 
356 /* JIKOUHO (sho)*/
357 void
do_kanzen_sho()358 do_kanzen_sho ()
359 {
360   int end, eid;
361   int vec;
362   int vec1;
363   w_char fzk[FZK_L];
364   struct DSD_SBN *d_list1;
365   register int b_suu_;
366   int hinsi;
367   int err;
368 
369   eid = get4_cur ();
370   c_env = env[eid];
371   end = maxchg - 1;
372   err = henkan_setup ();
373   get_fzk_vec (&hinsi, fzk, FZK_L, &vec, &vec1);
374   if (err == -1)
375     {
376       error_ret ();             /* ERROR */
377       return;
378     }
379 
380 #ifdef CHINESE
381   if (is_bwnn_rev_dict ())
382     {
383       do_question (WNN_SHO, WNN_ZENKOUHO);
384       return;
385     }
386 #endif /* CHINESE */
387   b_suu_ = jkt_get_syo (
388 #ifdef  CONVERT_from_TOP
389                          1, bun_pter_,
390 #else
391                          bun_pter_, end + 1,
392 #endif
393                          hinsi,
394 #ifndef NO_FZK
395                          fzk,
396 #endif
397                          vec, vec1, &d_list1);
398   if (b_suu_ < 0)
399     {
400       error_ret ();             /* ERROR */
401       return;
402     }
403 #ifdef  DEBUG
404   print_dlist1 (d_list1, b_suu_);
405 #endif
406   ret_sho (d_list1, b_suu_);
407   putc_purge ();
408 }
409 
410 static int
make_buns_par(c,at_index)411 make_buns_par (c, at_index)     /* make bun and bun     */
412      register w_char c;
413      register int at_index;
414 {
415   if ((at_index >= maxchg) || (at_index <= 0))
416     {
417       wnn_errorno = WNN_LONG_MOJIRETSU;
418       return (-1);
419     }
420   bun[at_index] = c;
421 
422   jmtp[at_index] = (struct jdata **) -1;        /* �����ޤ������Ƥ��ʤ� */
423   return (0);
424 }
425 
426 /* get kanji and put it in  kouho*/
427 void
Get_knj(jentptr,u,kouho,oy,oyl)428 Get_knj (jentptr, u, kouho, oy, oyl)
429      int u;
430      register struct jdata *jentptr;
431      w_char *kouho, *oy;
432      int oyl;
433 {
434   UCHAR *kptr;
435   register struct JT *jtl;
436 
437   jtl = (struct JT *) (files[dic_table[jentptr->jishono].body].area);
438   kptr = jtl->kanji + jentptr->kanji1;
439   if (jentptr->which == D_YOMI)
440     {
441       Get_knj1 (kptr, oy, oyl, jentptr->kanji2 + u, kouho, NULL, NULL);
442     }
443   else
444     {
445       Get_knj1 (kptr, oy, oyl, jentptr->kanji2 + u, NULL, kouho, NULL);
446     }
447 }
448 
449 #ifdef  no_def
450 void
get_yomi(jentptr,u,kouho)451 get_yomi (jentptr, u, kouho)    /* get yomi and put it in  kouho */
452      int u;
453      register struct jdata *jentptr;
454      w_char *kouho;
455 {
456   UCHAR *kptr;
457   register struct JT *jtl;
458 
459   jtl = (struct JT *) (files[dic_table[jentptr->jishono].body].area);
460   kptr = jtl->kanji + jentptr->kanji1;
461   Get_knj2 (kptr, jentptr->kanji2 + u, NULL, kouho, NULL);
462 }
463 #endif
464 
465 /* get comment and put it in  kouho*/
466 void
get_knj_com(jentptr,u,kouho,com)467 get_knj_com (jentptr, u, kouho, com)
468      int u;
469      register struct jdata *jentptr;
470      w_char *kouho;             /* kouho must be ended with NULL.       */
471      w_char *com;
472 {
473   register UCHAR *kptr;
474   struct JT *jtl;
475 
476   jtl = (struct JT *) (files[dic_table[jentptr->jishono].body].area);
477   kptr = jtl->kanji + jentptr->kanji1;
478   Get_knj2 (kptr, jentptr->kanji2 + u, kouho, NULL, com);
479 }
480