comparison Wnn/jserver/do_henkan.c @ 0:bbc77ca4def5

initial import
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Thu, 13 Dec 2007 04:30:14 +0900
parents
children 790205f476c0
comparison
equal deleted inserted replaced
-1:000000000000 0:bbc77ca4def5
1 /*
2 * $Id: do_henkan.c,v 1.5 2001/06/18 09:09:41 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 #if defined(HAVE_CONFIG_H)
33 #include <config.h>
34 #endif
35
36 #if defined(HAVE_SYS_TYPES_H)
37 #include <sys/types.h>
38 #endif
39
40 #include "commonhd.h"
41 #include "jslib.h"
42 #include "kaiseki.h"
43 #include "jdata.h"
44 #include "de_header.h"
45
46 static void ret_sho_x (), ret_sho_kanji (), ret_kanji ();
47 static int count_sho (), count_d_kanji (), count_s_kanji (), count_kanji ();
48
49 /* DAI BUN */
50 void
51 ret_dai (dai_list, cnt)
52 struct DSD_DBN *dai_list;
53 int cnt;
54 {
55 register int i;
56 register struct DSD_DBN *dp;
57 if (dai_list == NULL)
58 {
59 put4_cur (0);
60 return;
61 }
62 put4_cur (cnt);
63
64 put4_cur (count_sho (dai_list, cnt));
65 put4_cur (count_d_kanji (dai_list, cnt));
66
67 for (i = 0, dp = dai_list; i < cnt; dp++, i++)
68 {
69 #ifdef DEBUG
70 out ("\tbun_jc:%d, sbncnt:%d, bun_m:%d ,sbn:%x\n", dp->bun_jc, dp->sbncnt, dp->bun_m, dp->sbn);
71 #endif
72 #ifdef CONVERT_from_TOP
73 put4_cur (dp->bun_jc); /* end */
74 put4_cur (dp->bun_m); /* start */
75 #else
76 put4_cur (maxchg - 1 - dp->bun_m); /* end */
77 put4_cur (maxchg - 1 - dp->bun_jc); /* start */
78 #endif
79 put4_cur (dp->sbncnt);
80 put4_cur (dp->v_jc);
81 }
82 for (i = 0, dp = dai_list; i < cnt; dp++, i++)
83 {
84 ret_sho_x (dp->sbn, dp->sbncnt);
85 }
86 for (i = 0, dp = dai_list; i < cnt; dp++, i++)
87 {
88 ret_sho_kanji (dp->sbn, dp->sbncnt);
89 }
90 }
91
92 static int
93 count_sho (dai_list, cnt)
94 struct DSD_DBN *dai_list;
95 int cnt;
96 {
97 register int sho_sum, i;
98 register struct DSD_DBN *dp;
99 for (sho_sum = i = 0, dp = dai_list; i < cnt; dp++, i++)
100 {
101 sho_sum += dp->sbncnt;
102 }
103 return sho_sum;
104 }
105
106
107 static int
108 count_d_kanji (dp, cnt)
109 struct DSD_DBN *dp;
110 int cnt;
111 {
112 register int k_sum, i;
113 for (k_sum = i = 0; i < cnt; dp++, i++)
114 {
115 k_sum += count_s_kanji (dp->sbn, dp->sbncnt);
116 }
117 return k_sum;
118 }
119
120 static int
121 count_s_kanji (sp, cnt)
122 struct DSD_SBN *sp;
123 int cnt;
124 {
125 register int i, sho_sum;
126 if (sp == NULL)
127 cnt = 0;
128 sho_sum = 0;
129 for (i = 0; i < cnt; sp++, i++)
130 {
131 sho_sum += count_kanji (sp);
132 }
133 return sho_sum;
134 }
135
136 static int
137 count_kanji (sho)
138 struct DSD_SBN *sho;
139 {
140 register int tmp, k_sum;
141 w_char kouho[1000];
142
143 if (sho->jentptr)
144 {
145 Get_knj (sho->jentptr, sho->t_jc, kouho, bun + sho->i_jc, sho->bun_jc - sho->i_jc + 1);
146 }
147 else
148 {
149 get_giji_knj (sho->bun_jc, sho->i_jc, sho->t_jc, kouho);
150 }
151
152 k_sum = 0;
153 k_sum += Strlen (kouho) + 1; /* kanji */
154 /* yomi */
155 for (tmp = sho->bun_jc;; tmp--)
156 {
157 if (tmp < sho->bun_m)
158 break;
159 k_sum++; /* put2_cur(bun[tmp]); */
160 if (tmp == sho->i_jc)
161 break;
162 }
163 k_sum++; /* put2_cur(0); */
164 /* fuzoku */
165 for (tmp = sho->i_jc - 1;; tmp--)
166 {
167 if (tmp < sho->bun_m)
168 break;
169 k_sum++; /* put2_cur(bun[tmp]); */
170 }
171 k_sum++; /* put2_cur(0); */
172 return (k_sum);
173 }
174
175
176 static void
177 ret_sho_x (sho_list, cnt)
178 register struct DSD_SBN *sho_list;
179 register int cnt;
180 {
181 if (sho_list == NULL)
182 {
183 cnt = 0;
184 }
185 for (; cnt > 0; cnt--)
186 {
187 #ifdef DEBUG
188 out ("\tbun_jc: %d, i_jc: %d, bun_m: %d \n", sho_list->bun_jc, sho_list->i_jc, sho_list->bun_m);
189 out ("\tjdata:%x, kangovect:%d, t_jc:%d, hinsi: %d:%s, status:%d\n",
190 sho_list->jentptr, sho_list->kangovect, sho_list->t_jc, sho_list->hinsi, wnn_get_hinsi_name (sho_list->hinsi), sho_list->status);
191 #endif
192
193 #ifdef CONVERT_from_TOP
194 put4_cur (sho_list->bun_jc); /*end */
195 put4_cur (sho_list->bun_m); /*start */
196 put4_cur (sho_list->bun_jc); /*jiriend */
197 #else
198 put4_cur (maxchg - 1 - sho_list->bun_m); /*end */
199 put4_cur (maxchg - 1 - sho_list->bun_jc); /*start */
200 put4_cur (maxchg - 1 - sho_list->i_jc); /*jiriend */
201 #endif
202
203 if (sho_list->jentptr != NULL)
204 {
205 int hindo;
206 put4_cur (sho_list->jentptr->jishono); /*jisho No */
207 put4_cur (sho_list->jentptr->serial + sho_list->t_jc);
208 /* entry + t_jc */
209 /* Internally, we use "kasou-hindo"
210 * so return kasou-hindo as hindo-value"*/
211 hindo = *(sho_list->jentptr->hindo + sho_list->t_jc) & 0x7F;
212 if (sho_list->jentptr->hindo_in)
213 {
214 hindo += *(sho_list->jentptr->hindo_in + sho_list->t_jc) & 0x7F;
215 /* BUG */
216 if (hindo == 0x7f)
217 hindo--;
218 }
219 put4_cur (hindo);
220 /* hindo (u_char) */
221 put4_cur (*(sho_list->jentptr->hindo + sho_list->t_jc) >> 7);
222 /* ima */
223 }
224 else
225 {
226 put4_cur (-1);
227 put4_cur (sho_list->t_jc);
228 put4_cur (-1);
229 put4_cur (-1);
230 }
231 put4_cur (sho_list->hinsi); /* hinshi */
232 put4_cur (sho_list->status);
233 put4_cur (sho_list->status_bkwd);
234 put4_cur (sho_list->kangovect);
235 put4_cur (sho_list->v_jc);
236 sho_list++;
237 }
238 }
239
240 static void
241 ret_sho_kanji (sho_list, cnt)
242 register struct DSD_SBN *sho_list;
243 register int cnt;
244 {
245 if (sho_list == NULL)
246 {
247 cnt = 0;
248 }
249 for (; cnt > 0; sho_list++, cnt--)
250 {
251 ret_kanji (sho_list);
252 }
253 }
254
255 static void
256 ret_kanji (sho)
257 register struct DSD_SBN *sho;
258 {
259 register int tmp;
260 w_char kouho[1000];
261
262 if (sho->jentptr)
263 {
264 Get_knj (sho->jentptr, sho->t_jc, kouho, bun + sho->i_jc, sho->bun_jc - sho->i_jc + 1);
265 }
266 else
267 {
268 get_giji_knj (sho->bun_jc, sho->i_jc, sho->t_jc, kouho);
269 }
270 putws_cur (kouho); /* kanji */
271 /* yomi */
272 #ifdef CONVERT_from_TOP
273 for (tmp = sho->i_jc; tmp <= sho->bun_jc; tmp++)
274 {
275 #else
276 for (tmp = sho->bun_jc; tmp >= sho->i_jc; tmp--)
277 {
278 #endif
279 put2_cur (bun[tmp]);
280 }
281
282 put2_cur (0);
283 /* fuzoku */
284 for (tmp = sho->i_jc - 1;; tmp--)
285 {
286 if (tmp < sho->bun_m)
287 break;
288 put2_cur (bun[tmp]);
289 }
290 put2_cur (0);
291 }
292
293 /* SHO BUN */
294 void
295 ret_sho (sho_list, cnt)
296 register struct DSD_SBN *sho_list;
297 register int cnt;
298 {
299 if (sho_list == NULL)
300 {
301 cnt = 0;
302 put4_cur (cnt);
303 return;
304 }
305 put4_cur (cnt);
306 put4_cur (count_s_kanji (sho_list, cnt));
307
308 ret_sho_x (sho_list, cnt);
309 ret_sho_kanji (sho_list, cnt);
310 }
311
312 #ifdef CONVERT_by_STROKE
313 extern struct b_koho *p_kohos[]; /* BWNN koho buffer */
314
315 static int
316 count_s_kanji_B (cnt)
317 int cnt;
318 {
319 register int i, sho_sum;
320 sho_sum = 0;
321 for (i = 0; i < cnt; i++)
322 {
323 sho_sum += Strlen (p_kohos[i]->p_kanji);
324 sho_sum += Strlen (p_kohos[i]->p_yomi);
325 sho_sum += 3;
326 }
327 return sho_sum;
328 }
329
330 static void
331 ret_sho_x_B (end, start, cnt, zenp)
332 int end;
333 int start;
334 register int cnt;
335 int zenp;
336 {
337 int i;
338 int hindo = 0;
339 struct b_koho *b_pter;
340
341 for (i = 0; i < cnt; i++)
342 {
343 put4_cur (end); /*end */
344 put4_cur (start); /*start */
345 put4_cur (end); /*jiriend */
346 if ((b_pter = p_kohos[i]) != NULL)
347 {
348 put4_cur (b_pter->dic_no); /*jisho No */
349 put4_cur (b_pter->serial);
350 hindo = *(b_pter->p_hindo);
351 put4_cur (hindo & 0x7F); /* hindo (u_char) */
352 put4_cur (hindo >> 7); /* ima */
353 put4_cur (*(b_pter->p_hinsi)); /* hinshi */
354 }
355 else
356 {
357 put4_cur (-1);
358 put4_cur (0);
359 put4_cur (-1);
360 put4_cur (-1);
361 put4_cur (0);
362 }
363 put4_cur (3);
364 put4_cur (1);
365 put4_cur (0x7);
366 put4_cur (hindo * 5 - i);
367 }
368 }
369
370 static void
371 ret_sho_kanji_B (end, start, cnt, zenp)
372 int end;
373 int start;
374 register int cnt;
375 int zenp;
376 {
377 int i;
378 if (zenp == WNN_ZENKOUHO || (cnt != 1))
379 {
380 for (i = 0; i < cnt; i++)
381 {
382 putws_cur (p_kohos[i]->p_kanji); /* kanji */
383 putws_cur (p_kohos[i]->p_yomi); /* yomi */
384 /* fuzoku */
385 put2_cur (0);
386 }
387 }
388 else
389 {
390 putws_cur (p_kohos[0]->p_kanji);
391 for (i = end; i < start; i++)
392 put2_cur (bun[i]);
393 put2_cur (0);
394 /* fuzoku */
395 put2_cur (0);
396 }
397 }
398
399 /* BWNN SHO BUN */
400 void
401 ret_B (end, start, cnt, zenp)
402 int end;
403 int start;
404 register int cnt;
405 int zenp;
406 {
407 if (cnt == 0)
408 {
409 put4_cur (cnt);
410 return;
411 }
412 put4_cur (cnt);
413 put4_cur (count_s_kanji_B (cnt));
414
415 ret_sho_x_B (end, start, cnt, zenp);
416 ret_sho_kanji_B (end, start, cnt, zenp);
417 }
418
419 void
420 ret_daiB (end, start, cnt, zenp)
421 int end;
422 int start;
423 register int cnt;
424 int zenp;
425 {
426 register int i;
427 struct b_koho *b_pter;
428 int hindo = 0;
429
430 if (cnt == 0)
431 {
432 put4_cur (cnt);
433 return;
434 }
435 put4_cur (cnt);
436 put4_cur (cnt);
437 put4_cur (count_s_kanji_B (cnt));
438
439 for (i = 0; i < cnt; i++)
440 {
441 put4_cur (end);
442 put4_cur (start);
443 put4_cur (1);
444 b_pter = p_kohos[i];
445 hindo = *(b_pter->p_hindo);
446 put4_cur (hindo * 5 - i);
447 }
448 ret_sho_x_B (end, start, cnt, zenp);
449 ret_sho_kanji_B (end, start, cnt, zenp);
450
451 }
452 #endif /* CONVERT_by_STROKE */
453
454 #ifdef DEBUG
455
456 #ifdef putwchar
457 #undef putwchar
458 #endif
459
460 static void _print_dlist ();
461 static void _print_dlist1 ();
462
463 void
464 print_dlist (dlist, cnt)
465 struct DSD_DBN *dlist;
466 int cnt;
467 {
468
469 out ("大文節数:%d\n", cnt);
470 if (dlist == 0)
471 return;
472 for (; cnt > 0; dlist++, cnt--)
473 {
474 _print_dlist (dlist);
475 print_dlist1 (dlist->sbn, dlist->sbncnt);
476 }
477 fflush (stdout);
478 }
479
480 static void
481 _print_dlist (dlist)
482 struct DSD_DBN *dlist;
483 {
484 struct DSD_SBN *sbn;
485 int i;
486 int tmp;
487 w_char kouho[512];
488
489 out ("大文節:%x\t", dlist);
490 if (dlist == 0)
491 return;
492
493 sbn = dlist->sbn;
494 for (i = dlist->sbncnt; i > 0; i--)
495 {
496 if (sbn == 0)
497 break;
498
499 if (sbn->jentptr)
500 Get_knj (sbn->jentptr, sbn->t_jc, kouho, bun + sbn->i_jc, sbn->bun_jc - sbn->i_jc + 1);
501 else
502 get_giji_knj (sbn->bun_jc, sbn->i_jc, sbn->t_jc, kouho);
503 out (" ");
504 wsputs (kouho);
505 out (":");
506 for (tmp = sbn->i_jc - 1; tmp >= sbn->bun_m; tmp--)
507 putwchar (bun[tmp]);
508
509 sbn++;
510 }
511 out ("\t\thyouka:%d\n", dlist->v_jc);
512 fflush (stdout);
513 }
514
515 void
516 print_dlist1 (dlist1, cnt)
517 struct DSD_SBN *dlist1;
518 int cnt;
519 {
520 unsigned int hindo;
521
522 for (; cnt > 0; dlist1++, cnt--)
523 {
524 _print_dlist1 (dlist1);
525 if (dlist1 == 0)
526 return;
527 if (dlist1->jentptr == 0)
528 hindo = 0;
529 else
530 hindo = *(dlist1->jentptr->hindo + dlist1->t_jc);
531 out (" jdata:%x vect:%d t_jc:%d hinsi:%d:%s hindo:%x hyoka:%d status:%d status_bkwd:%d\n",
532 dlist1->jentptr, dlist1->kangovect, dlist1->t_jc, dlist1->hinsi, wnn_get_hinsi_name (dlist1->hinsi), hindo, dlist1->v_jc, dlist1->status, dlist1->status_bkwd);
533 }
534 fflush (stdout);
535 }
536
537 static void
538 _print_dlist1 (dlist1)
539 struct DSD_SBN *dlist1;
540 {
541 int tmp;
542 w_char kouho[512];
543
544 out ("小文節:%x\t", dlist1);
545 if (dlist1 == 0)
546 {
547 return;
548 }
549 for (tmp = dlist1->bun_jc; tmp >= dlist1->bun_m; tmp--)
550 {
551 putwchar (bun[tmp]);
552 if (tmp == dlist1->i_jc)
553 {
554 if (dlist1->jentptr)
555 Get_knj (dlist1->jentptr, dlist1->t_jc, kouho, bun + dlist1->i_jc, dlist1->bun_jc - dlist1->i_jc + 1);
556 else
557 get_giji_knj (dlist1->bun_jc, dlist1->i_jc, dlist1->t_jc, kouho);
558 out (" ");
559 wsputs (kouho);
560 out (":");
561 }
562 }
563 out ("\n");
564 fflush (stdout);
565 }
566
567 #endif /* DEBUG */