1 /* $Id: ttykbd.c,v 1.1.1.1 2000/06/27 01:48:01 amura Exp $ */
2 /*
3 * Name: MG 2a
4 * Amiga virtual terminal keyboard, default console keymap.
5 * Created: Mic Kaczmarczik (mic@emx.cc.utexas.edu)
6 * Last edit: May 14, 1988
7 */
8
9 /*
10 * $Log: ttykbd.c,v $
11 * Revision 1.1.1.1 2000/06/27 01:48:01 amura
12 * import to CVS
13 *
14 */
15
16 #undef TRUE
17 #undef FALSE
18 #include "config.h" /* Dec. 15, 1992 by H.Ohkubo */
19 #include "def.h"
20 #include "kbd.h"
21
22 /*
23 * List of function key names, from KFIRST to KLAST
24 */
25 #ifdef FKEYS
26 char *keystrings[] = {
27 "Up", "Down", "Left", "Right",
28 "Shift-Up", "Shift-Down", "Shift-Left", "Shift-Right",
29 "Help", "The menu", "The resize gadget", "The mouse",
30 "F1", "F2", "F3", "F4",
31 "F5", "F6", "F7", "F8",
32 "F9", "F10", "Shift-F1", "Shift-F2",
33 "Shift-F3", "Shift-F4", "Shift-F5", "Shift-F6",
34 "Shift-F7", "Shift-F8", "Shift-F9", "Shift-F10",
35 "Mouse", "Ctrl-Mouse",
36 "Shift-Mouse", "Shift-Ctrl-Mouse",
37 "Meta-Mouse", "Meta-Ctrl-Mouse",
38 "Meta-Shift-Mouse", "Meta-Shift-Ctrl-Mouse",
39 "Mode-Mouse", "Ctrl-Mode-Mouse",
40 "Shift-Mode-Mouse", "Shift-Ctrl-Mode-Mouse",
41 "Meta-Mode-Mouse", "Meta-Ctrl-Mode-Mouse",
42 "Meta-Shift-Mode-Mouse", "Meta-Shift-Ctrl-Mode-Mouse",
43 "Echo-Mouse", "Ctrl-Echo-Mouse",
44 "Shift-Echo-Mouse", "Shift-Ctrl-Echo-Mouse",
45 "Meta-Echo-Mouse", "Meta-Ctrl-Echo-Mouse",
46 "Meta-Shift-Echo-Mouse", "Meta-Shift-Ctrl-Echo-Mouse"
47 };
48 #endif
49
50 /*
51 * Read in a key, doing whatever low-level mapping of ASCII code to
52 * 11 bit code. This has become a bit easier since keymaps.
53 */
54 #define CSI 0x9b
55
getkbd()56 getkbd()
57 {
58 register int c;
59 #ifdef FKEYS
60 register int n;
61 #endif
62 loop:
63 if ((c = ttgetc()) == CSI) {
64 c = ttgetc();
65 #ifdef FKEYS
66 if (c == '?') { /* HELP key */
67 ttgetc(); /* discard '~' */
68 return (KHELP);
69 }
70 /* Arrow keys */
71 if (c == 'A')
72 return (KUP);
73 if (c == 'B')
74 return (KDOWN);
75 if (c == 'C')
76 return (KRIGHT);
77 if (c == 'D')
78 return (KLEFT);
79 if (c == 'T')
80 return (KSUP);
81 if (c == 'S')
82 return (KSDOWN);
83
84 /* Shifted left, right arrow */
85 if (c == ' ') {
86 c = ttgetc();
87 if (c == 'A' || c == '@')
88 return ((c == 'A') ? (KSLEFT) : (KSRIGHT));
89 goto loop; /* try again, sucker */
90 }
91
92 /* Function keys */
93 if (c >= '0' && c <= '9') {
94 n = 0;
95 do {
96 n = 10*n + c - '0';
97 c = ttgetc();
98 } while (c>='0' && c<='9');
99 if (c == '~' && n < 20)
100 return (n < 9) ? (KF1 + n) : (KSF1 + (n - 10));
101 else
102 goto loop; /* Try again */
103 }
104 #endif
105 goto loop; /* Try again */
106 }
107 return (c);
108 }
109
110 /*
111 * Terminal specific keymap initialization, calling bind() to get
112 * things done. All the keys bound here are done globally.
113 */
114 /*ARGSUSED*/
115 VOID
116 #ifdef ADDOPT
ttykeymapinit(ngrcfile)117 ttykeymapinit(ngrcfile)
118 char *ngrcfile;
119 #else
120 ttykeymapinit()
121 #endif
122 {
123 #ifndef BUGFIX /* Dec.19,1992 by H.Ohkubo */
124 #ifdef FKEYS
125 KCHAR c;
126 register KEYMAP **mapp = &map_table[0].p_map;
127 #endif
128 static KCHAR esc_bs[] = { CCHR('['), CCHR('H') };
129 static KCHAR esc_del[] = { CCHR('['), CCHR('?') };
130
131 #define BINDC(k,s) (c = k, bindkey(mapp, s, &c, 1))
132 #define BINDM(m,s) bindkey(mapp, s, m, (sizeof(m)/sizeof(KCHAR)))
133
134 /* Swap the backspace and del keys, at least in normal usage.
135 * This loses the help feature of CTRL-H, but we rebind
136 * CTRL-_ to do the same thing. Under FKEYS, the Help key
137 * calls describe-key-briefly.
138 */
139 BINDC(CCHR('_'), "help-help"); /* CTRL-Backspace */
140 BINDM(esc_bs, "backward-kill-word");
141 BINDC(CCHR('H'), "delete-backward-char");
142
143 BINDC(CCHR('?'), "delete-char");
144 BINDM(esc_del, "kill-word");
145 #endif /* BUGFIX */
146 }
147
148