1 /*
2 * Copyright (c) 1991-1994 Sony Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Except as contained in this notice, the name of Sony Corporation
24 * shall not be used in advertising or otherwise to promote the sale, use
25 * or other dealings in this Software without prior written authorization
26 * from Sony Corporation.
27 *
28 */
29
30 /*
31 * $SonyRCSfile: setjrec.c,v $
32 * $SonyRevision: 1.1 $
33 * $SonyDate: 1994/06/03 08:02:17 $
34 */
35
36
37
38
39 #include "sj_euc.h"
40 #include "sj_kcnv.h"
41 #include "sj_hinsi.h"
42
43 #include "sj_kanakan.h"
44
45 Int
setj_atrb(Uchar * p)46 setj_atrb(Uchar *p)
47 {
48 return 2;
49 }
50
51
52
53 Int
setj_ofs(Uchar * p)54 setj_ofs(Uchar *p)
55 {
56 Int contf = TRUE;
57
58
59 p = dicbuf + ((*p & KanjiCodeMask) << 8) + *(p + 1);
60
61
62 do {
63 if (p[codesize(*p)] == KanjiStrEnd) contf = FALSE;
64 switch(*p & KanjiModeMask) {
65 case ZenHiraAssyuku:
66 p += setj_norm1(p); break;
67
68 case ZenKataAssyuku:
69 p += setj_norm1(p); break;
70
71 case OffsetAssyuku:
72 p += setj_ofs(p); break;
73
74 case AiAttribute:
75 p += setj_atrb(p); break;
76
77 case LeadingHankaku:
78 p += setj_norm2(p); break;
79
80 case KanjiAssyuku:
81 p += setj_knj(p); break;
82
83 case KanjiStrEnd:
84 contf = FALSE; break;
85
86 default:
87 p += setj_norm2(p);
88 }
89 } while (contf);
90
91 return 2;
92 }
93
94
95
96 Int
setj_knj(Uchar * p)97 setj_knj(Uchar *p)
98 {
99 Int contf = TRUE;
100
101
102 p = askknj[*p & KnjAssyukuMask];
103
104
105 do {
106 if (p[codesize(*p)]== KanjiStrEnd) contf = FALSE;
107 switch(*p & KanjiModeMask) {
108 case ZenHiraAssyuku:
109 p += setj_norm1(p); break;
110
111 case ZenKataAssyuku:
112 p += setj_norm1(p); break;
113
114 case OffsetAssyuku:
115 p += setj_ofs(p); break;
116
117 case AiAttribute:
118 p += setj_atrb(p); break;
119
120 case LeadingHankaku:
121 p += setj_norm2(p); break;
122
123 case KanjiAssyuku:
124 p += setj_knj(p); break;
125
126 case KanjiStrEnd:
127 contf = FALSE; break;
128
129 default:
130 p += setj_norm2(p);
131 }
132 } while (contf);
133
134 return 1;
135 }
136
137
138
139 Int
setj_norm1(Uchar * p)140 setj_norm1(Uchar *p)
141 {
142 return 1;
143 }
144
145
146
147 Int
setj_norm2(Uchar * p)148 setj_norm2(Uchar *p)
149 {
150 return 2;
151 }
152
153 Int
setj_norm3(Uchar * p)154 setj_norm3(Uchar *p)
155 {
156 return 3;
157 }
158
159
160
161 Static Uchar
chkhead(TypeGram gram)162 chkhead(TypeGram gram)
163 {
164
165 if (!headcode) return TRUE;
166
167
168 if (headcode == SETTOU_DAI) {
169
170 if (gram == SUUSI) return TRUE;
171 }
172
173
174 else {
175 gram--;
176 if ((Scncttbl(headcode-1, gram >> 3) << (gram & 0x07)) & 0x80) {
177 return TRUE;
178 }
179 }
180
181 return FALSE;
182 }
183
184
185
186 Void
setjrec(Uchar * tagp,Int mode)187 setjrec(Uchar *tagp, Int mode)
188 {
189 TypeGram gram;
190 Uchar *ptr;
191 Uchar *endp;
192 Uchar *tmp;
193 JREC *rec;
194 Int plen;
195 Int nlen;
196 Int len;
197
198
199 plen = getplen(tagp);
200 nlen = getnlen(tagp);
201
202
203 len = plen + nlen;
204
205
206 if (headcode) len += headlen;
207
208
209 ptr = tagp + DouonBlkSizeNumber + nlen;
210
211
212 endp = tagp + getsize(tagp);
213
214
215 for ( ; ptr < endp ; ptr = tmp + 1) {
216
217
218 for (tmp = ptr + 1; *tmp != HinsiBlkTerm ; ) {
219 switch(*tmp & KanjiModeMask) {
220 case ZenHiraAssyuku:
221 tmp += setj_norm1(tmp); break;
222
223 case ZenKataAssyuku:
224 tmp += setj_norm1(tmp); break;
225
226 case OffsetAssyuku:
227 tmp += setj_ofs(tmp); break;
228
229 case AiAttribute:
230 tmp += setj_atrb(tmp); break;
231
232 case LeadingHankaku:
233 tmp += setj_norm2(tmp); break;
234
235 case KanjiAssyuku:
236 tmp += setj_knj(tmp); break;
237
238 case KanjiStrEnd:
239 tmp++; break;
240
241 default:
242 tmp += setj_norm2(tmp);
243 }
244 }
245
246
247 if ((gram = *ptr) == IKKATU && !(mode & DO_IKKATU)) continue;
248
249
250 if (!chkhead(gram)) continue;
251
252
253 if (!(rec = argjrec(len, (JREC *)NULL))) continue;
254
255
256 rec -> jseg = prevseg;
257 rec -> jofsst = ptr - dicbuf;
258 rec -> jofsed = tmp - dicbuf;
259 rec -> class = C_DICT;
260 rec -> dicid = curdict->dicid;
261 rec -> hinsi = gram;
262 rec -> sttofs = headcode;
263 }
264 }
265
266
267
268 Void
setnumrec(Uchar * tagp,JREC * rec,TypeGram gram)269 setnumrec(Uchar *tagp, JREC *rec, TypeGram gram)
270 {
271 Uchar *ptr;
272 Uchar *endp;
273 Uchar *tmp;
274 Int plen, nlen, len;
275 JREC *jrec;
276
277
278 plen = getplen(tagp);
279 nlen = getnlen(tagp);
280
281
282 len = plen + nlen;
283
284
285 ptr = tagp + DouonBlkSizeNumber + nlen;
286
287
288 endp = tagp + getsize(tagp);
289
290
291 for ( ; ptr < endp ; ptr = tmp + 1) {
292
293
294 for (tmp = ptr + 1; *tmp != HinsiBlkTerm ; ) {
295 switch(*tmp & KanjiModeMask) {
296 case ZenHiraAssyuku:
297 tmp += setj_norm1(tmp); break;
298
299 case ZenKataAssyuku:
300 tmp += setj_norm1(tmp); break;
301
302 case OffsetAssyuku:
303 tmp += setj_ofs(tmp); break;
304
305 case AiAttribute:
306 tmp += setj_atrb(tmp); break;
307
308 case LeadingHankaku:
309 tmp += setj_norm2(tmp); break;
310
311 case KanjiAssyuku:
312 tmp += setj_knj(tmp); break;
313
314 case KanjiStrEnd:
315 tmp++; break;
316
317 default:
318 tmp += setj_norm2(tmp);
319 }
320 }
321
322
323 if (gram != *ptr) continue;
324
325
326 if (!(jrec = argjrec((Int)(rec -> jlen + len), rec))) continue;
327
328
329 jrec -> jseg = prevseg;
330 jrec -> jofsst = ptr - dicbuf;
331 jrec -> jofsed = tmp - dicbuf;
332 jrec -> dicid = curdict->dicid;
333 }
334 }
335
336
337
338 Void
setcrec(Uchar * tagp)339 setcrec(Uchar *tagp)
340 {
341 JREC *rec;
342
343
344 if (!(rec = argjrec((int)ClYomiLen(tagp), (JREC *)NULL))) return;
345
346
347 rec -> jofsst = tagp - ClStudyDict;
348 rec -> class = C_BUNSETU;
349 rec -> hinsi = ClGramCode(tagp);
350 }
351