1 #ifndef lint
2 static char *rcsid = "$Id: dict.c,v 2.0 1992/02/13 18:33:19 nao Exp $";
3 #endif
4 /*
5  * Copyright 1991 Sony Corporation
6  *
7  * Permission to use, copy, modify, distribute, and sell this software and its
8  * documentation for any purpose is hereby granted without fee, provided that
9  * the above copyright notice appear in all copies and that both that
10  * copyright notice and this permission notice appear in supporting
11  * documentation, and that the name of Sony not be used in advertising or
12  * publicity pertaining to distribution of the software without specific,
13  * written prior permission.  Sony makes no representations about the
14  * suitability of this software for any purpose.  It is provided "as is"
15  * without express or implied warranty.
16  *
17  * SONY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SONY
19  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23  */
24 /*
25  * Author: Naoshi Suzuki, SONY Corporation.  (nao@sm.sony.co.jp)
26  */
27 
28 #include "common.h"
29 #include "util.h"
30 #include "segment.h"
31 
32 extern Xsj3cCVServerIF      serverIF[SERVER_NUM];
33 extern wchar               *_Xsj3cStoreWchar();
34 
35 void                        _Xsj3cFlushDictMsg();
36 Xsj3cDictData               _Xsj3cCreateDictData();
37 void                        _Xsj3cFreeDictData();
38 
39 int                         Xsj3cGetDictMsgNum();
40 Xsj3cDictMsg                Xsj3cGetDictMsgs();
41 wchar                      *Xsj3cGetDictMsg();
42 void                        Xsj3cDictRegister();
43 void                        Xsj3cDictClear();
44 void                        Xsj3cEndDict();
45 
46 Xsj3cHinsi                  _Xsj3cHinsiInit();
47 int                         Xsj3cGetHinsiNum();
48 Xsj3cHinsi                  Xsj3cGetHinsis();
49 wchar                      *Xsj3cGetHinsi();
50 int                         Xsj3cSetHinsi();
51 void                        Xsj3cEndHinsi();
52 
53 static Xsj3cDictMsg         _Xsj3cDictMsgInit();
54 static void                 _Xsj3cSetDictMsg();
55 
56 static Xsj3cDictMsg         dictmsglist[SERVER_NUM] = {NULL};
57 static int                  dictmsgnum[SERVER_NUM] = {0};
58 
59 static Xsj3cHinsi           hinsilist[SERVER_NUM] = {NULL};
60 static int                  hinsinum[SERVER_NUM] = {0};
61 
62 typedef struct _dict_hinsi {
63     int             code;
64     char           *string;
65 } Sj3HinsiRec, *Sj3HinsiPtr;
66 
67 static Sj3HinsiRec sj3_hinsi_list[] = {
68     SJ3_H_NRMNOUN,      "\225\201\222\312\226\274\216\214",
69     SJ3_H_PRONOUN,      "\221\343\226\274\216\214",
70     SJ3_H_LNAME,        "\225\143\216\232",
71     SJ3_H_FNAME,        "\226\274\221\117",
72     SJ3_H_LOCNAME,      "\222\156\226\274",
73     SJ3_H_PREFIC,       "\214\247\201\136\213\346\226\274",
74     SJ3_H_RENTAI,       "\230\101\221\314\216\214",
75     SJ3_H_CONJUNC,      "\220\332\221\261\216\214",
76     SJ3_H_SUBNUM,       "\217\225\220\224\216\214",
77     SJ3_H_NUMERAL,      "\220\224\216\214",
78     SJ3_H_PREFIX,       "\220\332\223\252\214\352",
79     SJ3_H_POSTFIX,      "\220\332\224\366\214\352",
80     SJ3_H_ADVERB,       "\225\233\216\214",
81     SJ3_H_ADJECT,       "\214\140\227\145\216\214",
82     SJ3_H_ADJVERB,      "\214\140\227\145\223\256\216\214",
83     SJ3_H_SILVERB,      "\203\124\225\317\223\256\216\214",
84     SJ3_H_ZILVERB,      "\203\125\225\317\223\256\216\214",
85     SJ3_H_ONEVERB,      "\210\352\222\151\223\256\216\214",
86     SJ3_H_KAVERB,       "\203\112\215\163\214\334\222\151\223\256\216\214",
87     SJ3_H_GAVERB,       "\203\113\215\163\214\334\222\151\223\256\216\214",
88     SJ3_H_SAVERB,       "\203\124\215\163\214\334\222\151\223\256\216\214",
89     SJ3_H_TAVERB,       "\203\136\215\163\214\334\222\151\223\256\216\214",
90     SJ3_H_NAVERB,       "\203\151\215\163\214\334\222\151\223\256\216\214",
91     SJ3_H_BAVERB,       "\203\157\215\163\214\334\222\151\223\256\216\214",
92     SJ3_H_MAVERB,       "\203\175\215\163\214\334\222\151\223\256\216\214",
93     SJ3_H_RAVERB,       "\203\211\215\163\214\334\222\151\223\256\216\214",
94     SJ3_H_WAVERB,       "\203\217\215\163\214\334\222\151\223\256\216\214",
95     SJ3_H_SINGLE,       "\222\120\212\277\216\232",
96 };
97 
98 typedef struct _dict_status {
99     Xsj3cdMode      state;
100     Xsj3cdMode      value;
101     char            *string;
102 } Sj3DictStatusRec, *Sj3DictStatusPtr;
103 
104 static Sj3DictStatusRec sj3_dict_status[] = {
105     REG_STATE|CLR_STATE,    SJ3_DICT_INPUT,
106     " \224\315\210\315\216\167\222\350/\223\307\202\335\223\374\227\
107 \315:[\223\307\202\335]",
108     /* $BHO0O;XDj(B/$BFI$_F~NO(B:[$BFI$_(B] */
109     REG_STATE|CLR_STATE,    SJ3_DICT_YOMI,
110     " [\223\307\202\335]",
111     /* [$BFI$_(B] */
112     REG_STATE|CLR_STATE,    SJ3_DICT_HINSI,
113     " [\225\151\216\214]",
114     /* [$BIJ;l(B] */
115     REG_STATE|CLR_STATE,    SJ3_DICT_CONFIRM,
116     " [ok ?]",
117     /* [ok ?] */
118     REG_STATE,              SJ3_TOUROKU_SUCCESSED,
119     ":\223\157\230\136\202\265\202\334\202\265\202\275",
120     /* $BEPO?$7$^$7$?(B */
121     CLR_STATE,              SJ3_SYOUKYO_SUCCESSED,
122     ":\217\301\213\216\202\265\202\334\202\265\202\275",
123     /* $B>C5n$7$^$7$?(B */
124     REG_STATE|CLR_STATE,    SJ3_NO_YOMI_STR,
125     ":\223\307\202\335\225\266\216\232\227\361\202\252\202\240\202\350\
126 \202\334\202\271\202\361",
127     /* $BFI$_J8;zNs$,$"$j$^$;$s(B */
128     REG_STATE|CLR_STATE,    SJ3_LONG_YOMI_STR,
129     ":\223\307\202\335\225\266\216\232\227\361\202\252\222\267\202\267\
130 \202\254\202\334\202\267",
131     /* $BFI$_J8;zNs$,D9$9$.$^$9(B */
132     REG_STATE|CLR_STATE,    SJ3_DICT_ERROR,
133     ":\216\253\217\221\202\326\202\314\217\221\202\253\215\236\202\335\
134 \202\252\217\157\227\210\202\334\202\271\202\361",
135     /* $B<-=q$X$N=q$-9~$_$,=PMh$^$;$s(B */
136     REG_STATE|CLR_STATE,    SJ3_DICT_LOCKED,
137     ":\216\253\217\221\202\252\203\215\203\142\203\116\202\263\202\352\
138 \202\304\202\242\202\334\202\267",
139     /* $B<-=q$,%m%C%/$5$l$F$$$^$9(B */
140     REG_STATE|CLR_STATE,    SJ3_BAD_YOMI_STR,
141     ":\223\307\202\335\225\266\216\232\227\361\202\311\225\163\220\263\
142 \202\310\225\266\216\232\202\252\212\334\202\334\202\352\202\304\202\242\
143 \202\334\202\267",
144     /* $BFI$_J8;zNs$KIT@5$JJ8;z$,4^$^$l$F$$$^$9(B */
145     REG_STATE|CLR_STATE,    SJ3_BAD_KANJI_STR,
146     ":\212\277\216\232\225\266\216\232\227\361\202\311\225\163\220\263\
147 \202\310\225\266\216\232\202\252\212\334\202\334\202\352\202\304\202\242\
148 \202\351\202\251\222\267\202\267\202\254\202\334\202\267",
149     /* $B4A;zJ8;zNs$KIT@5$JJ8;z$,4^$^$l$F$$$k$+D9$9$.$^$9(B */
150     REG_STATE|CLR_STATE,    SJ3_BAD_HINSI_CODE,
151     ":\225\151\216\214\203\122\201\133\203\150\202\252\225\163\220\263\
152 \202\305\202\267",
153     /* $BIJ;l%3!<%I$,IT@5$G$9(B */
154     REG_STATE,              SJ3_WORD_EXIST,
155     ":\223\157\230\136\215\317\202\314\217\156\214\352\202\305\202\267",
156     /* $BEPO?:Q$N=O8l$G$9(B */
157     CLR_STATE,              SJ3_WORD_NOT_EXIST,
158     ":\217\156\214\352\202\252\223\157\230\136\202\263\202\352\202\304\
159 \202\242\202\334\202\271\202\361",
160     /* $B=O8l$,EPO?$5$l$F$$$^$;$s(B */
161     REG_STATE,              SJ3_DOUON_FULL,
162     ":\202\261\202\352\210\310\217\343\223\257\211\271\214\352\202\360\
163 \223\157\230\136\202\305\202\253\202\334\202\271\202\361",
164     /* $B$3$l0J>eF12;8l$rEPO?$G$-$^$;$s(B */
165     REG_STATE,              SJ3_DICT_FULL,
166     ":\202\261\202\352\210\310\217\343\216\253\217\221\202\311\223\157\
167 \230\136\202\305\202\253\202\334\202\271\202\361",
168     /* $B$3$l0J>e<-=q$KEPO?$G$-$^$;$s(B */
169     REG_STATE,              SJ3_INDEX_FULL,
170     ":\202\261\202\352\210\310\217\343 INDEX \202\311\223\157\230\136\202\
171 \305\202\253\202\334\202\271\202\361",
172     /* $B$3$l0J>e(B INDEX $B$KEPO?$G$-$^$;$s(B */
173     REG_STATE,              SJ3_TOUROKU_FAILED,
174     ":\216\253\217\221\202\326\202\314\223\157\230\136\202\311\216\270\
175 \224\163\202\265\202\334\202\265\202\275",
176     /* $B<-=q$X$NEPO?$K<:GT$7$^$7$?(B */
177     CLR_STATE,              SJ3_SYOUKYO_FAILED,
178     ":\216\253\217\221\202\251\202\347\202\314\217\301\213\216\202\311\
179 \216\270\224\163\202\265\202\334\202\265\202\275",
180     /* $B<-=q$+$i$N>C5n$K<:GT$7$^$7$?(B */
181 };
182 
183 /*
184  * _Xsj3cCreateDictData()
185  */
186 Xsj3cDictData
_Xsj3cCreateDictData(buf,mode)187 _Xsj3cCreateDictData(buf, mode)
188     Xsj3cBuf            buf;
189     Xsj3cdMode          mode;
190 {
191     register Xsj3cDictData  dict;
192 
193     if (buf->dict)
194         return buf->dict;
195     if ((dict = (Xsj3cDictData)malloc(sizeof(Xsj3cDictDataRec))) == NULL)
196         Xsj3cError("Failed to allocate data for DictMode.");
197     if ((dict->seg = (Xsj3cSeg)Xsj3cCreateSegment(buf)) == NULL)
198         Xsj3cError("Failed to allocate segment for dictionary.");
199     if ((dict->msg = (Xsj3cDictMsg)
200             calloc(DICT_STR_NUM, sizeof(Xsj3cDictMsgRec))) == NULL)
201         Xsj3cError("Failed to allocate message buffer for dictionary.");
202     dict->mode = mode;
203     dict->status = DICT_INPUT;
204     dict->value = SJ3_DICT_INPUT;
205     dict->n_dict = 0;
206     return (dict);
207 }
208 
209 /*
210  * _Xsj3cFreeDictData()
211  */
212 void
_Xsj3cFreeDictData(buf)213 _Xsj3cFreeDictData(buf)
214     Xsj3cBuf            buf;
215 {
216     if (!buf->dict)
217         return ;
218     Xsj3cFreeSegment(buf->dict->seg);
219     buf->dict->seg = NULL;
220     free (buf->dict->msg);
221     free (buf->dict);
222     buf->dict = NULL;
223 }
224 
225 /*
226  * _Xsj3cDictMsgInit()
227  */
228 static Xsj3cDictMsg
_Xsj3cDictMsgInit(buf)229 _Xsj3cDictMsgInit(buf)
230     Xsj3cBuf            buf;
231 {
232     wchar               data[KANABUFSIZ];
233     register int        i;
234 
235     if (dictmsglist[buf->server]) {
236         return (dictmsglist[buf->server]);
237     }
238     switch(buf->server) {
239     case SERVER_SJ3:
240     default:
241         dictmsgnum[SERVER_SJ3]
242                 = sizeof(sj3_dict_status)/sizeof(Sj3DictStatusRec);
243         break;
244     }
245     if ((dictmsglist[buf->server] =
246             (Xsj3cDictMsg)calloc(dictmsgnum[buf->server],
247             sizeof(Sj3DictStatusRec))) == NULL) {
248         Xsj3cError("Failed to allocate hinsi data");
249     }
250     switch(buf->server) {
251     case SERVER_SJ3:
252     default:
253         for (i = 0; i < dictmsgnum[SERVER_SJ3]; i++) {
254             dictmsglist[buf->server][i].len = _Xsj3cmPStowOUT(buf, data,
255                     (unsigned char *)sj3_dict_status[i].string);
256             dictmsglist[buf->server][i].data
257                 = _Xsj3cStoreWchar(data, dictmsglist[buf->server][i].len + 1);
258             dictmsglist[buf->server][i].attr = SEG_NORMAL;
259             if (!dictmsglist[buf->server][i].data)
260                 Xsj3cError("Failed to allocate hinsi data");
261         }
262         break;
263     }
264     return (dictmsglist[buf->server]);
265 }
266 
267 /*
268  * Xsj3cGetDictMsgNum()
269  */
270 int
Xsj3cGetDictMsgNum(buf)271 Xsj3cGetDictMsgNum(buf)
272     Xsj3cBuf      buf;
273 {
274     switch (buf->dict->status) {
275     case DICT_INPUT:
276     case DICT_HINSI:
277         if (buf->dict->seg->num > 0)
278             return (DICT_STR_YOMI + 1);
279         else
280             return (DICT_STR_MSG1 + 1);
281     case DICT_CONFIRM:
282         if (buf->dict->mode == REG_STATE)
283             return (DICT_STR_NUM);
284         else
285             return (DICT_STR_MSG2 + 1);
286     case DICT_END:
287         if (buf->dict->seg->num > 0) {
288             if (buf->curhinsi < 0)
289                 return (DICT_STR_MSG2 + 1);
290             else
291                 return (DICT_STR_NUM);
292         } else {
293             return (DICT_STR_MSG1 + 1);
294         }
295     default:
296         return (NULL);
297     }
298 }
299 
300 /*
301  * _Xsj3cFlushDictMsg()
302  */
303 void
_Xsj3cFlushDictMsg(buf)304 _Xsj3cFlushDictMsg(buf)
305     Xsj3cBuf      buf;
306 {
307     if (!dictmsglist[buf->server]) {
308         dictmsglist[buf->server] = _Xsj3cDictMsgInit(buf);
309     }
310 
311     switch (buf->dict->status) {
312     case DICT_INPUT:
313     case DICT_HINSI:
314         if (buf->dict->seg->num > 0) {
315             _Xsj3cSetDictMsg(buf, DICT_STR_YOMI);
316         } else {
317             _Xsj3cSetDictMsg(buf, DICT_STR_MODE);
318             _Xsj3cSetDictMsg(buf, DICT_STR_MSG1);
319         }
320         break;
321     case DICT_CONFIRM:
322         if (buf->dict->mode == REG_STATE) {
323             _Xsj3cSetDictMsg(buf, DICT_STR_MSG1);
324             _Xsj3cSetDictMsg(buf, DICT_STR_MSG2);
325             _Xsj3cSetDictMsg(buf, DICT_STR_HINSI);
326             _Xsj3cSetDictMsg(buf, DICT_STR_MSG3);
327         } else {
328             _Xsj3cSetDictMsg(buf, DICT_STR_MSG1);
329             _Xsj3cSetDictMsg(buf, DICT_STR_MSG2);
330         }
331         break;
332     case DICT_END:
333         if (buf->dict->seg->num > 0) {
334             if (buf->dict->seg->num > DICT_YOMI_MAX) {
335                 _Xsj3cSetDictMsg(buf, DICT_STR_MSG2);
336             } else {
337                 if (buf->dict->mode == REG_STATE) {
338                     _Xsj3cSetDictMsg(buf, DICT_STR_MSG1);
339                     _Xsj3cSetDictMsg(buf, DICT_STR_MSG3);
340                 } else {
341                     if (buf->curhinsi < 0) {
342                         _Xsj3cSetDictMsg(buf, DICT_STR_MSG2);
343                     } else {
344                         _Xsj3cSetDictMsg(buf, DICT_STR_MSG1);
345                         _Xsj3cSetDictMsg(buf, DICT_STR_MSG2);
346                         _Xsj3cSetDictMsg(buf, DICT_STR_HINSI);
347                         _Xsj3cSetDictMsg(buf, DICT_STR_MSG3);
348                     }
349                 }
350             }
351         } else {
352             _Xsj3cSetDictMsg(buf, DICT_STR_MSG1);
353         }
354         break;
355     default:
356         break;
357     }
358 }
359 
360 /*
361  * Xsj3cGetDictMsgs()
362  */
363 Xsj3cDictMsg
Xsj3cGetDictMsgs(buf)364 Xsj3cGetDictMsgs(buf)
365     Xsj3cBuf    buf;
366 {
367     return (buf->dict->msg);
368 }
369 
370 /*
371  * Xsj3cGetDictMsg()
372  */
373 wchar *
Xsj3cGetDictMsg(buf,n,len,attr)374 Xsj3cGetDictMsg(buf, n, len, attr)
375     Xsj3cBuf    buf;
376     int         n;
377     int         *len;
378     int         *attr;
379 {
380     *attr = buf->dict->msg[n].attr;
381     *len = buf->dict->msg[n].len;
382     return (buf->dict->msg[n].data);
383 }
384 
385 static void
_Xsj3cSetDictMsg(buf,n)386 _Xsj3cSetDictMsg(buf, n)
387     Xsj3cBuf    buf;
388     Xsj3cdMode  n;
389 {
390     Xsj3csMode      mode;
391     register int    i;
392     int             value;
393 
394     switch (n) {
395     case DICT_STR_MODE:
396         mode = (buf->dict->mode == REG_STATE ? MODE_TOROKU : MODE_SYOUKYO);
397         buf->dict->msg[DICT_STR_MODE].data = buf->modestr[mode];
398         buf->dict->msg[DICT_STR_MODE].len = buf->modelen[mode];
399         buf->dict->msg[DICT_STR_MODE].attr = SEG_REVERSED;
400         return;
401     case DICT_STR_MSG1:
402         if (buf->dict->status == DICT_INPUT) {
403             value = SJ3_DICT_INPUT;
404         } else {
405             if (buf->dict->seg->num > 0)
406                 value = SJ3_DICT_YOMI;
407             else
408                 value = buf->dict->value;
409         }
410         break;
411     case DICT_STR_YOMI:
412         buf->dict->msg[DICT_STR_YOMI].data = buf->dict->seg->disp;
413         buf->dict->msg[DICT_STR_YOMI].len = buf->dict->seg->dnum;
414         buf->dict->msg[DICT_STR_YOMI].attr = SEG_UNDER_LINE;
415         return;
416     case DICT_STR_MSG2:
417         if (buf->dict->mode == CLR_STATE && buf->dict->status == DICT_CONFIRM) {
418             value = SJ3_DICT_CONFIRM;
419         } else {
420             if (buf->curhinsi < 0)
421                 value = buf->dict->value;
422             else
423                 value = SJ3_DICT_HINSI;
424         }
425         break;
426     case DICT_STR_HINSI:
427         buf->dict->msg[DICT_STR_HINSI].data = buf->hinsi[buf->curhinsi].data;
428         buf->dict->msg[DICT_STR_HINSI].len = buf->hinsi[buf->curhinsi].len;
429         buf->dict->msg[DICT_STR_HINSI].attr = SEG_NORMAL;
430         return;
431     case DICT_STR_MSG3:
432         if (buf->dict->mode == REG_STATE && buf->dict->status == DICT_CONFIRM) {
433             value = SJ3_DICT_CONFIRM;
434         } else {
435             value = buf->dict->value;
436         }
437         break;
438     default:
439         value = buf->dict->value;
440         break;
441     }
442 
443     switch(buf->server) {
444     case SERVER_SJ3:
445     default:
446         for (i = 0; i < dictmsgnum[SERVER_SJ3]; i++) {
447             if ((buf->dict->mode & sj3_dict_status[i].state) &&
448                     value == sj3_dict_status[i].value)
449                 break;
450         }
451         break;
452     }
453     if (i >= dictmsgnum[buf->server])
454         Xsj3cError("Cannot find message for now status %s.",_Xsj3cItoa(value));
455     else
456         buf->dict->msg[n] = dictmsglist[buf->server][i];
457 }
458 
459 void
Xsj3cDictRegister(buf)460 Xsj3cDictRegister(buf)
461     Xsj3cBuf        buf;
462 {
463     wchar           disp[KANABUFSIZ];
464     unsigned char   kana[KANJIBUFSIZ],  kanji[KANJIBUFSIZ];
465     register int    i;
466 
467     disp[0] = '\0';
468     for (i = buf->curseg; i <= buf->curseg + buf->dict->n_dict; i++) {
469         _Xsj3cWcat(disp, buf->input[i]->disp);
470     }
471     buf->dict->n_dict = 0;
472     _Xsj3cwOUTtomPS(buf, kanji, disp);
473     if (buf->gakusyuu)
474         _Xsj3cClearDcid(buf);
475     _Xsj3cwPStomPS(buf, kana, buf->dict->seg->yomi);
476 
477     switch (buf->server) {
478     case SERVER_SJ3:
479     default:
480         if ((buf->dict->value
481                 = serverIF[buf->server].func[FUNC_REGISTER](kana, kanji,
482                 sj3_hinsi_list[buf->curhinsi].code)) == 0) {
483             buf->dict->value = SJ3_TOUROKU_SUCCESSED;
484         } else if (buf->dict->value  < 0) {
485             Xsj3cWarning("sj3serv is down. reconnect please");
486             buf->dict->value = SJ3_TOUROKU_FAILED;
487         }
488         break;
489     }
490     _Xsj3cFlushDictMsg(buf);
491 }
492 
493 void
Xsj3cDictClear(buf)494 Xsj3cDictClear(buf)
495     Xsj3cBuf        buf;
496 {
497     wchar           disp[KANABUFSIZ];
498     unsigned char   kana[KANJIBUFSIZ],  kanji[KANJIBUFSIZ];
499     register int    i;
500     Sj3HinsiPtr     hp;
501 
502     disp[0] = '\0';
503     for (i = buf->curseg; i <= buf->curseg + buf->dict->n_dict; i++) {
504         _Xsj3cWcat(disp, buf->input[i]->disp);
505     }
506     buf->dict->n_dict = 0;
507     _Xsj3cwOUTtomPS(buf, kanji, disp);
508     if (buf->gakusyuu)
509         _Xsj3cClearDcid(buf);
510     _Xsj3cwPStomPS(buf, kana, buf->dict->seg->yomi);
511 
512     switch (buf->server) {
513     case SERVER_SJ3:
514     default:
515         for (hp = sj3_hinsi_list, i = 0; hp->code > 0; hp++, i++) {
516             if ((buf->dict->value
517                     = serverIF[buf->server].func[FUNC_CLEAR](kana, kanji,
518                     hp->code)) == 0) {
519                 buf->dict->value = SJ3_SYOUKYO_SUCCESSED;
520                 buf->curhinsi = i;
521                 _Xsj3cFlushDictMsg(buf);
522                 return;
523             } else if (buf->dict->value < 0) {
524                 Xsj3cWarning("sj3serv is down. reconnect please");
525                 buf->dict->value = SJ3_SYOUKYO_FAILED;
526                 buf->curhinsi = -1;
527                 _Xsj3cFlushDictMsg(buf);
528                 return;
529             } else if (buf->dict->value != SJ3_WORD_NOT_EXIST) {
530                 buf->curhinsi = -1;
531                 _Xsj3cFlushDictMsg(buf);
532                 return;
533             }
534         }
535         break;
536     }
537 
538     buf->curhinsi = -1;
539     _Xsj3cFlushDictMsg(buf);
540     return;
541 }
542 
543 /*
544  * Xsj3cEndDict()
545  *  End dictionary mode(DictMode) and back to ConvedMode.
546  */
547 void
Xsj3cEndDict(buf)548 Xsj3cEndDict(buf)
549     Xsj3cBuf      buf;
550 {
551     _Xsj3cFreeDictData(buf);
552     buf->convmode = ConvedModeMask;
553 }
554 
555 /*
556  * _Xsj3cHinsiInit()
557  *  Initialize hinsi data.
558  */
559 Xsj3cHinsi
_Xsj3cHinsiInit(buf)560 _Xsj3cHinsiInit(buf)
561     Xsj3cBuf      buf;
562 {
563     wchar               data[KANABUFSIZ];
564     register int        i;
565 
566     if (hinsilist[buf->server]) {
567         return(hinsilist[buf->server]);
568     }
569 
570     switch (buf->server) {
571     case SERVER_SJ3:
572     default:
573         hinsinum[SERVER_SJ3]= sizeof(sj3_hinsi_list)/sizeof(Sj3HinsiRec);
574         break;
575     }
576 
577     if ((hinsilist[buf->server]
578             = (Xsj3cHinsi)calloc(hinsinum[buf->server], sizeof(Xsj3cHinsiRec)))
579             == NULL) {
580         Xsj3cError("Failed to allocate hinsi data");
581     }
582 
583     switch (buf->server) {
584     case SERVER_SJ3:
585     default:
586         for (i = 0; i < hinsinum[buf->server]; i++) {
587             hinsilist[buf->server][i].len = _Xsj3cmPStowOUT(buf, data,
588                     (unsigned char *)sj3_hinsi_list[i].string);
589             hinsilist[buf->server][i].data
590                 = _Xsj3cStoreWchar(data, hinsilist[buf->server][i].len + 1);
591             if (!hinsilist[buf->server][i].data)
592                 Xsj3cError("Failed to allocate hinsi data");
593         }
594         break;
595     }
596 
597     return (hinsilist[buf->server]);
598 }
599 
600 /*
601  * Xsj3cGetHinsiNum()
602  *  Return hinsi data total number.
603  */
604 int
Xsj3cGetHinsiNum(buf,cur)605 Xsj3cGetHinsiNum(buf, cur)
606     Xsj3cBuf            buf;
607     int                *cur;
608 {
609     if (!buf->hinsi) {
610         buf->hinsi = _Xsj3cHinsiInit(buf);
611     }
612     *cur = 0;
613     return (hinsinum[buf->server]);
614 }
615 
616 /*
617  * Xsj3cGetHinsis()
618  *  Return hinsi data structure.
619  */
620 Xsj3cHinsi
Xsj3cGetHinsis(buf)621 Xsj3cGetHinsis(buf)
622     Xsj3cBuf            buf;
623 {
624     if (!buf->hinsi) {
625         buf->hinsi = _Xsj3cHinsiInit(buf);
626     }
627     return (buf->hinsi);
628 }
629 
630 /*
631  * Xsj3cGetHinsi()
632  *  Set the appointed (by 1st argument) hinsi to 2nd argument.
633  */
634 wchar *
Xsj3cGetHinsi(buf,n,len)635 Xsj3cGetHinsi(buf, n, len)
636     Xsj3cBuf            buf;
637     int                 n;
638     int                *len;
639 {
640     if (!buf->hinsi) {
641         buf->hinsi = _Xsj3cHinsiInit(buf);
642     }
643     *len = buf->hinsi[n].len;
644     return (buf->hinsi[n].data);
645 }
646 
647 /*
648  * Xsj3cSetHinsi()
649  *  Set the selected hinsi.
650  */
651 int
Xsj3cSetHinsi(buf,sel_hinsi,changed,flush)652 Xsj3cSetHinsi(buf, sel_hinsi, changed, flush)
653     Xsj3cBuf    buf;
654     int         sel_hinsi;
655     int         *changed;
656     int         *flush;
657 {
658     buf->curhinsi = sel_hinsi;
659     _Xsj3cFlushDictMsg(buf);
660     *changed = OFF;
661     *flush = OFF;
662     return 0;
663 }
664 
665 /*
666  * Xsj3cEndHinsi()
667  *  End hinsi select mode(SelectMode) and back to ConvedMode.
668  */
669 void
Xsj3cEndHinsi(buf)670 Xsj3cEndHinsi(buf)
671     Xsj3cBuf    buf;
672 {
673     buf->convmode = DictModeMask;
674 }
675