0
|
1 /*
|
|
2 * $Id: jbiki_b.c,v 1.3 2001/06/14 18:16:02 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 /** cWnn Version 1.1 **/
|
|
33
|
|
34 /********************************************
|
|
35 Modified by Zhong in Sept.1 1990
|
|
36 *********************************************
|
|
37 */
|
|
38 #include <stdio.h>
|
|
39 #include "commonhd.h"
|
|
40
|
|
41 #include "de_header.h"
|
|
42 #include "jdata.h"
|
|
43 #include "kaiseki.h"
|
|
44
|
|
45 #ifdef CONVERT_by_STROKE
|
|
46
|
|
47 #ifndef min
|
|
48 #define min(a, b) ( ((a) > (b))? (b):(a) )
|
|
49 #define max(a, b) ( ((a) < (b))? (b):(a) )
|
|
50 #endif
|
|
51
|
|
52 #define MAX_B_KOHO 64
|
|
53 #define MIN_B_KOHO 5
|
|
54
|
|
55 static void rd_biki_b (), set_kohos (), koho_insert (), b_koho_put ();
|
|
56 static int set_value ();
|
|
57
|
|
58 static int number; /** クライアントの辞書番号 */
|
|
59 static int prior;
|
|
60 static unsigned short *hinsistart;
|
|
61 static UCHAR *hindoin;
|
|
62 static UCHAR *hindostart;
|
|
63 static UCHAR *hindo2start;
|
|
64
|
|
65 struct b_koho *p_kohos[MAX_B_KOHO]; /* BiXing koho Buffer' Index */
|
|
66 struct b_koho b_kohos[MAX_B_KOHO]; /* BiXing koho Buffer */
|
|
67 static struct b_koho *cur_koho; /* */
|
|
68 static struct b_koho *last_koho; /* */
|
|
69 int cnt_k; /* Current koho */
|
|
70 int max_b_koho; /* MAX num of b_koho */
|
|
71
|
|
72 int
|
|
73 is_bwnn_rev_dict ()
|
|
74 {
|
|
75 int k;
|
|
76 struct JT *jt;
|
|
77
|
|
78 for (k = 0; k < c_env->jishomax; k++)
|
|
79 {
|
|
80 number = c_env->jisho[k];
|
|
81 if (dic_table[c_env->jisho[k]].enablef)
|
|
82 {
|
|
83 jt = (struct JT *) (files[dic_table[c_env->jisho[k]].body].area);
|
|
84 if (jt->syurui == BWNN_REV_DICT && dic_table[c_env->jisho[k]].rev == 0)
|
|
85 {
|
|
86 return (1);
|
|
87 }
|
|
88 else
|
|
89 {
|
|
90 return (0);
|
|
91 }
|
|
92 }
|
|
93 }
|
|
94 return (0);
|
|
95 }
|
|
96
|
|
97 int
|
|
98 jishobiki_b (b_bgn, b_end) /* return number of b_koho */
|
|
99 int b_bgn;
|
|
100 int b_end;
|
|
101 {
|
|
102 register struct JT *jt;
|
|
103 int b_ptr; /* point to b_node */
|
|
104 register int k;
|
|
105
|
|
106 max_b_koho = min (MAX_B_KOHO, c_env->fuzokogo_val);
|
|
107 max_b_koho = max (MIN_B_KOHO, max_b_koho);
|
|
108 cnt_k = 0;
|
|
109 cur_koho = b_kohos; /* set init koho address */
|
|
110 last_koho = NULL;
|
|
111
|
|
112 for (k = 0; k < c_env->jishomax; k++)
|
|
113 {
|
|
114 number = c_env->jisho[k];
|
|
115 if (dic_table[c_env->jisho[k]].enablef)
|
|
116 {
|
|
117 jt = (struct JT *) (files[dic_table[c_env->jisho[k]].body].area);
|
|
118 prior = dic_table[c_env->jisho[k]].nice;
|
|
119
|
|
120 hindo2start = (dic_table[c_env->jisho[k]].hindo != -1) ? jt->hindo : NULL;
|
|
121 hindostart = (dic_table[c_env->jisho[k]].hindo != -1) ? ((struct HJT *) (files[dic_table[c_env->jisho[k]].hindo].area))->hindo : jt->hindo;
|
|
122
|
|
123 hinsistart = jt->hinsi;
|
|
124 if (jt->syurui == BWNN_REV_DICT)
|
|
125 {
|
|
126 b_ptr = jt->bind[0].pter_son;
|
|
127 rd_biki_b (jt, b_bgn, b_end - 1, b_ptr);
|
|
128 }
|
|
129 }
|
|
130 }
|
|
131 if (last_koho == NULL)
|
|
132 return (-1);
|
|
133 cnt_k = 0;
|
|
134 b_koho_put (last_koho); /* put b_kohos in sequence */
|
|
135 return (cnt_k);
|
|
136 }
|
|
137
|
|
138 /****************************************
|
|
139 "rd_biki_b()" is a recursive function, used for recursively search the
|
|
140 "b_index". When it is first called by "jishobiki_b()", the second
|
|
141 param "cur" is equel to one. " cur will become 2,3 .., when it is
|
|
142 called by itself for further deep levels.
|
|
143 **************************************/
|
|
144 static void
|
|
145 rd_biki_b (jt, cur, bend, b_ptr)
|
|
146 struct JT *jt; /* dic head */
|
|
147 int cur; /* Input: input lenths */
|
|
148 int bend;
|
|
149 int b_ptr; /* Input: point to current b_node */
|
|
150 {
|
|
151 w_char *yo_kanji; /*pointing to yomi or kanji of a tuple */
|
|
152 struct b_node *bind;
|
|
153 int tmp_b_ptr;
|
|
154
|
|
155 bind = jt->bind;
|
|
156
|
|
157 if (bun[cur] == Q_MARK)
|
|
158 { /* Ignored w_char */
|
|
159 while (b_ptr != -1)
|
|
160 {
|
|
161 if (cur == bend)
|
|
162 set_kohos (jt, bind[b_ptr].pter);
|
|
163 else
|
|
164 rd_biki_b (jt, cur + 1, bend, bind[b_ptr].pter_son);
|
|
165 b_ptr = bind[b_ptr].pter_next;
|
|
166 }
|
|
167 return;
|
|
168 }
|
|
169 while (b_ptr != -1)
|
|
170 {
|
|
171 tmp_b_ptr = b_ptr;
|
|
172 while (bind[tmp_b_ptr].pter == -1)
|
|
173 tmp_b_ptr = bind[tmp_b_ptr].pter_son;
|
|
174 yo_kanji = KANJI_str (jt->ri2[bind[tmp_b_ptr].pter].kanjipter + jt->kanji, 0);
|
|
175 if (bun[cur] > yo_kanji[cur - 1])
|
|
176 b_ptr = bind[b_ptr].pter_next;
|
|
177 else
|
|
178 break;
|
|
179 }
|
|
180
|
|
181 if (b_ptr == -1)
|
|
182 return; /* not searched */
|
|
183 tmp_b_ptr = b_ptr;
|
|
184 while (bind[tmp_b_ptr].pter == -1)
|
|
185 tmp_b_ptr = bind[tmp_b_ptr].pter_son;
|
|
186 yo_kanji = KANJI_str (jt->ri2[bind[tmp_b_ptr].pter].kanjipter + jt->kanji, 0);
|
|
187 if (bun[cur] < yo_kanji[cur - 1])
|
|
188 return; /* not searched */
|
|
189
|
|
190 if (bun[cur] == yo_kanji[cur - 1])
|
|
191 { /* searched */
|
|
192
|
|
193 if (cur == bend) /* Set kohos */
|
|
194 set_kohos (jt, bind[b_ptr].pter);
|
|
195 else if (bind[b_ptr].pter_son != -1)
|
|
196 rd_biki_b (jt, cur + 1, bend, bind[b_ptr].pter_son);
|
|
197 }
|
|
198 }
|
|
199
|
|
200 static void
|
|
201 set_kohos (jt, cur_off2)
|
|
202 struct JT *jt;
|
|
203 int cur_off2;
|
|
204 {
|
|
205 for (; cur_off2 != -1; cur_off2 = jt->ri2[cur_off2].next[0])
|
|
206 {
|
|
207
|
|
208
|
|
209 if (hindo2start && (*(hindo2start + cur_off2) & 0x7f) == 0x7f || (*(hindostart + cur_off2) & 0x7f) == 0x7f)
|
|
210 continue; /* Check masked word */
|
|
211
|
|
212 if (cnt_k < max_b_koho) /* is not a full table */
|
|
213 cnt_k++;
|
|
214 else
|
|
215 {
|
|
216 cur_koho = last_koho;
|
|
217 last_koho = last_koho->previou;
|
|
218 }
|
|
219 cur_koho->p_yomi = KANJI_str (((jt->ri2) + cur_off2)->kanjipter + jt->kanji, 0);
|
|
220 cur_koho->p_kanji = KANJI_str (((jt->ri2) + cur_off2)->kanjipter + jt->kanji, 1);
|
|
221 cur_koho->p_hinsi = hinsistart + cur_off2;
|
|
222 /* cur_off2 is serial */
|
|
223 cur_koho->p_hindo = hindostart + cur_off2;
|
|
224 if (hindo2start)
|
|
225 hindoin = hindo2start + cur_off2;
|
|
226 else
|
|
227 hindoin = NULL;
|
|
228 cur_koho->dic_no = number;
|
|
229 cur_koho->serial = cur_off2;
|
|
230 koho_insert (cur_koho);
|
|
231 cur_koho++;
|
|
232 }
|
|
233 }
|
|
234
|
|
235 static void
|
|
236 koho_insert (c_koho)
|
|
237 register struct b_koho *c_koho;
|
|
238 {
|
|
239 register struct b_koho *t_koho1;
|
|
240 register struct b_koho *t_koho2;
|
|
241
|
|
242 if (last_koho == NULL)
|
|
243 { /* for first koho */
|
|
244 c_koho->value = set_value (c_koho);
|
|
245 last_koho = c_koho;
|
|
246 c_koho->previou = NULL;
|
|
247 return;
|
|
248 }
|
|
249 t_koho1 = last_koho;
|
|
250 t_koho2 = last_koho;
|
|
251 c_koho->value = set_value (c_koho);
|
|
252
|
|
253 while ((t_koho1 != NULL) && ((t_koho1->value) <= (c_koho->value)))
|
|
254 {
|
|
255 t_koho2 = t_koho1;
|
|
256 t_koho1 = t_koho1->previou;
|
|
257 }
|
|
258 if (t_koho1 == t_koho2) /* c_koho is the last koho */
|
|
259 last_koho = c_koho;
|
|
260 else
|
|
261 t_koho2->previou = c_koho;
|
|
262 c_koho->previou = t_koho1;
|
|
263 }
|
|
264
|
|
265 static int
|
|
266 set_value (koho)
|
|
267 struct b_koho *koho;
|
|
268 {
|
|
269 if (hindoin != NULL)
|
|
270 return (hyoka1 (*(koho->p_hindo), *hindoin, 0, 0, prior));
|
|
271 else
|
|
272 return (hyoka1 (*(koho->p_hindo), 0, 0, 0, prior));
|
|
273 }
|
|
274
|
|
275 static void
|
|
276 b_koho_put (last) /* put b_kohos in sequence */
|
|
277 struct b_koho *last;
|
|
278 {
|
|
279 if (last->previou != NULL)
|
|
280 b_koho_put (last->previou);
|
|
281 p_kohos[cnt_k++] = last;
|
|
282 }
|
|
283 #endif /* CONVERT_by_STROKE */
|