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: defaultmap.c 14875 2005-11-12 21:25:31Z bonefish $";
25#endif	/* lint */
26
27#include "canna.h"
28#include <canna/mfdef.h>
29
30extern int howToBehaveInCaseOfUndefKey;
31
32#define DEFAULTBEHAVIOR 0
33
34static int
35(*getfunc(
36struct funccfunc *tbl,
37unsigned char f))(...)
38{
39  struct funccfunc *p;
40
41  for (p = tbl ; p->funcid || p->cfunc ; p++) {
42    if (p->funcid == (unsigned char)f) {
43      return (int (*)(...))p->cfunc;
44    }
45  }
46  return (int (*)(...))0;
47}
48
49static int
50simpleUndefBehavior(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
85int
86searchfunc(uiContext d, KanjiMode mode, int whattodo, int key, int fnum)
87{
88  int (*func)(...);
89
90  if (fnum == 0) {
91    fnum = mode->keytbl[key];
92  }
93  switch (whattodo) {
94  case KEY_CALL:
95    /* ¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¥â¡¼¥É¤¬ strokelimit ¥¹¥È¥í¡¼¥¯°Ê¾å³¤¤¤¿¤é
96       ¥µ¡¼¥Ð¤È¤ÎÀܳ¤òÀÚ¤ë */
97    if (cannaconf.strokelimit > 0) {
98      extern KanjiModeRec alpha_mode;
99      if (mode == &alpha_mode) {
100	d->strokecounter++;
101#ifdef DEBUG
102	if (iroha_debug) {
103	  fprintf(stderr, "d->strokecounter=%d\n", d->strokecounter);
104	}
105#endif
106	if (d->strokecounter == cannaconf.strokelimit + 1) {
107	  jrKanjiPipeError();
108	}
109      }else{
110	d->strokecounter = 0;
111#ifdef DEBUG
112	if (iroha_debug) {
113	  fprintf(stderr, "d->strokecounter=%d\n", d->strokecounter);
114	}
115#endif
116      }
117    }
118    /* ¤¤¤è¤¤¤èËܳÊŪ¤Ê½èÍý(¤³¤³¤Þ¤Ç¤ÏÁ°½èÍý) */
119    if (fnum < CANNA_FN_MAX_FUNC) {
120      func = getfunc(mode->ftbl, fnum);
121      if (func) {
122	return (*func)(d);
123      }
124    }
125    else {
126      func = getfunc(mode->ftbl, CANNA_FN_UserMode);
127      if (func) {
128	/* func ¤Î¥¿¥¤¥×¤¬¾å¤È°ã¤Ã¤Æ¤Æ±ø¤¤¤Ê¤¢... */
129	return (*func)(d, fnum);
130      }
131    }
132    /* ¤½¤Î¥â¡¼¥É¤Ç fnum ¤ËÂбþ¤¹¤ëµ¡Ç½¤¬¤Ê¤¤¡£¤·¤«¤¿¤¬¤Ê¤¤¤Î¤Ç¡¢
133       ¥Ç¥Õ¥©¥ë¥Èµ¡Ç½¤òõ¤¹ */
134    func = getfunc(mode->ftbl, DEFAULTBEHAVIOR);
135    if (func) {
136      return (*func)(d);
137    }
138    else {
139      return simpleUndefBehavior(d);
140    }
141    /* NOTREACHED */
142    break;
143  case KEY_CHECK:
144    if (fnum >= CANNA_FN_MAX_FUNC) {
145      fnum = CANNA_FN_UserMode;
146    }
147    return getfunc(mode->ftbl, fnum) ? 1 : 0;
148    /* NOTREACHED */
149    break;
150  case KEY_SET: /* is not supported yet */
151    return 0;
152    /* NOTREACHED */
153    break;
154  }
155  /* NOTREACHED */
156}
157
158/* Ã༡Æɤߥ⡼¥ÉÍÑ */
159
160int
161CYsearchfunc(uiContext d, KanjiMode mode, int whattodo, int key, int fnum)
162{
163  int (*func)(...);
164  extern KanjiModeRec yomi_mode;
165
166  if (fnum == 0) {
167    fnum = mode->keytbl[key];
168  }
169  if (Yomisearchfunc(d, mode, KEY_CHECK, key, fnum)) {
170    return Yomisearchfunc(d, mode, whattodo, key, fnum);
171  }
172  else {
173    func = getfunc(yomi_mode.ftbl, fnum);
174    switch (whattodo) {
175    case KEY_CALL:
176      if (func) {
177	return (*func)(d);
178      }else{
179	return Yomisearchfunc(d, mode, whattodo, key, fnum);
180      }
181      /* NOTREACHED */
182      break;
183    case KEY_CHECK:
184      return func ? 1 : 0;
185      /* NOTREACHED */
186      break;
187    case KEY_SET:
188      return 0;
189      /* NOTREACHED */
190      break;
191    }
192  }
193  /* may be NOTREACHED */
194  return 0;
195}
196
197#define NONE CANNA_FN_Undefined
198
199BYTE default_kmap[256] =
200{
201/* C-@ */       CANNA_FN_Mark,
202/* C-a */       CANNA_FN_BeginningOfLine,
203/* C-b */       CANNA_FN_Backward,
204/* C-c */       CANNA_FN_BubunMuhenkan,
205/* C-d */       CANNA_FN_DeleteNext,
206/* C-e */       CANNA_FN_EndOfLine,
207/* C-f */       CANNA_FN_Forward,
208/* C-g */       CANNA_FN_Quit,
209/* C-h */       CANNA_FN_DeletePrevious,
210/* C-i */       CANNA_FN_Shrink,
211/* C-j */       CANNA_FN_BubunKakutei,
212/* C-k */       CANNA_FN_KillToEndOfLine,
213/* C-l */       CANNA_FN_ToLower,
214/* C-m */       CANNA_FN_Kakutei,
215/* C-n */       CANNA_FN_Next,
216/* C-o */       CANNA_FN_Extend,
217/* C-p */       CANNA_FN_Prev,
218/* C-q */       CANNA_FN_QuotedInsert,
219/* C-r */       NONE,
220/* C-s */       NONE,
221/* C-t */       NONE,
222/* C-u */       CANNA_FN_ToUpper,
223/* C-v */       NONE,
224/* C-w */       CANNA_FN_KouhoIchiran,
225/* C-x */       NONE,
226/* C-y */       CANNA_FN_ConvertAsHex,
227/* C-z */       NONE,
228#ifdef WIN
229/* C-[ */       CANNA_FN_Quit,
230#else
231/* C-[ */       NONE,
232#endif
233/* C-\ */       NONE,
234/* C-] */       NONE,
235/* C-^ */       NONE,
236/* C-_ */       NONE,
237/* space */     CANNA_FN_Henkan,
238/* ! */         CANNA_FN_FunctionalInsert,
239/* " */         CANNA_FN_FunctionalInsert,
240/* # */         CANNA_FN_FunctionalInsert,
241/* $ */         CANNA_FN_FunctionalInsert,
242/* % */         CANNA_FN_FunctionalInsert,
243/* & */         CANNA_FN_FunctionalInsert,
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/* 0 */         CANNA_FN_FunctionalInsert,
254/* 1 */         CANNA_FN_FunctionalInsert,
255/* 2 */         CANNA_FN_FunctionalInsert,
256/* 3 */         CANNA_FN_FunctionalInsert,
257/* 4 */         CANNA_FN_FunctionalInsert,
258/* 5 */         CANNA_FN_FunctionalInsert,
259/* 6 */         CANNA_FN_FunctionalInsert,
260/* 7 */         CANNA_FN_FunctionalInsert,
261/* 8 */         CANNA_FN_FunctionalInsert,
262/* 9 */         CANNA_FN_FunctionalInsert,
263/* : */         CANNA_FN_FunctionalInsert,
264/* ; */         CANNA_FN_FunctionalInsert,
265/* < */         CANNA_FN_FunctionalInsert,
266/* = */         CANNA_FN_FunctionalInsert,
267/* > */         CANNA_FN_FunctionalInsert,
268/* ? */         CANNA_FN_FunctionalInsert,
269/* @ */         CANNA_FN_FunctionalInsert,
270/* A */         CANNA_FN_FunctionalInsert,
271/* B */         CANNA_FN_FunctionalInsert,
272/* C */         CANNA_FN_FunctionalInsert,
273/* D */         CANNA_FN_FunctionalInsert,
274/* E */         CANNA_FN_FunctionalInsert,
275/* F */         CANNA_FN_FunctionalInsert,
276/* G */         CANNA_FN_FunctionalInsert,
277/* H */         CANNA_FN_FunctionalInsert,
278/* I */         CANNA_FN_FunctionalInsert,
279/* J */         CANNA_FN_FunctionalInsert,
280/* K */         CANNA_FN_FunctionalInsert,
281/* L */         CANNA_FN_FunctionalInsert,
282/* M */         CANNA_FN_FunctionalInsert,
283/* N */         CANNA_FN_FunctionalInsert,
284/* O */         CANNA_FN_FunctionalInsert,
285/* P */         CANNA_FN_FunctionalInsert,
286/* Q */         CANNA_FN_FunctionalInsert,
287/* R */         CANNA_FN_FunctionalInsert,
288/* S */         CANNA_FN_FunctionalInsert,
289/* T */         CANNA_FN_FunctionalInsert,
290/* U */         CANNA_FN_FunctionalInsert,
291/* V */         CANNA_FN_FunctionalInsert,
292/* W */         CANNA_FN_FunctionalInsert,
293/* X */         CANNA_FN_FunctionalInsert,
294/* Y */         CANNA_FN_FunctionalInsert,
295/* Z */         CANNA_FN_FunctionalInsert,
296/* [ */         CANNA_FN_FunctionalInsert,
297/* \ */         CANNA_FN_FunctionalInsert,
298/* ] */         CANNA_FN_FunctionalInsert,
299/* ^ */         CANNA_FN_FunctionalInsert,
300/* _ */         CANNA_FN_FunctionalInsert,
301/* ` */         CANNA_FN_FunctionalInsert,
302/* a */         CANNA_FN_FunctionalInsert,
303/* b */         CANNA_FN_FunctionalInsert,
304/* c */         CANNA_FN_FunctionalInsert,
305/* d */         CANNA_FN_FunctionalInsert,
306/* e */         CANNA_FN_FunctionalInsert,
307/* f */         CANNA_FN_FunctionalInsert,
308/* g */         CANNA_FN_FunctionalInsert,
309/* h */         CANNA_FN_FunctionalInsert,
310/* i */         CANNA_FN_FunctionalInsert,
311/* j */         CANNA_FN_FunctionalInsert,
312/* k */         CANNA_FN_FunctionalInsert,
313/* l */         CANNA_FN_FunctionalInsert,
314/* m */         CANNA_FN_FunctionalInsert,
315/* n */         CANNA_FN_FunctionalInsert,
316/* o */         CANNA_FN_FunctionalInsert,
317/* p */         CANNA_FN_FunctionalInsert,
318/* q */         CANNA_FN_FunctionalInsert,
319/* r */         CANNA_FN_FunctionalInsert,
320/* s */         CANNA_FN_FunctionalInsert,
321/* t */         CANNA_FN_FunctionalInsert,
322/* u */         CANNA_FN_FunctionalInsert,
323/* v */         CANNA_FN_FunctionalInsert,
324/* w */         CANNA_FN_FunctionalInsert,
325/* x */         CANNA_FN_FunctionalInsert,
326/* y */         CANNA_FN_FunctionalInsert,
327/* z */         CANNA_FN_FunctionalInsert,
328/* { */         CANNA_FN_FunctionalInsert,
329/* | */         CANNA_FN_FunctionalInsert,
330/* } */         CANNA_FN_FunctionalInsert,
331/* ~ */         CANNA_FN_FunctionalInsert,
332/* DEL */       NONE,
333#ifdef WIN
334/* Nfer */      CANNA_FN_KanaRotate,
335#else
336/* Nfer */      CANNA_FN_Kakutei,
337#endif
338/* Xfer */      CANNA_FN_Henkan,
339/* Up */        CANNA_FN_Prev,
340/* Left */      CANNA_FN_Backward,
341/* Right */     CANNA_FN_Forward,
342/* Down */      CANNA_FN_Next,
343#ifdef WIN
344/* Insert */    NONE,
345#else
346/* Insert */    CANNA_FN_KigouMode,
347#endif
348/* Rollup */    CANNA_FN_PageDown,
349/* Rolldown */  CANNA_FN_PageUp,
350/* Home */      CANNA_FN_BeginningOfLine,
351/* Help */      CANNA_FN_EndOfLine,
352/* KeyPad */	NONE,
353/* End */       CANNA_FN_EndOfLine,
354/* 8d */        NONE,
355/* 8e */        NONE,
356/* 8f */        NONE,
357#ifdef WIN
358/* S-nfer */    CANNA_FN_RomajiRotate,
359#else
360/* S-nfer */    NONE,
361#endif
362/* S-xfer */    CANNA_FN_Prev,
363/* S-up */      NONE,
364/* S-left */    CANNA_FN_Shrink,
365/* S-right */   CANNA_FN_Extend,
366/* S-down */    NONE,
367/* C-nfer */    NONE,
368/* C-xfer */    NONE,
369/* C-up */      NONE,
370/* C-left */    CANNA_FN_Shrink,
371/* C-right */   CANNA_FN_Extend,
372/* C-down */    NONE,
373/* KP-, */      NONE,
374/* KP-. */      NONE,
375/* KP-/ */      NONE,
376/* KP-- */      NONE,
377/* S-space */   NONE,
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/* ¥ì */        CANNA_FN_FunctionalInsert,
436/* ¥í */        CANNA_FN_FunctionalInsert,
437/* ¥ï */        CANNA_FN_FunctionalInsert,
438/* ¥ó */        CANNA_FN_FunctionalInsert,
439/* ¡« */        CANNA_FN_FunctionalInsert,
440/* ¡¬ */        CANNA_FN_FunctionalInsert,
441/* F1 */        NONE,
442/* F2 */        NONE,
443/* F3 */        NONE,
444/* F4 */        NONE,
445/* F5 */        NONE,
446/* F6 */        NONE,
447/* F7 */        NONE,
448/* F8 */        NONE,
449/* F9 */        NONE,
450/* F10 */       NONE,
451/* ea */        NONE,
452/* eb */        NONE,
453/* ec */        NONE,
454/* ed */        NONE,
455/* ee */        NONE,
456/* ef */        NONE,
457/* PF1 */       NONE,
458/* PF2 */       NONE,
459/* PF3 */       NONE,
460/* PF4 */       NONE,
461/* PF5 */       NONE,
462/* PF6 */       NONE,
463/* PF7 */       NONE,
464/* PF8 */       NONE,
465/* PF9 */       NONE,
466/* PF10 */      NONE,
467/* HIRAGANA */  CANNA_FN_BaseHiragana,
468/* KATAKANA */  CANNA_FN_BaseKatakana,
469/* HAN-ZEN */   CANNA_FN_BaseZenHanToggle,
470/* EISU */      CANNA_FN_BaseEisu,
471/* fe */        NONE,
472/* ff */        NONE,
473};
474