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__)
24 static char rcs_id[] = "@(#) 102.1 $Id: hex.c,v 1.2 2003/01/10 13:08:44 aida_s Exp $";
25 #endif /* lint */
26 
27 #ifndef NO_EXTEND_MENU
28 #include "canna.h"
29 
30 #define HEXPROMPT "\245\263\241\274\245\311: "
31 #define HEXPROMPTLEN  5 /* "������: " ��Ĺ����5�Х��� */
32 
33 /*********************************************************************
34  *                      wchar_t replace begin                        *
35  *********************************************************************/
36 #ifdef wchar_t
37 # error "wchar_t is already defined"
38 #endif
39 #define wchar_t cannawc
40 
41 static int quitHex();
42 
43 /* cfuncdef
44 
45   hexEveryTimeCatch -- �ɤߤ��������ϥ⡼�ɤ�ɽ������ؿ�
46 
47  */
48 
49 static
hexEveryTimeCatch(d,retval,env)50 hexEveryTimeCatch(d, retval, env)
51      uiContext d;
52      int retval;
53      mode_context env;
54      /* ARGSUSED */
55 {
56   yomiContext yc = (yomiContext)d->modec;
57   static wchar_t buf[256];
58   /* ??? ���Τ褦�ʥХåե����������ʬ�ǻ��ĤΤϹ��ޤ����ʤ��Τǡ�
59      uiContext �ˤޤȤ�ƻ��äƶ�ͭ���ƻȤä������ɤ� */
60   int codelen = d->kanji_status_return->length;
61 
62   d->kanji_status_return->info &= ~(KanjiThroughInfo | KanjiEmptyInfo);
63 
64   if (codelen >= 0) {
65     MBstowcs(buf, HEXPROMPT, 256);
66     WStrncpy(buf + HEXPROMPTLEN, d->kanji_status_return->echoStr, codelen);
67     d->kanji_status_return->gline.line = buf;
68     d->kanji_status_return->gline.length = codelen + HEXPROMPTLEN;
69     d->kanji_status_return->gline.revPos =
70       d->kanji_status_return->revPos + HEXPROMPTLEN;
71     d->kanji_status_return->gline.revLen = d->kanji_status_return->revLen;
72     d->kanji_status_return->info |= KanjiGLineInfo;
73     echostrClear(d);
74     if (codelen == 4) { /* ��ʸ���ˤʤä��Ȥ��ˤ�.... */
75       if (convertAsHex(d)) {
76 	yc->allowedChars = CANNA_NOTHING_ALLOWED;
77 	*(d->kanji_status_return->echoStr = yc->kana_buffer + yc->kEndp + 1)
78 	  = *(d->buffer_return);
79 	d->kanji_status_return->revPos = d->kanji_status_return->revLen = 0;
80 	d->kanji_status_return->length = 1;
81 	retval = 0;
82 	if (cannaconf.hexCharacterDefiningStyle != HEX_USUAL) {
83 	  d->more.todo = 1;
84 	  d->more.ch = d->ch;
85 	  d->more.fnum = CANNA_FN_Kakutei;
86 	}
87       }
88       else {
89 	CannaBeep();
90 	d->more.todo = 1;
91 	d->more.ch = d->ch;
92 	d->more.fnum = CANNA_FN_DeletePrevious;
93       }
94     }
95     else {
96       yc->allowedChars = CANNA_ONLY_HEX;
97     }
98   }
99   checkGLineLen(d);
100   return retval;
101 }
102 
103 static
exitHex(d,retval,env)104 exitHex(d, retval, env)
105 uiContext d;
106 int retval;
107 mode_context env;
108 {
109   killmenu(d);
110   if (cvtAsHex(d, d->buffer_return, d->buffer_return, d->nbytes)) {
111     GlineClear(d);
112     popCallback(d);
113     retval = YomiExit(d, 1);
114     currentModeInfo(d);
115     return retval;
116   }
117   else {
118     return quitHex(d, 0, env);
119   }
120 }
121 
122 static
quitHex(d,retval,env)123 quitHex(d, retval, env)
124      uiContext d;
125      int retval;
126      mode_context env;
127      /* ARGSUSED */
128 {
129   GlineClear(d);
130   popCallback(d);
131   currentModeInfo(d);
132   return prevMenuIfExist(d);
133 }
134 
135 yomiContext GetKanjiString();
136 
137 static
hexMode(d,major_mode)138 hexMode(d, major_mode)
139 uiContext d;
140 int major_mode;
141 {
142   yomiContext yc;
143 
144   yc = GetKanjiString(d, (wchar_t *)NULL, 0,
145 		      CANNA_ONLY_HEX,
146 		      (int)CANNA_YOMI_CHGMODE_INHIBITTED,
147 		      (int)CANNA_YOMI_END_IF_KAKUTEI,
148 		      CANNA_YOMI_INHIBIT_ALL,
149 		      hexEveryTimeCatch, exitHex, quitHex);
150   if (yc == (yomiContext)0) {
151     return NoMoreMemory();
152   }
153   yc->majorMode = major_mode;
154   yc->minorMode = CANNA_MODE_HexMode;
155   currentModeInfo(d);
156   return 0;
157 }
158 
159 /* cfuncdef
160 
161   HexMode -- ���������ϥ⡼�ɤˤʤ�Ȥ��˸ƤФ�롣
162 
163  */
164 
HexMode(d)165 HexMode(d)
166 uiContext d;
167 {
168   yomiContext yc = (yomiContext)d->modec;
169 
170   if (yc->generalFlags & CANNA_YOMI_CHGMODE_INHIBITTED) {
171     return NothingChangedWithBeep(d);
172   }
173 
174   return hexMode(d, CANNA_MODE_HexMode);
175 }
176 
177 #endif /* NO_EXTEND_MENU */
178 
179 #ifndef wchar_t
180 # error "wchar_t is already undefined"
181 #endif
182 #undef wchar_t
183 /*********************************************************************
184  *                       wchar_t replace end                         *
185  *********************************************************************/
186