1/* Copyright 1992 NEC Corporation, Tokyo, Japan.
2 *
3 * Permission to use, copy, modify, distribute and sell this software
4 * and its documentation for any purpose is hereby granted without
5 * fee, provided that the above copyright notice appear in all copies
6 * and that both that copyright notice and this permission notice
7 * appear in supporting documentation, and that the name of NEC
8 * Corporation not be used in advertising or publicity pertaining to
9 * distribution of the software without specific, written prior
10 * permission.  NEC Corporation makes no representations about the
11 * suitability of this software for any purpose.  It is provided "as
12 * is" without express or implied warranty.
13 *
14 * NEC CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
16 * NO EVENT SHALL NEC CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19 * OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#if !defined(lint) && !defined(__CODECENTER__)
24static char rcs_id[] = "@(#) 102.1 $Id: uldefine.c 14875 2005-11-12 21:25:31Z bonefish $";
25#endif
26
27#include	<errno.h>
28#include 	"canna.h"
29#include "RK.h"
30#include "RKintern.h"
31
32// static void clearTourokuContext(tourokuContext p);
33static tourokuContext newTourokuContext(void);
34static int uuTTangoEveryTimeCatch(uiContext d, int retval, mode_context env);
35static int uuTTangoExitCatch(uiContext d, int retval, mode_context env);
36static int uuT2TangoEveryTimeCatch(uiContext d, int retval, mode_context env);
37static int uuT2TangoExitCatch(uiContext d, int retval, mode_context nyc);
38static int uuT2TangoQuitCatch(uiContext d, int retval, mode_context env);
39static int uuTMakeDicYesCatch(uiContext d, int retval, mode_context env);
40static int uuTMakeDicQuitCatch(uiContext d, int retval, mode_context env);
41static int uuTMakeDicNoCatch(uiContext d, int retval, mode_context env);
42static int dicTourokuDo(uiContext d);
43static struct dicname *findUsrDic(void);
44static int checkUsrDic(uiContext d);
45static int dicTourokuTangoPre(uiContext d);
46static int acDicTourokuTangoPre(uiContext d, int dn, mode_context dm);
47static int uuTYomiEveryTimeCatch(uiContext d, int retval, mode_context env);
48static int uuTYomiExitCatch(uiContext d, int retval, mode_context env);
49static int uuTYomiQuitCatch(uiContext d, int retval, mode_context env);
50static int dicTourokuYomi(uiContext d);
51static int acDicTourokuYomi(uiContext d, int dn, mode_context dm);
52static int dicTourokuYomiDo(uiContext d, canna_callback_t quitfunc);
53static int uuTHinshiExitCatch(uiContext d, int retval, mode_context env);
54static int uuTHinshiQuitCatch(uiContext d, int retval, mode_context env);
55extern int specialfunc (uiContext, int);
56
57#if !defined(NO_EXTEND_MENU) && !defined(WIN)
58#ifdef luna88k
59extern int errno;
60#endif
61
62
63static char *shinshitbl1[] =
64{
65  "\314\276\273\354",                 /* �������� */
66  "\270\307\315\255\314\276\273\354", /* ���������������� */
67  "\306\260\273\354",                 /* �������� */
68  "\267\301\315\306\273\354",         /* ������������ */
69  "\267\301\315\306\306\260\273\354", /* ���������������� */
70  "\311\373\273\354",                 /* �������� */
71  "\244\275\244\316\302\276",         /* ������������ */
72};
73
74static char *shinshitbl2[] =
75{
76  "\303\261\264\301\273\372",           /* ������������ */
77  "\277\364\273\354",                   /* �������� */
78  "\317\242\302\316\273\354",           /* ������������ */
79  "\300\334\302\263\273\354\241\246\264\266\306\260\273\354",/* ���������������������������� */
80};
81
82
83static int tblflag;
84
85#define TABLE1 1
86#define TABLE2 2
87
88#define HINSHI1_SZ (sizeof(shinshitbl1) / sizeof(char *))
89#define HINSHI2_SZ (sizeof(shinshitbl2) / sizeof(char *))
90
91#define SONOTA       HINSHI1_SZ - 1
92
93static WCHAR_T *hinshitbl1[HINSHI1_SZ];
94static WCHAR_T *hinshitbl2[HINSHI2_SZ];
95
96static WCHAR_T *b1, *b2;
97
98int
99initHinshiTable(void)
100{
101  int retval = 0;
102
103  retval = setWStrings(hinshitbl1, shinshitbl1, HINSHI1_SZ);
104  if (retval != NG) {
105    retval = setWStrings(hinshitbl2, shinshitbl2, HINSHI2_SZ);
106    b1 = WString("\303\261\270\354?[");
107                  /* �������� */
108    b2 = WString("]");
109    if (!b1 || !b2) {
110      retval = NG;
111    }
112  }
113  return retval;
114}
115
116static void
117clearTango(uiContext d)
118{
119  tourokuContext tc = (tourokuContext)d->modec;
120
121  tc->tango_buffer[0] = 0;
122  tc->tango_len = 0;
123}
124
125void
126clearYomi(uiContext d)
127{
128  tourokuContext tc = (tourokuContext)d->modec;
129
130  tc->yomi_buffer[0] = 0;
131  tc->yomi_len = 0;
132}
133
134inline void
135clearTourokuContext(tourokuContext p)
136{
137  p->id = TOUROKU_CONTEXT;
138  p->genbuf[0] = 0;
139  p->qbuf[0] = 0;
140  p->tango_buffer[0] = 0;
141  p->tango_len = 0;
142  p->yomi_buffer[0] = 0;
143  p->yomi_len = 0;
144  p->curHinshi = 0;
145  p->newDic = (struct dicname *)0;
146  p->hcode[0] = 0;
147  p->katsuyou = 0;
148  p->workDic2 = (deldicinfo *)0;
149  p->workDic3 = (deldicinfo *)0;
150  p->udic = (WCHAR_T **)0;
151  p->delContext = 0;
152
153//  return(0);
154}
155
156static tourokuContext
157newTourokuContext(void)
158{
159  tourokuContext tcxt;
160
161  if ((tcxt = (tourokuContext)malloc(sizeof(tourokuContextRec)))
162                                          == (tourokuContext)NULL) {
163#ifndef WIN
164    jrKanjiError = "malloc (newTourokuContext) ��������������������������������";
165#else
166    jrKanjiError = "malloc (newTourokuContext) \244\307\244\255\244\336"
167	"\244\273\244\363\244\307\244\267\244\277";
168#endif
169    return (tourokuContext)NULL;
170  }
171  clearTourokuContext(tcxt);
172
173  return tcxt;
174}
175
176int getTourokuContext(uiContext d)
177{
178  tourokuContext tc;
179  int retval = 0;
180
181  if (pushCallback(d, d->modec, NO_CALLBACK, NO_CALLBACK,
182                                  NO_CALLBACK, NO_CALLBACK) == 0) {
183#ifndef WIN
184    jrKanjiError = "malloc (pushCallback) ��������������������������������";
185#else
186    jrKanjiError = "malloc (pushCallback) \244\307\244\255\244\336\244\273"
187	"\244\363\244\307\244\267\244\277";
188#endif
189    return(NG);
190  }
191
192  if((tc = newTourokuContext()) == (tourokuContext)NULL) {
193    popCallback(d);
194    return(NG);
195  }
196  tc->majorMode = d->majorMode;
197  tc->next = d->modec;
198  d->modec = (mode_context)tc;
199
200  tc->prevMode = d->current_mode;
201
202  return(retval);
203}
204
205void
206popTourokuMode(uiContext d)
207{
208  tourokuContext tc = (tourokuContext)d->modec;
209
210  d->modec = tc->next;
211  d->current_mode = tc->prevMode;
212  free(tc);
213}
214
215
216/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
217 * ����������������������������������������                                                      *
218 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
219
220static
221int uuTTangoEveryTimeCatch(uiContext d, int retval, mode_context env)
222{
223  tourokuContext tc = (tourokuContext)env;
224  int len, echoLen, revPos;
225  WCHAR_T tmpbuf[ROMEBUFSIZE];
226  /* I will leave this stack located array becase this will not be
227     compiled in case WIN is defined.  1996.6.5 kon */
228
229  retval = d->nbytes = 0;
230
231#ifdef DEBUG
232  checkModec(d);
233#endif
234  if((echoLen = d->kanji_status_return->length) < 0 || d->more.todo)
235    return(retval);
236
237  if (echoLen == 0) {
238    d->kanji_status_return->revPos = 0;
239    d->kanji_status_return->revLen = 0;
240  }
241
242  if(d->kanji_status_return->info & KanjiGLineInfo &&
243     d->kanji_status_return->gline.length > 0) {
244    echostrClear(d);
245    return 0;
246  }
247
248  WStrncpy(tmpbuf, d->kanji_status_return->echoStr, echoLen);
249  tmpbuf[echoLen] = (WCHAR_T)'\0';
250
251  WStrcpy(d->genbuf, b1);
252  WStrcat(d->genbuf, tmpbuf);
253  WStrcat(d->genbuf, b2);
254
255  revPos = WStrlen(b1);
256
257  len = revPos + echoLen + 1;
258  WStrcpy(d->genbuf + len, tc->genbuf); /* �������������������� */
259
260  len += WStrlen(tc->genbuf);
261  tc->genbuf[0] = 0;
262  d->kanji_status_return->gline.line = d->genbuf;
263  d->kanji_status_return->gline.length = len;
264  if (d->kanji_status_return->revLen) {
265    d->kanji_status_return->gline.revPos =
266      d->kanji_status_return->revPos + revPos;
267    d->kanji_status_return->gline.revLen = d->kanji_status_return->revLen;
268  }
269  else { /* ������������������������������������ */
270    d->kanji_status_return->gline.revPos = len - WStrlen(b2);
271    d->kanji_status_return->gline.revLen = 1;
272  }
273  d->kanji_status_return->info |= KanjiGLineInfo;
274  d->kanji_status_return->length = 0;
275
276  echostrClear(d);
277#ifdef WIN
278  if (checkGLineLen(d) < 0) {
279    echostrClear(d);
280  }
281#else
282  checkGLineLen(d);
283#endif
284
285  return retval;
286}
287
288static
289int uuTTangoExitCatch(uiContext d, int retval, mode_context env)
290/* ARGSUSED */
291{
292  tourokuContext tc;
293
294  popCallback(d); /* ������������ pop */
295
296  tc = (tourokuContext)d->modec;
297
298  WStrncpy(tc->tango_buffer, d->buffer_return, retval);
299  tc->tango_buffer[retval] = (WCHAR_T)'\0';
300  tc->tango_len = retval;
301
302  return(dicTourokuYomi(d));
303}
304
305int uuTTangoQuitCatch(uiContext d, int retval, mode_context env)
306/* ARGSUSED */
307{
308  popCallback(d); /* ������������ pop */
309
310  freeAndPopTouroku(d);
311  GlineClear(d);
312  currentModeInfo(d);
313  return prevMenuIfExist(d);
314}
315
316static
317int uuT2TangoEveryTimeCatch(uiContext d, int retval, mode_context env)
318{
319  yomiContext nyc;
320  int echoLen, pos, offset;
321  WCHAR_T tmpbuf[ROMEBUFSIZE];
322  /* I will leave this stack located array becase this will not be
323     compiled in case WIN is defined.  1996.6.5 kon */
324
325  nyc = (yomiContext)env;
326
327#ifdef DEBUG
328  checkModec(d);
329#endif
330  if(d->kanji_status_return->info & KanjiThroughInfo) {
331    extern KanjiModeRec yomi_mode;
332    _do_func_slightly(d, 0, (mode_context)nyc, &yomi_mode);
333  } else if(retval > 0){
334    /* ���������������� */
335    generalReplace(nyc->kana_buffer, nyc->kAttr, &nyc->kRStartp,
336		   &nyc->kCurs, &nyc->kEndp, 0, d->buffer_return,
337		   retval, HENKANSUMI);
338    generalReplace(nyc->romaji_buffer, nyc->rAttr, &nyc->rStartp,
339		   &nyc->rCurs, &nyc->rEndp, 0, d->buffer_return,
340		   retval, 0);
341    nyc->rStartp = nyc->rCurs;
342    nyc->kRStartp = nyc->kCurs;
343  }
344
345  d->kanji_status_return->info &= ~(KanjiThroughInfo | KanjiEmptyInfo);
346  if((echoLen = d->kanji_status_return->length) < 0)
347    return(retval);
348
349  WStrncpy(tmpbuf, d->kanji_status_return->echoStr, echoLen);
350
351  WStrncpy(d->genbuf, nyc->kana_buffer, pos = offset = nyc->kCurs);
352
353  WStrncpy(d->genbuf + pos, tmpbuf, echoLen);
354  pos += echoLen;
355  WStrncpy(d->genbuf + pos, nyc->kana_buffer + offset, nyc->kEndp - offset);
356  pos += nyc->kEndp - offset;
357  if (d->kanji_status_return->revLen == 0 && /* ������������������������������������... */
358      nyc->kEndp - offset) { /* ���������������������������������������������������������������� */
359    d->kanji_status_return->revLen = 1;
360    d->kanji_status_return->revPos = offset + echoLen;
361  }
362  else {
363    d->kanji_status_return->revPos += offset;
364  }
365  d->kanji_status_return->echoStr = d->genbuf;
366  d->kanji_status_return->length = pos;
367
368  return retval;
369}
370
371/************************************************
372 *  ������������������������������������������������������������������������������������  *
373 ************************************************/
374static
375int uuT2TangoExitCatch(uiContext d, int retval, mode_context nyc)
376/* ARGSUSED */
377{
378  yomiContext yc;
379
380  popCallback(d); /* ������������ pop */
381
382  yc = (yomiContext)d->modec;
383  d->nbytes = retval = yc->kEndp;
384  WStrncpy(d->buffer_return, yc->kana_buffer, retval);
385  d->buffer_return[retval] = (WCHAR_T)'\0';
386
387  RomajiClearYomi(d);
388  popYomiMode(d);
389  d->status = EXIT_CALLBACK;
390
391  return retval;
392}
393
394static
395int uuT2TangoQuitCatch(uiContext d, int retval, mode_context env)
396/* ARGSUSED */
397{
398  popCallback(d); /* ������������ pop */
399
400  popYomiMode(d);
401
402  d->status = QUIT_CALLBACK;
403
404  return(0);
405}
406
407/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
408 * ������������������������������������                                                        *
409 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
410
411static
412int uuTMakeDicYesCatch(uiContext d, int retval, mode_context env)
413/* ARGSUSED */
414{
415  int err = 0, perr = 0;
416  tourokuContext tc;
417  WCHAR_T **dp;
418  extern int defaultContext;
419
420  popCallback(d); /* yesNo ���������������� */
421
422  tc = (tourokuContext)d->modec;
423
424  if(defaultContext < 0) {
425    if((KanjiInit() < 0) || (defaultContext < 0)) {
426      jrKanjiError = KanjiInitError();
427      freeAndPopTouroku(d);
428      defineEnd(d);
429      return(GLineNGReturn(d));
430    }
431  }
432  /* �������������������� */
433  if (RkwCreateDic(defaultContext, tc->newDic->name, 0x80) < 0) {
434    err++; if (errno == EPIPE) perr++;
435    MBstowcs(d->genbuf, "\274\255\275\361\244\316\300\270\300\256\244\313"
436	"\274\272\307\324\244\267\244\336\244\267\244\277", 256);
437                          /* ������������������������������������������������ */
438  } else if(RkwMountDic(defaultContext, tc->newDic->name, 0) < 0) {
439    err++; if (errno == EPIPE) perr++;
440    MBstowcs(d->genbuf, "\274\255\275\361\244\316\245\336\245\246\245\363"
441	"\245\310\244\313\274\272\307\324\244\267\244\336\244\267\244\277", 256);
442                          /* �������������������������������������������������������� */
443  } else if(d->contextCache != -1 &&
444    RkwMountDic(d->contextCache, tc->newDic->name, 0) < 0) {
445    err++; if (errno == EPIPE) perr++;
446    MBstowcs(d->genbuf, "\274\255\275\361\244\316\245\336\245\246\245\363"
447	"\245\310\244\313\274\272\307\324\244\267\244\336\244\267\244\277", 256);
448                          /* �������������������������������������������������������� */
449  }
450
451  if(err) {
452    if (perr) {
453      jrKanjiPipeError();
454    }
455    makeGLineMessage(d, d->genbuf, WStrlen(d->genbuf));
456    freeAndPopTouroku(d);
457    defineEnd(d);
458    currentModeInfo(d);
459    return(0);
460  }
461
462  tc->newDic->dicflag = DIC_MOUNTED;
463
464  /* ���������������������������������������������������� */
465  dp = tc->udic;
466  if (dp) {
467    while (*dp) {
468      dp++;
469    }
470    *dp++ = WString(tc->newDic->name);
471    *dp = 0;
472  }
473
474  return(dicTourokuTango(d, uuTTangoQuitCatch));
475}
476
477static
478int uuTMakeDicQuitCatch(uiContext d, int retval, mode_context env)
479/* ARGSUSED */
480{
481  popCallback(d); /* yesNo ���������������� */
482
483  freeAndPopTouroku(d);
484
485  return prevMenuIfExist(d);
486}
487
488static
489int uuTMakeDicNoCatch(uiContext d, int retval, mode_context env)
490/* ARGSUSED */
491{
492  popCallback(d); /* yesNo ���������������� */
493
494  freeAndPopTouroku(d);
495  defineEnd(d);
496  currentModeInfo(d);
497
498  GlineClear(d);
499  defineEnd(d);
500  return(retval);
501}
502
503/*
504  ������������������������������������������������������������������������������������������������
505 */
506WCHAR_T **
507getUserDicName(uiContext d)
508/* ARGSUSED */
509{
510  int nmudic; /* ���������������������������������������������������������������� */
511  struct dicname *p;
512  WCHAR_T **tourokup, **tp;
513  extern int defaultContext;
514
515  if(defaultContext < 0) {
516    if((KanjiInit() < 0) || (defaultContext < 0)) {
517      jrKanjiError = KanjiInitError();
518      return (WCHAR_T **)0;
519    }
520  }
521
522  for (nmudic = 0, p = kanjidicnames ; p ; p = p->next) {
523    if (p->dictype == DIC_USER && p->dicflag == DIC_MOUNTED) {
524      nmudic++;
525    }
526  }
527
528  /* return BUFFER ���� alloc */
529  if ((tourokup = (WCHAR_T **)calloc(nmudic + 2, sizeof(WCHAR_T *)))
530                                                  == (WCHAR_T **)NULL) {
531    /* + 2 ������������ 1 ���������������������������������������������������������������������������������������������������� */
532#ifndef WIN
533    jrKanjiError = "malloc (getUserDicName) ��������������������������������";
534#else
535    jrKanjiError = "malloc (getUserDicName) \244\307\244\255\244\336\244\273"
536	"\244\363\244\307\244\267\244\277";
537#endif
538    return (WCHAR_T **)0;
539  }
540
541  for (tp = tourokup + nmudic, p = kanjidicnames ; p ; p = p->next) {
542    if (p->dictype == DIC_USER && p->dicflag == DIC_MOUNTED) {
543      *--tp = WString(p->name);
544    }
545  }
546  tourokup[nmudic] = (WCHAR_T *)0;
547
548  return (WCHAR_T **)tourokup;
549}
550
551/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
552 * ����������������������������������������                                                      *
553 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
554/* ������������������������������������ */
555
556int dicTouroku(uiContext d)
557{
558  tourokuContext tc;
559  yomiContext yc = (yomiContext)d->modec;
560
561  if (yc->generalFlags & CANNA_YOMI_CHGMODE_INHIBITTED) {
562    return NothingChangedWithBeep(d);
563  }
564  if(dicTourokuDo(d) < 0) {
565    defineEnd(d);
566    return(GLineNGReturn(d));
567  }
568
569  tc = (tourokuContext)d->modec;
570
571  /* ������������������������������������������������ */
572  if(!*tc->udic) {
573    checkUsrDic(d);
574    return(0); /* ��������������������������������������������������������������������������������(��������)����
575		  ������������������������������������checkUsrDic ����������������������������������������
576		  �������������������������������������������������������������������� */
577  }
578  tblflag = TABLE1;
579  return(dicTourokuTango(d, uuTTangoQuitCatch));
580}
581
582static
583int dicTourokuDo(uiContext d)
584{
585  tourokuContext tc;
586  WCHAR_T **up;
587
588  d->status = 0;
589
590  /* �������������������������������������������������������������������������������������������� */
591  if((up = getUserDicName(d)) == 0) {
592    return(NG);
593  }
594
595  if (getTourokuContext(d) < 0) {
596    if (up) {
597      WCHAR_T **p = up;
598
599      for ( ; *p; p++) {
600        WSfree(*p);
601      }
602      free(up);
603    }
604    return(NG);
605  }
606
607  tc = (tourokuContext)d->modec;
608
609  tc->udic = up;
610
611  return(0);
612}
613
614/*
615 * ��������������������������������������������
616 *  ��������������������������������������������������������������������������������������������
617 *  ������������������������������������������������
618 */
619static struct dicname *
620findUsrDic(void)
621{
622  struct dicname *res = (struct dicname *)0, *p;
623
624  for (p = kanjidicnames ; p ; p = p->next) {
625    if (p->dictype == DIC_USER) {
626      res = p;
627    }
628  }
629  return res;
630}
631
632/*
633 * ����������������������������������������������������������������
634 * ������������������������������������������������������������������������������������������������������������������������
635 *   ����������������������������������������������������������������
636 *     ���� ��������������������(������������������������������������)
637 * ����������������������������������������������������������������������������������������������������������������������������������������
638 * ������������������������������������������������������������������������������������������������������������������������
639 *   ��������������������������������������������������������
640 */
641static
642int checkUsrDic(uiContext d)
643{
644  tourokuContext tc = (tourokuContext)d->modec;
645  coreContext ync;
646  struct dicname *u;
647  WCHAR_T xxxx[512];
648  /* I will leave this stack located array becase this will not be
649     compiled in case WIN is defined.  1996.6.5 kon */
650
651  u = findUsrDic();
652
653  /* ��������������������������������������������������������������������������������������������������������������������
654     ����������������������������������������������������                                */
655  if (u) {
656    if (u->dicflag == DIC_MOUNT_FAILED) {
657      char tmpbuf[1024];
658      sprintf(tmpbuf, "\303\261\270\354\305\320\317\277\315\321\274\255"
659	"\275\361\244\254\244\242\244\352\244\336\244\273\244\363\241\243"
660	"\274\255\275\361(%s)\244\362\272\356\300\256\244\267\244\336\244"
661	"\271\244\253?(y/n)",
662	      u->name);
663                /* ����������������������������������������������������������������(%s)���������������������������� */
664      makeGLineMessageFromString(d, tmpbuf);
665      tc->newDic = u; /* ���������������� */
666      if(getYesNoContext(d,
667			 NO_CALLBACK, uuTMakeDicYesCatch,
668			 uuTMakeDicQuitCatch, uuTMakeDicNoCatch) < 0) {
669	defineEnd(d);
670	return(GLineNGReturn(d));
671      }
672      makeGLineMessage(d, d->genbuf, WStrlen(d->genbuf));
673      ync = (coreContext)d->modec;
674      ync->majorMode = CANNA_MODE_ExtendMode;
675      ync->minorMode = CANNA_MODE_TourokuMode;
676    }
677  }
678
679  /* ������������������������������������������������������������������������������������������������������������������������
680     ������������������������������������������������������������������������������������                  */
681  if (!u || u->dicflag == DIC_NOT_MOUNTED) {
682    MBstowcs(xxxx, "\303\261\270\354\305\320\317\277\315\321\274\255\275\361"
683	"\244\254\273\330\304\352\244\265\244\354\244\306\244\244\244\336"
684	"\244\273\244\363", 512);
685                 /* �������������������������������������������������������������������� */
686    WStrcpy(d->genbuf, xxxx);
687    makeGLineMessage(d, d->genbuf, WStrlen(d->genbuf));
688    freeAndPopTouroku(d);
689    defineEnd(d);
690    currentModeInfo(d);
691  }
692
693  return(0);
694}
695
696int dicTourokuTango(uiContext d, canna_callback_t quitfunc)
697{
698  tourokuContext tc = (tourokuContext)d->modec;
699  yomiContext yc, yc2;
700  int retval = 0;
701
702  yc = GetKanjiString(d, (WCHAR_T *)0, 0,
703		      CANNA_NOTHING_RESTRICTED,
704		      (int)CANNA_YOMI_CHGMODE_INHIBITTED,
705		      (int)CANNA_YOMI_END_IF_KAKUTEI,
706		      CANNA_YOMI_INHIBIT_NONE,
707		      uuTTangoEveryTimeCatch, uuTTangoExitCatch,
708		      quitfunc);
709  if (yc == (yomiContext)0) {
710    freeAndPopTouroku(d);
711    defineEnd(d);
712    currentModeInfo(d);
713    return NoMoreMemory();
714  }
715  yc2 = GetKanjiString(d, (WCHAR_T *)0, 0,
716		      CANNA_NOTHING_RESTRICTED,
717		      (int)CANNA_YOMI_CHGMODE_INHIBITTED,
718		      (int)!CANNA_YOMI_END_IF_KAKUTEI,
719		      CANNA_YOMI_INHIBIT_NONE,
720		      uuT2TangoEveryTimeCatch, uuT2TangoExitCatch,
721		      uuT2TangoQuitCatch);
722  if (yc2 == (yomiContext)0) {
723    popYomiMode(d);  /* yc1 ���� pop �������� */
724    popCallback(d);
725    freeAndPopTouroku(d);
726    defineEnd(d);
727    currentModeInfo(d);
728    return NoMoreMemory();
729  }
730  yc2->generalFlags |= CANNA_YOMI_DELETE_DONT_QUIT;
731
732  yc2->majorMode = CANNA_MODE_ExtendMode;
733  yc2->minorMode = CANNA_MODE_TourokuMode;
734  currentModeInfo(d);
735
736  return(retval);
737}
738
739static
740int dicTourokuTangoPre(uiContext d)
741{
742  return dicTourokuTango(d, uuTTangoQuitCatch);
743}
744
745static
746int acDicTourokuTangoPre(uiContext d, int dn, mode_context dm)
747/* ARGSUSED */
748{
749  popCallback(d);
750  return dicTourokuTangoPre(d);
751}
752
753/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
754 * ����������������������������������������                                                      *
755 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
756
757static
758int uuTYomiEveryTimeCatch(uiContext d, int retval, mode_context env)
759{
760  tourokuContext tc = (tourokuContext)env;
761  int len, echoLen, revPos;
762  WCHAR_T tmpbuf[ROMEBUFSIZE];
763
764  retval = d->nbytes = 0;
765
766  if((echoLen = d->kanji_status_return->length) < 0)
767    return(retval);
768
769  if (echoLen == 0) {
770    d->kanji_status_return->revPos = 0;
771    d->kanji_status_return->revLen = 0;
772  }
773
774  /* �������������������� echoStr ���� d->genbuf �������������������������������� copy ���������������� */
775  WStrncpy(tmpbuf, d->kanji_status_return->echoStr, echoLen);
776
777  d->kanji_status_return->info &= ~(KanjiThroughInfo | KanjiEmptyInfo);
778  revPos = MBstowcs(d->genbuf, "\303\261\270\354[", ROMEBUFSIZE);
779                               /* �������� */
780  WStrcpy(d->genbuf + revPos, tc->tango_buffer);
781  revPos += WStrlen(tc->tango_buffer);
782  revPos += MBstowcs(d->genbuf + revPos, "] \306\311\244\337?[", ROMEBUFSIZE - revPos);
783                                           /* �������� */
784  WStrncpy(d->genbuf + revPos, tmpbuf, echoLen);
785  len = echoLen + revPos;
786  d->genbuf[len++] = (WCHAR_T) ']';
787  WStrcpy(d->genbuf + len, tc->genbuf);
788  len += WStrlen(tc->genbuf);
789  tc->genbuf[0] = 0;
790  d->kanji_status_return->gline.line = d->genbuf;
791  d->kanji_status_return->gline.length = len;
792  if (d->kanji_status_return->revLen) {
793    d->kanji_status_return->gline.revPos =
794      d->kanji_status_return->revPos + revPos;
795    d->kanji_status_return->gline.revLen = d->kanji_status_return->revLen;
796  }
797  else { /* ������������������������������������ */
798    d->kanji_status_return->gline.revPos = len - 1;
799    d->kanji_status_return->gline.revLen = 1;
800  }
801  d->kanji_status_return->info |= KanjiGLineInfo;
802  echostrClear(d);
803#ifdef WIN
804  if (checkGLineLen(d) < 0) {
805    echostrClear(d);
806  }
807#else
808  checkGLineLen(d);
809#endif
810
811  return retval;
812}
813
814static
815int uuTYomiExitCatch(uiContext d, int retval, mode_context env)
816/* ARGSUSED */
817{
818  tourokuContext tc;
819
820  popCallback(d); /* ������������ pop */
821
822  tc = (tourokuContext)d->modec;
823
824  WStrncpy(tc->yomi_buffer, d->buffer_return, retval);
825  tc->yomi_buffer[retval] = (WCHAR_T)'\0';
826  tc->yomi_len = retval;
827
828  return(dicTourokuHinshi(d));
829}
830
831static int uuTYomiQuitCatch (uiContext, int, mode_context);
832
833static
834int uuTYomiQuitCatch(uiContext d, int retval, mode_context env)
835/* ARGSUSED */
836{
837  popCallback(d); /* ������������ pop */
838
839  clearTango(d);
840  clearYomi(d);
841
842  return(dicTourokuTango(d, uuTTangoQuitCatch));
843}
844
845static
846int dicTourokuYomi(uiContext d)
847{
848  return(dicTourokuYomiDo(d, uuTYomiQuitCatch));
849}
850
851static
852int acDicTourokuYomi(uiContext d, int dn, mode_context dm)
853/* ARGSUSED */
854{
855  popCallback(d);
856  return dicTourokuYomi(d);
857}
858
859static
860int dicTourokuYomiDo(uiContext d, canna_callback_t quitfunc)
861{
862  yomiContext yc;
863  tourokuContext tc = (tourokuContext)d->modec;
864  int retval = 0;
865
866  if(tc->tango_len < 1) {
867    clearTango(d);
868    return canna_alert(d, "\303\261\270\354\244\362\306\376\316\317\244\267\244\306\244\257\244\300\244\265\244\244", acDicTourokuTangoPre);
869                         /* �������������������������������������������� */
870  }
871
872  yc = GetKanjiString(d, (WCHAR_T *)0, 0,
873		      CANNA_NOTHING_RESTRICTED,
874		      (int)CANNA_YOMI_CHGMODE_INHIBITTED,
875		      (int)CANNA_YOMI_END_IF_KAKUTEI,
876		      (CANNA_YOMI_INHIBIT_HENKAN | CANNA_YOMI_INHIBIT_ASHEX |
877		      CANNA_YOMI_INHIBIT_ASBUSHU),
878		      uuTYomiEveryTimeCatch, uuTYomiExitCatch,
879		      quitfunc);
880  if (yc == (yomiContext)0) {
881    freeAndPopTouroku(d);
882    defineEnd(d);
883    currentModeInfo(d);
884    return NoMoreMemory();
885  }
886  yc->majorMode = CANNA_MODE_ExtendMode;
887  yc->minorMode = CANNA_MODE_TourokuMode;
888  currentModeInfo(d);
889
890  return(retval);
891}
892
893/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
894 * ����������������������������������������                                                      *
895 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
896
897static
898int uuTHinshiExitCatch(uiContext d, int retval, mode_context env)
899/* ARGSUSED */
900{
901  forichiranContext fc;
902  tourokuContext tc;
903  int cur;
904
905  d->nbytes = 0;
906
907  popCallback(d); /* ������������ pop */
908
909  fc = (forichiranContext)d->modec;
910  cur = fc->curIkouho;
911
912  popForIchiranMode(d);
913  popCallback(d);
914
915  if (tblflag == TABLE1 && cur == SONOTA) {
916    tblflag = TABLE2;
917    return dicTourokuHinshi(d);
918  }
919
920  if (tblflag == TABLE2) {
921    cur += SONOTA;
922  }
923
924  tc = (tourokuContext)d->modec;
925
926  tc->curHinshi = cur;
927
928  return(dicTourokuHinshiDelivery(d));
929}
930
931static
932int uuTHinshiQuitCatch(uiContext d, int retval, mode_context env)
933/* ARGSUSED */
934{
935  popCallback(d); /* ������������ pop */
936
937  popForIchiranMode(d);
938  popCallback(d);
939
940  if (tblflag == TABLE2) {
941    tblflag = TABLE1;
942    return dicTourokuHinshi(d);
943  }
944
945  clearYomi(d);
946
947  return(dicTourokuYomi(d));
948}
949
950int dicTourokuHinshi(uiContext d)
951{
952  tourokuContext tc = (tourokuContext)d->modec;
953  forichiranContext fc;
954  ichiranContext ic;
955  unsigned inhibit = 0;
956  int currentkouho, retval = 0, numkouho;
957
958  d->status = 0;
959
960  if(tc->yomi_len < 1) {
961    return canna_alert(d, "\306\311\244\337\244\362\306\376\316\317\244\267"
962	"\244\306\244\257\244\300\244\265\244\244", acDicTourokuYomi);
963                          /* �������������������������������������������� */
964  }
965
966  if((retval = getForIchiranContext(d)) < 0) {
967    freeDic(tc);
968    defineEnd(d);
969    return(GLineNGReturnTK(d));
970  }
971
972  fc = (forichiranContext)d->modec;
973
974  /* selectOne �������������������������������� */
975  if (tblflag == TABLE2) {
976    fc->allkouho = hinshitbl2;
977    numkouho = HINSHI2_SZ;
978  }
979  else {
980    fc->allkouho = hinshitbl1;
981    numkouho = HINSHI1_SZ;
982  }
983
984  fc->curIkouho = 0;
985  currentkouho = 0;
986  if (!cannaconf.HexkeySelect)
987    inhibit |= ((unsigned char)NUMBERING | (unsigned char)CHARINSERT);
988  else
989    inhibit |= (unsigned char)CHARINSERT;
990
991  if((retval = selectOne(d, fc->allkouho, &fc->curIkouho, numkouho,
992		 BANGOMAX, inhibit, currentkouho, WITH_LIST_CALLBACK,
993		 NO_CALLBACK, uuTHinshiExitCatch,
994		 uuTHinshiQuitCatch, uiUtilIchiranTooSmall)) < 0) {
995    popForIchiranMode(d);
996    popCallback(d);
997    freeDic(tc);
998    defineEnd(d);
999    return(GLineNGReturnTK(d));
1000  }
1001
1002  ic = (ichiranContext)d->modec;
1003  ic->majorMode = CANNA_MODE_ExtendMode;
1004  ic->minorMode = CANNA_MODE_TourokuHinshiMode;
1005  currentModeInfo(d);
1006
1007  /* ������������������������������������������������������������������������ */
1008  if(ic->tooSmall) {
1009    d->status = AUX_CALLBACK;
1010    return(retval);
1011  }
1012
1013  if ( !(ic->flags & ICHIRAN_ALLOW_CALLBACK) ) {
1014    makeGlineStatus(d);
1015  }
1016
1017  /* d->status = ICHIRAN_EVERYTIME; */
1018
1019  return(retval);
1020}
1021
1022/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1023 * jrKanjiControl ����                                                         *
1024 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1025
1026int dicTourokuControl(uiContext d, WCHAR_T *tango, canna_callback_t quitfunc)
1027{
1028  tourokuContext tc;
1029
1030  if(dicTourokuDo(d) < 0) {
1031    return(GLineNGReturn(d));
1032  }
1033
1034  tc = (tourokuContext)d->modec;
1035
1036  if(!*tc->udic) {
1037    if(checkUsrDic(d) < 0)
1038      return(GLineNGReturn(d));
1039    else
1040      return(0);
1041  }
1042
1043  if(tango == 0 || tango[0] == 0) {
1044    return(dicTourokuTango(d, quitfunc));
1045  }
1046
1047  WStrcpy(tc->tango_buffer, tango);
1048  tc->tango_len = WStrlen(tc->tango_buffer);
1049
1050  return(dicTourokuYomiDo(d, quitfunc));
1051}
1052#endif /* NO_EXTEND_MENU */
1053