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: fuzoku.c,v $
32  * $SonyRevision: 1.1 $
33  * $SonyDate: 1994/06/03 08:01:47 $
34  */
35 
36 
37 
38 
39 
40 #include "sj_kcnv.h"
41 #include "sj_hinsi.h"
42 #include "sj_right.h"
43 #include "sj_yomi.h"
44 
45 #include "sj_kanakan.h"
46 
47 Static Int
fzkstrcmp(Uchar * yptr,Uchar TFar * fzkp,Int * saml)48 fzkstrcmp(Uchar *yptr, Uchar TFar *fzkp, Int *saml)
49 {
50 	Int	asklen, nkrlen;
51 
52 	asklen = FzkAskLen(fzkp);
53 
54 
55 	if (*saml < asklen) return CONT;
56 
57 
58 	if (*saml > asklen) return OVER;
59 
60 
61 	nkrlen = FzkNkrLen(fzkp);
62 
63 
64 	yptr += asklen;
65 	fzkp ++;
66 
67 
68 	while (nkrlen--) {
69 		if (*yptr > *fzkp)
70 			return CONT;
71 
72 		else if (*yptr < *fzkp) {
73 			if (!*yptr) return PARTLY;
74 			return OVER;
75 		}
76 
77 		else{
78 			yptr++;
79 			fzkp++;
80 			(*saml)++;
81 		}
82 	}
83 
84 	return MATCH;
85 }
86 
87 
88 
89 Void
setclrec(JREC * jrec,Uchar * yptr,TypeCnct right)90 setclrec(JREC *jrec, Uchar *yptr, TypeCnct right)
91 {
92 	CLREC		*new;
93 	TypeGram	hinsi;
94 	Int		len;
95 
96 
97 	if (!(len = yptr - cnvstart)) return;
98 
99 
100 	if (len > MaxClInputLen) return;
101 
102 
103 	if (!(new = argclrec(len))) return;
104 
105 
106 	new -> jnode    = jrec;
107 	new -> gobiln   = gobilen;
108 	new -> right    = right;
109 	new -> fzk_ka   = fzk_ka_flg;
110 	(jrec -> count)++;
111 
112 
113 	hinsi = jrec -> hinsi;
114 
115 	if (hinsi >= DO_SAHEN && hinsi <= SP_KA_ONB)
116 		new -> kubun = K_DOUSHI;
117 
118 	else if ((hinsi >= KEIYOUSI_1 && hinsi <= KE_DOUSI_9) ||
119 		 (hinsi == SP_KEIYOUSI)){
120 		if(right == R_FZKMEISI)
121 			new -> kubun = K_TAIGEN;
122 		else
123 			new -> kubun = K_YOUGEN;
124 	}
125 
126 	else if (hinsi == RENTAISI)
127 		new -> kubun = K_RENTAISI;
128 
129 	else if ((hinsi >= FUKUSI_1 && hinsi <= FUKUSI_9) ||
130 		 (hinsi == SP_FUKUSI))
131 		new -> kubun = K_FUKUSI;
132 
133 	else if (hinsi == SETUZOKU || hinsi==KANDOUSI ||
134 		hinsi == TANKANJI || hinsi==AISATU)
135 		new -> kubun = K_SONOTA;
136 
137 	else if (gobilen) {
138 		if (hinsi >= MEISI_5 && hinsi <= MEISI_7)
139 			new -> kubun = K_DOUSHI;
140 
141 		else if (hinsi == D_MEISI_4)
142 			new -> kubun = K_DOUSHI;
143 
144 		else if (hinsi == SETUBI_7 || hinsi == SETUBI_8)
145 			new -> kubun = K_DOUSHI;
146 
147 
148 		else if (hinsi == D_MEISI_5)
149 			new -> kubun = K_YOUGEN;
150 
151 		else if (hinsi == SETUBI_5 || hinsi == SETUBI_6)
152 			new -> kubun = K_YOUGEN;
153 		else
154 			new -> kubun = K_TAIGEN;
155 	}
156 	else if (hinsi >= MEISI_5 && hinsi <= MEISI_7) {
157 		if (right >= R_I && right <= R_ITADAKE)
158 			new -> kubun = K_DOUSHI;
159 
160 		else if (right >= R_DESHI && right <= R_TAI)
161 			new -> kubun = K_DOUSHI;
162 
163 		else if (right >= R_NAI && right <= R_MEIREI2)
164 			new -> kubun = K_DOUSHI;
165 
166 		else if (right == R_TE2 || right == R_TERU)
167 			new -> kubun = K_DOUSHI;
168 		else
169 			new -> kubun = K_TAIGEN;
170 	}
171 	else
172 		new -> kubun = K_TAIGEN;
173 }
174 
175 Static Int
fzkcnct(TypeCnct right,TypeCnct left)176 fzkcnct(TypeCnct right, TypeCnct left)
177 {
178 	Uchar	TFar	*cncttbl;
179 
180 	if (right && left) {
181 		cncttbl = Rigtadr(right);
182 		left--;
183 		if (cncttbl[left >> 3] << (left & 0x07) & 0x80)
184 			return TRUE;
185 	}
186 
187 	return FALSE;
188 }
189 
190 RECURS
191 Void
srchfzk(JREC * jrec,Uchar * yptr,TypeCnct right,Int level)192 srchfzk(JREC *jrec, Uchar *yptr, TypeCnct right, Int level)
193 {
194 	Uchar	TFar	*fzk;
195 	Int	len = 0;
196 	Int	cmp;
197 	Uchar	*next;
198 	FREC	*fzkrec;
199 	Int	i;
200 	Int	nlen;
201 	TypeCnct	rt;
202 
203 	if ((level >= MAXFLVL) && !(Chrtbl[*yptr] & FZK_KGU)) return;
204 
205 	if (terminate(right, yptr) && Chrtbl[*yptr] & FZK_KGU){
206 		if (!level) fzk_ka_flg = 0;
207 		yptr++;
208 		while (Chrtbl[*yptr] & FZK_KGU) yptr++;
209 		setclrec(jrec, yptr, (TypeCnct)R_FZKKGU);
210 		return;
211 	}
212 
213 	if (right == R_CUT) return;
214 
215 	if (!*yptr) return;
216 
217 	if (!(*yptr >= _XA && *yptr <= _NN)) return;
218 
219 	fzkrec = fzktbl;
220 
221 	for (i = fzkcount ; i ; i--, fzkrec++) {
222 
223 		if (yptr != fzkrec -> yomip) continue;
224 
225 		fzk = fzkrec -> fzkp;
226 
227 		len = FzkAskLen(fzk) + (nlen = FzkNkrLen(fzk)) + 1;
228 
229 		if (!fzkcnct(right, (TypeCnct)FzkLeft(fzk))) continue;
230 
231 		if (!level) fzk_ka_flg = FzkStrKa(fzk);
232 
233 		next = yptr + len;
234 
235 		if (terminate(rt = FzkRight(fzk), next)) {
236 			setclrec(jrec, next, rt);
237 		}
238 
239 		srchfzk(jrec, next, rt, level + 1);
240 	}
241 
242 	if (len) return;
243 
244 
245 	if (!(fzk = Fzkadr(*yptr - _XA))) return;
246 
247 	yptr++;
248 
249 	for ( ; *fzk != FZKEND ; fzk += nlen + (i ? 4 : 3)) {
250 
251 		nlen = FzkNkrLen(fzk);
252 		i    = FzkHasCode(fzk);
253 
254 		cmp = fzkstrcmp(yptr, fzk, &len);
255 
256 		if (cmp == OVER)
257 			break;
258 
259 		else if (cmp == PARTLY)
260 			break;
261 
262 		else if ((cmp != MATCH) || isdpnd(*(yptr + len)))
263 			continue;
264 
265 
266 		fzktbl[fzkcount].yomip   = yptr - 1;
267 		fzktbl[fzkcount].fzkp    = fzk;
268 		fzkcount++;
269 
270 		if (!fzkcnct(right, (TypeCnct)FzkLeft(fzk))) continue;
271 
272 		if (!level) fzk_ka_flg = FzkStrKa(fzk);
273 
274 		next = yptr + len;
275 
276 		if (terminate(rt = FzkRight(fzk), next)) {
277 			setclrec(jrec, next, rt);
278 		}
279 
280 		srchfzk(jrec, next, rt, level + 1);
281 	}
282 }
283