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

initial import
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Thu, 13 Dec 2007 04:30:14 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bbc77ca4def5
1 /*
2 * $Id: dictoasc.c,v 1.3 2001/06/14 18:16:00 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 #include <stdio.h>
33 #include "commonhd.h"
34 #include "jslib.h"
35 #include "jh.h"
36 #include "jdata.h"
37 #include "de_header.h"
38
39 output_entry (jtl, hjtl, kanji1, kanji2, serial, yomi, ofpter)
40 struct JT *jtl;
41 struct HJT *hjtl;
42 int kanji1, kanji2;
43 int serial;
44 w_char *yomi;
45 FILE *ofpter;
46 {
47 w_char comm[LENGTHKANJI];
48 w_char kanji[LENGTHKANJI];
49 int ima, hindo;
50 UCHAR *kptr;
51
52 ima = (hjtl ? hjtl->hindo[serial] : jtl->hindo[serial]) & 0x80;
53 hindo = motoni2 ((hjtl ? hjtl->hindo[serial] : jtl->hindo[serial]) & 0x7f);
54
55 kptr = jtl->kanji + kanji1;
56 get_kanji_str (kptr, kanji, NULL, comm);
57
58 Print_entry (yomi, kanji, comm, hindo, ima, jtl->hinsi[serial], serial, ofpter);
59 }
60
61 dictoasc (dic_no, ofpter)
62 int dic_no;
63 FILE *ofpter;
64 {
65 if (((struct JT *) (files[dic_table[dic_no].body].area))->syurui == WNN_UD_DICT)
66 {
67 return (udtoasc ((struct JT *) (files[dic_table[dic_no].body].area), (dic_table[dic_no].hindo == -1) ? NULL : (struct HJT *) (files[dic_table[dic_no].hindo].area), ofpter));
68 }
69 else
70 {
71 return (sdtoasc ((struct JT *) (files[dic_table[dic_no].body].area), (dic_table[dic_no].hindo == -1) ? NULL : (struct HJT *) (files[dic_table[dic_no].hindo].area), ofpter));
72 }
73 }
74
75
76 udtoasc (jtl, hjtl, ofpter)
77 struct JT *jtl;
78 struct HJT *hjtl;
79 FILE *ofpter;
80 {
81 struct uind2 *hop;
82 int i, k;
83 int len;
84 int serial;
85 UCHAR *hostart = jtl->hontai;
86 struct uind1 *tary = jtl->table;
87 static w_char yomi[LENGTHYOMI]; /* 2 byte yomi */
88
89 for (i = 0; i < jtl->maxtable; i++)
90 {
91 for (hop = (struct uind2 *) (tary[i].pter + (char *) hostart); hop != (struct uind2 *) hostart; hop = (struct uind2 *) (hop->next + (char *) hostart))
92 {
93 /* Though each hop has the same yomi, but calculate yomi each time. */
94 yomi[0] = tary[i].yomi1 >> 16;
95 yomi[1] = tary[i].yomi1 & 0xffff;
96 if (yomi[1])
97 {
98 yomi[2] = tary[i].yomi2 >> 16;
99 if (yomi[2])
100 {
101 yomi[3] = tary[i].yomi2 & 0xffff;
102 }
103 }
104 len = hop->yomi[0];
105 Strncpy (yomi + 4, (hop->yomi) + 1, len - 4);
106 yomi[len] = 0;
107 serial = hop->serial;
108 for (k = 0; k < hop->kosuu; k++, serial++)
109 {
110 output_entry (jtl, hjtl, hop->kanjipter, k, serial, yomi, ofpter);
111 }
112 }
113 }
114 return (0);
115 }
116
117 sdtoasc (jtl, hjtl, ofpter)
118 struct JT *jtl;
119 struct HJT *hjtl;
120 FILE *ofpter;
121 {
122 return (sdtoasc1 (jtl, hjtl, ofpter, jtl->hontai, 0));
123 }
124
125 sdtoasc1 (jtl, hjtl, ofpter, hopter, level)
126 UCHAR *hopter;
127 struct JT *jtl;
128 struct HJT *hjtl;
129 FILE *ofpter;
130 int level;
131 {
132 int tsize;
133 w_char *charst;
134 w_char *sumst;
135 int *ptrst;
136 int j, k;
137 int serial;
138 int kanji1;
139 static w_char yomi[LENGTHYOMI]; /* 2 byte yomi */
140
141 yomi[level + 1] = 0;
142 switch (*(w_char *) hopter)
143 {
144 case ST_NORMAL:
145 tsize = *(w_char *) (hopter + 2);
146 serial = *(int *) (hopter + 4);
147 kanji1 = *(int *) (hopter + 8);
148 charst = (w_char *) (hopter + 12);
149 sumst = ((w_char *) charst + tsize + 2); /* + 2 keeps two zero words */
150 ptrst = (int *) ((w_char *) sumst + tsize);
151 for (k = 0; k < tsize; k++)
152 {
153 if (sumst[k] == sumst[k - 1])
154 {
155 yomi[level] = charst[k];
156 for (j = sumst[k - 1] + 1; j <= sumst[k]; j++)
157 {
158 output_entry (jtl, hjtl, kanji1, j, serial, yomi, ofpter);
159 }
160 }
161 }
162 for (k = 0; k < tsize; k++)
163 {
164 if (ptrst[k] != ENDPTR)
165 {
166 yomi[level] = charst[k];
167 sdtoasc1 (jtl, hjtl, ofpter, jtl->hontai + ptrst[k], level + 1);
168 }
169 }
170 break;
171 case ST_NOENT:
172 tsize = *(w_char *) (hopter + 2);
173 charst = (w_char *) (hopter + 4);
174 ptrst = (int *) AL_INT ((w_char *) charst + tsize);
175 for (k = 0; k < tsize; k++)
176 {
177 if (ptrst[k] != ENDPTR)
178 {
179 yomi[level] = charst[k];
180 sdtoasc1 (jtl, hjtl, ofpter, jtl->hontai + ptrst[k], level + 1);
181 }
182 }
183 break;
184 case ST_NOPTER:
185 tsize = *(w_char *) (hopter + 2);
186 serial = *(int *) (hopter + 4);
187 kanji1 = *(int *) (hopter + 8);
188 charst = (w_char *) (hopter + 12);
189 sumst = ((w_char *) charst + tsize + 2); /* + 2 keeps two zero words */
190 for (k = 0; k < tsize; k++)
191 {
192 if (sumst[k] == sumst[k - 1])
193 {
194 yomi[level] = charst[k];
195 for (j = sumst[k - 1] + 1; j <= sumst[k]; j++)
196 {
197 output_entry (jtl, hjtl, kanji1, j, serial, yomi, ofpter);
198 }
199 }
200 }
201 break;
202 case ST_SMALL:
203 yomi[level] = *(w_char *) (hopter + 2);
204 sdtoasc1 (jtl, hjtl, ofpter, hopter + 4, level + 1);
205 break;
206 }
207 return (0);
208 }