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: defaultmap.c,v 1.2 2003/09/17 08:50:53 aida_s Exp $";
25 #endif	/* lint */
26 
27 #include "canna.h"
28 #include <canna/mfdef.h>
29 
30 extern int howToBehaveInCaseOfUndefKey;
31 
32 #define DEFAULTBEHAVIOR 0
33 
34 static int (*getfunc(tbl, f))()
35 struct funccfunc *tbl;
36 unsigned char f;
37 {
38   struct funccfunc *p;
39 
40   for (p = tbl ; p->funcid || p->cfunc ; p++) {
41     if (p->funcid == (unsigned char)f) {
42       return p->cfunc;
43     }
44   }
45   return (int (*)())0;
46 }
47 
48 static
simpleUndefBehavior(d)49 simpleUndefBehavior(d)
50 uiContext d;
51 {
52   switch (howToBehaveInCaseOfUndefKey)
53     {
54     case kc_through:
55       d->kanji_status_return->length = -1;
56       return d->nbytes;
57     case kc_kakutei:
58       d->nbytes = escapeToBasicStat(d, CANNA_FN_Kakutei);
59       if (d->n_buffer > d->nbytes) {
60 	int check;
61 	d->buffer_return[d->nbytes] =
62 	  key2wchar(d->ch, &check);
63 	if (check) {
64 	  d->nbytes++;
65 	}
66       }
67       return d->nbytes;
68     case kc_kill:
69       d->nbytes = escapeToBasicStat(d, CANNA_FN_Quit);
70       if (d->n_buffer > d->nbytes) {
71 	int check;
72 	d->buffer_return[d->nbytes] =
73 	  key2wchar(d->ch, &check);
74 	if (check) {
75 	  d->nbytes++;
76 	}
77       }
78       return d->nbytes;
79     case kc_normal:
80     default:
81       return NothingChangedWithBeep(d);
82     }
83 }
84 
searchfunc(d,mode,whattodo,key,fnum)85 searchfunc(d, mode, whattodo, key, fnum)
86 uiContext d;
87 KanjiMode mode;
88 int whattodo;
89 int key;
90 int fnum;
91 {
92   int (*func)();
93 
94   if (fnum == 0) {
95     fnum = mode->keytbl[key];
96   }
97   switch (whattodo) {
98   case KEY_CALL:
99     /* ����ե��٥åȥ⡼�ɤ� strokelimit ���ȥ����ʾ�³������
100        �����ФȤ���³���ڤ� */
101     if (cannaconf.strokelimit > 0) {
102       extern KanjiModeRec alpha_mode;
103       if (mode == &alpha_mode) {
104 	d->strokecounter++;
105 #ifdef DEBUG
106 	if (iroha_debug) {
107 	  fprintf(stderr, "d->strokecounter=%d\n", d->strokecounter);
108 	}
109 #endif
110 	if (d->strokecounter == cannaconf.strokelimit + 1) {
111 	  jrKanjiPipeError();
112 	}
113       }
114       else {
115 	d->strokecounter = 0;
116 #ifdef DEBUG
117 	if (iroha_debug) {
118 	  fprintf(stderr, "d->strokecounter=%d\n", d->strokecounter);
119 	}
120 #endif
121       }
122     }
123     /* ���褤���ܳ�Ū�ʽ���(�����ޤǤ�������) */
124     if (fnum < CANNA_FN_MAX_FUNC) {
125       func = getfunc(mode->ftbl, fnum);
126       if (func) {
127 	return (*func)(d);
128       }
129     }
130     else {
131       func = getfunc(mode->ftbl, CANNA_FN_UserMode);
132       if (func) {
133 	/* func �Υ����פ���Ȱ�äƤƱ����ʤ�... */
134 	return (*func)(d, fnum);
135       }
136     }
137     /* ���Υ⡼�ɤ� fnum ���б����뵡ǽ���ʤ������������ʤ��Τǡ�
138        �ǥե���ȵ�ǽ��õ�� */
139     func = getfunc(mode->ftbl, DEFAULTBEHAVIOR);
140     if (func) {
141       return (*func)(d);
142     }
143     else {
144       return simpleUndefBehavior(d);
145     }
146     /* NOTREACHED */
147     break;
148   case KEY_CHECK:
149     if (fnum >= CANNA_FN_MAX_FUNC) {
150       fnum = CANNA_FN_UserMode;
151     }
152     return getfunc(mode->ftbl, fnum) ? 1 : 0;
153     /* NOTREACHED */
154     break;
155   case KEY_SET: /* is not supported yet */
156     return 0;
157     /* NOTREACHED */
158     break;
159   }
160   /* NOTREACHED */
161 }
162 
163 /* �༡�ɤߥ⡼���� */
164 
CYsearchfunc(d,mode,whattodo,key,fnum)165 CYsearchfunc(d, mode, whattodo, key, fnum)
166 uiContext d;
167 KanjiMode mode;
168 int whattodo;
169 int key;
170 int fnum;
171 {
172   int (*func)();
173   extern KanjiModeRec yomi_mode;
174 
175   if (fnum == 0) {
176     fnum = mode->keytbl[key];
177   }
178   if (Yomisearchfunc(d, mode, KEY_CHECK, key, fnum)) {
179     return Yomisearchfunc(d, mode, whattodo, key, fnum);
180   }
181   else {
182     func = getfunc(yomi_mode.ftbl, fnum);
183     switch (whattodo) {
184     case KEY_CALL:
185       if (func) {
186 	return (*func)(d);
187       }
188       else {
189 	return Yomisearchfunc(d, mode, whattodo, key, fnum);
190       }
191       /* NOTREACHED */
192       break;
193     case KEY_CHECK:
194       return func ? 1 : 0;
195       /* NOTREACHED */
196       break;
197     case KEY_SET:
198       return 0;
199       /* NOTREACHED */
200       break;
201     }
202   }
203   /* may be NOTREACHED */
204   return 0;
205 }
206 
207 #define NONE CANNA_FN_Undefined
208 
209 BYTE default_kmap[256] =
210 {
211 /* C-@ */       CANNA_FN_Mark,
212 /* C-a */       CANNA_FN_BeginningOfLine,
213 /* C-b */       CANNA_FN_Backward,
214 /* C-c */       CANNA_FN_BubunMuhenkan,
215 /* C-d */       CANNA_FN_DeleteNext,
216 /* C-e */       CANNA_FN_EndOfLine,
217 /* C-f */       CANNA_FN_Forward,
218 /* C-g */       CANNA_FN_Quit,
219 /* C-h */       CANNA_FN_DeletePrevious,
220 /* C-i */       CANNA_FN_Shrink,
221 /* C-j */       CANNA_FN_BubunKakutei,
222 /* C-k */       CANNA_FN_KillToEndOfLine,
223 /* C-l */       CANNA_FN_ToLower,
224 /* C-m */       CANNA_FN_Kakutei,
225 /* C-n */       CANNA_FN_Next,
226 /* C-o */       CANNA_FN_Extend,
227 /* C-p */       CANNA_FN_Prev,
228 /* C-q */       CANNA_FN_QuotedInsert,
229 /* C-r */       NONE,
230 /* C-s */       NONE,
231 /* C-t */       NONE,
232 /* C-u */       CANNA_FN_ToUpper,
233 /* C-v */       NONE,
234 /* C-w */       CANNA_FN_KouhoIchiran,
235 /* C-x */       NONE,
236 /* C-y */       CANNA_FN_ConvertAsHex,
237 /* C-z */       NONE,
238 /* C-[ */       NONE,
239 /* C-\ */       NONE,
240 /* C-] */       NONE,
241 /* C-^ */       NONE,
242 /* C-_ */       NONE,
243 /* space */     CANNA_FN_Henkan,
244 /* ! */         CANNA_FN_FunctionalInsert,
245 /* " */         CANNA_FN_FunctionalInsert,
246 /* # */         CANNA_FN_FunctionalInsert,
247 /* $ */         CANNA_FN_FunctionalInsert,
248 /* % */         CANNA_FN_FunctionalInsert,
249 /* & */         CANNA_FN_FunctionalInsert,
250 /* ' */         CANNA_FN_FunctionalInsert,
251 /* ( */         CANNA_FN_FunctionalInsert,
252 /* ) */         CANNA_FN_FunctionalInsert,
253 /* * */         CANNA_FN_FunctionalInsert,
254 /* + */         CANNA_FN_FunctionalInsert,
255 /* , */         CANNA_FN_FunctionalInsert,
256 /* - */         CANNA_FN_FunctionalInsert,
257 /* . */         CANNA_FN_FunctionalInsert,
258 /* / */         CANNA_FN_FunctionalInsert,
259 /* 0 */         CANNA_FN_FunctionalInsert,
260 /* 1 */         CANNA_FN_FunctionalInsert,
261 /* 2 */         CANNA_FN_FunctionalInsert,
262 /* 3 */         CANNA_FN_FunctionalInsert,
263 /* 4 */         CANNA_FN_FunctionalInsert,
264 /* 5 */         CANNA_FN_FunctionalInsert,
265 /* 6 */         CANNA_FN_FunctionalInsert,
266 /* 7 */         CANNA_FN_FunctionalInsert,
267 /* 8 */         CANNA_FN_FunctionalInsert,
268 /* 9 */         CANNA_FN_FunctionalInsert,
269 /* : */         CANNA_FN_FunctionalInsert,
270 /* ; */         CANNA_FN_FunctionalInsert,
271 /* < */         CANNA_FN_FunctionalInsert,
272 /* = */         CANNA_FN_FunctionalInsert,
273 /* > */         CANNA_FN_FunctionalInsert,
274 /* ? */         CANNA_FN_FunctionalInsert,
275 /* @ */         CANNA_FN_FunctionalInsert,
276 /* A */         CANNA_FN_FunctionalInsert,
277 /* B */         CANNA_FN_FunctionalInsert,
278 /* C */         CANNA_FN_FunctionalInsert,
279 /* D */         CANNA_FN_FunctionalInsert,
280 /* E */         CANNA_FN_FunctionalInsert,
281 /* F */         CANNA_FN_FunctionalInsert,
282 /* G */         CANNA_FN_FunctionalInsert,
283 /* H */         CANNA_FN_FunctionalInsert,
284 /* I */         CANNA_FN_FunctionalInsert,
285 /* J */         CANNA_FN_FunctionalInsert,
286 /* K */         CANNA_FN_FunctionalInsert,
287 /* L */         CANNA_FN_FunctionalInsert,
288 /* M */         CANNA_FN_FunctionalInsert,
289 /* N */         CANNA_FN_FunctionalInsert,
290 /* O */         CANNA_FN_FunctionalInsert,
291 /* P */         CANNA_FN_FunctionalInsert,
292 /* Q */         CANNA_FN_FunctionalInsert,
293 /* R */         CANNA_FN_FunctionalInsert,
294 /* S */         CANNA_FN_FunctionalInsert,
295 /* T */         CANNA_FN_FunctionalInsert,
296 /* U */         CANNA_FN_FunctionalInsert,
297 /* V */         CANNA_FN_FunctionalInsert,
298 /* W */         CANNA_FN_FunctionalInsert,
299 /* X */         CANNA_FN_FunctionalInsert,
300 /* Y */         CANNA_FN_FunctionalInsert,
301 /* Z */         CANNA_FN_FunctionalInsert,
302 /* [ */         CANNA_FN_FunctionalInsert,
303 /* \ */         CANNA_FN_FunctionalInsert,
304 /* ] */         CANNA_FN_FunctionalInsert,
305 /* ^ */         CANNA_FN_FunctionalInsert,
306 /* _ */         CANNA_FN_FunctionalInsert,
307 /* ` */         CANNA_FN_FunctionalInsert,
308 /* a */         CANNA_FN_FunctionalInsert,
309 /* b */         CANNA_FN_FunctionalInsert,
310 /* c */         CANNA_FN_FunctionalInsert,
311 /* d */         CANNA_FN_FunctionalInsert,
312 /* e */         CANNA_FN_FunctionalInsert,
313 /* f */         CANNA_FN_FunctionalInsert,
314 /* g */         CANNA_FN_FunctionalInsert,
315 /* h */         CANNA_FN_FunctionalInsert,
316 /* i */         CANNA_FN_FunctionalInsert,
317 /* j */         CANNA_FN_FunctionalInsert,
318 /* k */         CANNA_FN_FunctionalInsert,
319 /* l */         CANNA_FN_FunctionalInsert,
320 /* m */         CANNA_FN_FunctionalInsert,
321 /* n */         CANNA_FN_FunctionalInsert,
322 /* o */         CANNA_FN_FunctionalInsert,
323 /* p */         CANNA_FN_FunctionalInsert,
324 /* q */         CANNA_FN_FunctionalInsert,
325 /* r */         CANNA_FN_FunctionalInsert,
326 /* s */         CANNA_FN_FunctionalInsert,
327 /* t */         CANNA_FN_FunctionalInsert,
328 /* u */         CANNA_FN_FunctionalInsert,
329 /* v */         CANNA_FN_FunctionalInsert,
330 /* w */         CANNA_FN_FunctionalInsert,
331 /* x */         CANNA_FN_FunctionalInsert,
332 /* y */         CANNA_FN_FunctionalInsert,
333 /* z */         CANNA_FN_FunctionalInsert,
334 /* { */         CANNA_FN_FunctionalInsert,
335 /* | */         CANNA_FN_FunctionalInsert,
336 /* } */         CANNA_FN_FunctionalInsert,
337 /* ~ */         CANNA_FN_FunctionalInsert,
338 /* DEL */       NONE,
339 /* Nfer */      CANNA_FN_Kakutei,
340 /* Xfer */      CANNA_FN_Henkan,
341 /* Up */        CANNA_FN_Prev,
342 /* Left */      CANNA_FN_Backward,
343 /* Right */     CANNA_FN_Forward,
344 /* Down */      CANNA_FN_Next,
345 /* Insert */    CANNA_FN_KigouMode,
346 /* Rollup */    CANNA_FN_PageDown,
347 /* Rolldown */  CANNA_FN_PageUp,
348 /* Home */      CANNA_FN_BeginningOfLine,
349 /* Help */      CANNA_FN_EndOfLine,
350 /* KeyPad */	NONE,
351 /* End */       CANNA_FN_EndOfLine,
352 /* 8d */        NONE,
353 /* 8e */        NONE,
354 /* 8f */        NONE,
355 /* S-nfer */    NONE,
356 /* S-xfer */    CANNA_FN_Prev,
357 /* S-up */      NONE,
358 /* S-left */    CANNA_FN_Shrink,
359 /* S-right */   CANNA_FN_Extend,
360 /* S-down */    NONE,
361 /* C-nfer */    NONE,
362 /* C-xfer */    NONE,
363 /* C-up */      NONE,
364 /* C-left */    CANNA_FN_Shrink,
365 /* C-right */   CANNA_FN_Extend,
366 /* C-down */    NONE,
367 /* KP-, */      NONE,
368 /* KP-. */      NONE,
369 /* KP-/ */      NONE,
370 /* KP-- */      NONE,
371 /* S-space */   NONE,
372 /* �� */        CANNA_FN_FunctionalInsert,
373 /* �� */        CANNA_FN_FunctionalInsert,
374 /* �� */        CANNA_FN_FunctionalInsert,
375 /* �� */        CANNA_FN_FunctionalInsert,
376 /* �� */        CANNA_FN_FunctionalInsert,
377 /* �� */        CANNA_FN_FunctionalInsert,
378 /* �� */        CANNA_FN_FunctionalInsert,
379 /* �� */        CANNA_FN_FunctionalInsert,
380 /* �� */        CANNA_FN_FunctionalInsert,
381 /* �� */        CANNA_FN_FunctionalInsert,
382 /* �� */        CANNA_FN_FunctionalInsert,
383 /* �� */        CANNA_FN_FunctionalInsert,
384 /* �� */        CANNA_FN_FunctionalInsert,
385 /* �� */        CANNA_FN_FunctionalInsert,
386 /* �� */        CANNA_FN_FunctionalInsert,
387 /* �� */        CANNA_FN_FunctionalInsert,
388 /* �� */        CANNA_FN_FunctionalInsert,
389 /* �� */        CANNA_FN_FunctionalInsert,
390 /* �� */        CANNA_FN_FunctionalInsert,
391 /* �� */        CANNA_FN_FunctionalInsert,
392 /* �� */        CANNA_FN_FunctionalInsert,
393 /* �� */        CANNA_FN_FunctionalInsert,
394 /* �� */        CANNA_FN_FunctionalInsert,
395 /* �� */        CANNA_FN_FunctionalInsert,
396 /* �� */        CANNA_FN_FunctionalInsert,
397 /* �� */        CANNA_FN_FunctionalInsert,
398 /* �� */        CANNA_FN_FunctionalInsert,
399 /* �� */        CANNA_FN_FunctionalInsert,
400 /* �� */        CANNA_FN_FunctionalInsert,
401 /* �� */        CANNA_FN_FunctionalInsert,
402 /* �� */        CANNA_FN_FunctionalInsert,
403 /* �� */        CANNA_FN_FunctionalInsert,
404 /* �� */        CANNA_FN_FunctionalInsert,
405 /* �� */        CANNA_FN_FunctionalInsert,
406 /* �� */        CANNA_FN_FunctionalInsert,
407 /* �� */        CANNA_FN_FunctionalInsert,
408 /* �� */        CANNA_FN_FunctionalInsert,
409 /* �� */        CANNA_FN_FunctionalInsert,
410 /* �� */        CANNA_FN_FunctionalInsert,
411 /* �� */        CANNA_FN_FunctionalInsert,
412 /* �� */        CANNA_FN_FunctionalInsert,
413 /* �� */        CANNA_FN_FunctionalInsert,
414 /* �� */        CANNA_FN_FunctionalInsert,
415 /* �� */        CANNA_FN_FunctionalInsert,
416 /* �� */        CANNA_FN_FunctionalInsert,
417 /* �� */        CANNA_FN_FunctionalInsert,
418 /* �� */        CANNA_FN_FunctionalInsert,
419 /* �� */        CANNA_FN_FunctionalInsert,
420 /* �� */        CANNA_FN_FunctionalInsert,
421 /* �� */        CANNA_FN_FunctionalInsert,
422 /* �� */        CANNA_FN_FunctionalInsert,
423 /* �� */        CANNA_FN_FunctionalInsert,
424 /* �� */        CANNA_FN_FunctionalInsert,
425 /* �� */        CANNA_FN_FunctionalInsert,
426 /* �� */        CANNA_FN_FunctionalInsert,
427 /* �� */        CANNA_FN_FunctionalInsert,
428 /* �� */        CANNA_FN_FunctionalInsert,
429 /* �� */        CANNA_FN_FunctionalInsert,
430 /* �� */        CANNA_FN_FunctionalInsert,
431 /* �� */        CANNA_FN_FunctionalInsert,
432 /* �� */        CANNA_FN_FunctionalInsert,
433 /* �� */        CANNA_FN_FunctionalInsert,
434 /* �� */        CANNA_FN_FunctionalInsert,
435 /* F1 */        NONE,
436 /* F2 */        NONE,
437 /* F3 */        NONE,
438 /* F4 */        NONE,
439 /* F5 */        NONE,
440 /* F6 */        NONE,
441 /* F7 */        NONE,
442 /* F8 */        NONE,
443 /* F9 */        NONE,
444 /* F10 */       NONE,
445 /* ea */        NONE,
446 /* eb */        NONE,
447 /* ec */        NONE,
448 /* ed */        NONE,
449 /* ee */        NONE,
450 /* ef */        NONE,
451 /* PF1 */       NONE,
452 /* PF2 */       NONE,
453 /* PF3 */       NONE,
454 /* PF4 */       NONE,
455 /* PF5 */       NONE,
456 /* PF6 */       NONE,
457 /* PF7 */       NONE,
458 /* PF8 */       NONE,
459 /* PF9 */       NONE,
460 /* PF10 */      NONE,
461 /* HIRAGANA */  CANNA_FN_BaseHiragana,
462 /* KATAKANA */  CANNA_FN_BaseKatakana,
463 /* HAN-ZEN */   CANNA_FN_BaseZenHanToggle,
464 /* EISU */      CANNA_FN_BaseEisu,
465 /* fe */        NONE,
466 /* ff */        NONE,
467 };
468