]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/sys/i386/isa/pcvt/pcvt_kbd.h
merge fix for boot-time hang on centos' xen
[FreeBSD/FreeBSD.git] / 6 / sys / i386 / isa / pcvt / pcvt_kbd.h
1 /*-
2  * Copyright (c) 1999, 2000 Hellmuth Michaelis
3  *
4  * Copyright (c) 1992, 1995 Hellmuth Michaelis and Joerg Wunsch.
5  *
6  * Copyright (c) 1992, 1993 Brian Dunford-Shore and Holger Veit.
7  *
8  * All rights reserved.
9  *
10  * This code is derived from software contributed to Berkeley by
11  * William Jolitz and Don Ahn.
12  *
13  * This code is derived from software contributed to 386BSD by
14  * Holger Veit.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  * 3. All advertising materials mentioning features or use of this software
25  *    must display the following acknowledgement:
26  *      This product includes software developed by Hellmuth Michaelis,
27  *      Brian Dunford-Shore and Joerg Wunsch.
28  * 4. The name authors may not be used to endorse or promote products
29  *    derived from this software without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
32  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  */
42
43 /*---------------------------------------------------------------------------*
44  *
45  *      pcvt_kbd.h      VT220 Driver Keyboard Interface Header
46  *      ------------------------------------------------------
47  *
48  *      Last Edit-Date: [Sun Mar 26 10:38:38 2000]
49  *
50  * $FreeBSD$
51  *
52  *---------------------------------------------------------------------------*/
53
54 /*---------------------------------------------------------------------------*
55  *      this is one sub-entry for the table. the type can be either
56  *      "pointer to a string" or "pointer to a function"
57  *---------------------------------------------------------------------------*/
58 typedef struct
59 {
60         u_char subtype;                 /* subtype, string or function */
61         union what
62         {
63                 u_char *string;         /* ptr to string, null terminated */
64                 void (*func)(void);     /* ptr to function */
65         } what;
66 } entry;
67
68 /*---------------------------------------------------------------------------*
69  *      this is the "outer" table
70  *---------------------------------------------------------------------------*/
71 typedef struct
72 {
73         u_short type;                   /* type of key */
74         u_short ovlindex;               /* -hv- index into overload table */
75         entry   unshift;                /* normal default codes/funcs */
76         entry   shift;                  /* shifted default codes/funcs */
77         entry   ctrl;                   /* control default codes/funcs */
78 } Keycap_def;
79
80 #define IDX0            0       /* default indexvalue into ovl table */
81
82 #define STR             KBD_SUBT_STR    /* subtype = ptr to string */
83 #define FNC             KBD_SUBT_FNC    /* subtype = ptr to function */
84
85 #define CODE_SIZE       5
86
87 /*---------------------------------------------------------------------------*
88  * the overlaytable table is a static fixed size scratchpad where all the
89  * overloaded definitions are stored.
90  * an entry consists of a short (holding the new type attribute) and
91  * four entries for a new keydefinition.
92  *---------------------------------------------------------------------------*/
93
94 #define OVLTBL_SIZE     64              /* 64 keys can be overloaded */
95
96 #define Ovl_tbl struct kbd_ovlkey
97
98 static Ovl_tbl *ovltbl;                 /* the table itself */
99
100 static int ovlinitflag = 0;             /* the init flag for the table */
101
102 /*
103  * key codes >= 128 denote "virtual" shift/control
104  * They are resolved before any keymapping is handled
105  */
106
107 #if PCVT_SCANSET == 2
108 static u_char scantokey[] = {
109 /*      -0- -1- -2- -3- -4- -5- -6- -7-    This layout is valid for US only */
110 /*00*/   0,120,  0,116,114,112,113,123,  /* ??  F9  ??  F5  F3  F1  F2  F12 */
111 /*08*/   0,121,119,117,115, 16,  1,  0,  /* ??  F10 F8  F6  F4  TAB `   ??  */
112 /*10*/   0, 60, 44,  0, 58, 17,  2,  0,  /* ??  ALl SHl ??  CTl Q   1   ??  */
113 /*18*/   0,  0, 46, 32, 31, 18,  3,  0,  /* ??  Z   S   A   W   2   ??  ??  */
114 /*20*/   0, 48, 47, 33, 19,  5,  4,  0,  /* ??  C   X   D   E   4   3   ??  */
115 /*28*/   0, 61, 49, 34, 21, 20,  6,  0,  /* ??  SP  V   F   T   R   5   ??  */
116 /*30*/   0, 51, 50, 36, 35, 22,  7,  0,  /* ??  N   B   H   G   Y   6   ??  */
117 /*38*/   0,  0, 52, 37, 23,  8,  9,  0,  /* ??  ??  M   J   U   7   8   ??  */
118 /*40*/   0, 53, 38, 24, 25, 11, 10,  0,  /* ??  ,   K   I   O   0   9   ??  */
119 /*48*/   0, 54, 55, 39, 40, 26, 12,  0,  /* ??  .   /   L   ;   P   -   ??  */
120 /*50*/   0,  0, 41,  0, 27, 13,  0,  0,  /* ??  ??  "   ??  [   =   ??  ??  */
121 /*58*/  30, 57, 43, 28,  0, 29,  0,  0,  /* CAP SHr ENT ]   ??  \   ??  ??  */
122 /*60*/   0, 45,  0,  0,  0,  0, 15,  0,  /* ??  NL1 ??  ??  ??  ??  BS  ??  */
123 /*68*/   0, 93,  0, 92, 91,  0,  0,  0,  /* ??  KP1 ??  KP4 KP7 ??  ??  ??  */
124 /*70*/  99,104, 98, 97,102, 96,110, 90,  /* KP0 KP. KP2 KP5 KP6 KP8 ESC NUM */
125 /*78*/ 122,106,103,105,100,101,125,  0,  /* F11 KP+ KP3 KP- KP* KP9 LOC ??  */
126 /*80*/   0,  0,  0,118,127               /* ??  ??  ??  F7 SyRQ */
127 };
128
129 static u_char extscantokey[] = {
130 /*      -0- -1- -2- -3- -4- -5- -6- -7-    This layout is valid for US only */
131 /*00*/   0,120,  0,116,114,112,113,123,  /* ??  F9  ??  F5  F3  F1  F2  F12 */
132 /*08*/   0,121,119,117,115, 16,  1,  0,  /* ??  F10 F8  F6  F4  TAB `   ??  */
133 /*10*/   0, 62,128,  0, 64, 17,  2,  0,  /* ??  ALr vSh ??  CTr Q   1   ??  */
134 /*18*/   0,  0, 46, 32, 31, 18,  3,  0,  /* ??  Z   S   A   W   2   ??  ??  */
135 /*20*/   0, 48, 47, 33, 19,  5,  4,  0,  /* ??  C   X   D   E   4   3   ??  */
136 /*28*/   0, 61, 49, 34, 21, 20,  6,  0,  /* ??  SP  V   F   T   R   5   ??  */
137 /*30*/   0, 51, 50, 36, 35, 22,  7,  0,  /* ??  N   B   H   G   Y   6   ??  */
138 /*38*/   0,  0, 52, 37, 23,  8,  9,  0,  /* ??  ??  M   J   U   7   8   ??  */
139 /*40*/   0, 53, 38, 24, 25, 11, 10,  0,  /* ??  ,   K   I   O   0   9   ??  */
140 /*48*/   0, 54, 95, 39, 40, 26, 12,  0,  /* ??  .   KP/ L   ;   P   -   ??  */
141 /*50*/   0,  0, 41,  0, 27, 13,  0,  0,  /* ??  ??  "   ??  [   =   ??  ??  */
142 /*58*/  30, 57,108, 28,  0, 29,  0,  0,  /* CAP  SHr KPE ]   ??  \  ??  ??  */
143 /*60*/   0, 45,  0,  0,  0,  0, 15,  0,  /* ??  NL1 ??  ??  ??  ??  BS  ??  */
144 /*68*/   0, 81,  0, 79, 80,  0,  0,  0,  /* ??  END ??  LA  HOM ??  ??  ??  */
145 /*70*/  75, 76, 84, 97, 89, 83,110, 90,  /* INS DEL DA  KP5 RA  UA  ESC NUM */
146 /*78*/ 122,106, 86,105,124, 85,126,  0,  /* F11 KP+ PD  KP- PSc PU  Brk ??  */
147 /*80*/   0,  0,  0,118,127               /* ??  ??  ??  F7 SysRq */
148 };
149
150 #else   /* PCVT_SCANSET != 2 */
151
152 static u_char scantokey[] = {
153 /*       -0- -1- -2- -3- -4- -5- -6- -7-    This layout is valid for US only */
154 /*00*/    0,110,  2,  3,  4,  5,  6,  7,  /* ??  ESC 1   2   3   4   5   6   */
155 /*08*/    8,  9, 10, 11, 12, 13, 15, 16,  /* 7   8   9   0   -   =   BS  TAB */
156 /*10*/   17, 18, 19, 20, 21, 22, 23, 24,  /* Q   W   E   R   T   Y   U   I   */
157 /*18*/   25, 26, 27, 28, 43, 58, 31, 32,  /* O   P   [   ]   ENT CTl A   S   */
158 /*20*/   33, 34, 35, 36, 37, 38, 39, 40,  /* D   F   G   H   J   K   L   ;   */
159 /*28*/   41,  1, 44, 29, 46, 47, 48, 49,  /* '   `   SHl \   Z   X   C   V   */
160 /*30*/   50, 51, 52, 53, 54, 55, 57,100,  /* B   N   M   ,   .   /   SHr KP* */
161 /*38*/   60, 61, 30,112,113,114,115,116,  /* ALl SP  CAP F1  F2  F3  F4  F5  */
162 /*40*/  117,118,119,120,121, 90,125, 91,  /* F6  F7  F8  F9  F10 NUM LOC KP7 */
163 /*48*/   96,101,105, 92, 97,102,106, 93,  /* KP8 KP9 KP- KP4 KP5 KP6 KP+ KP1 */
164 /*50*/   98,103, 99,104,127,  0, 45,122,  /* KP2 KP3 KP0 KP. SyRq??  NL1 F11 */
165 /*58*/  123                               /* F12 */
166 };
167
168 static u_char extscantokey[] = {
169 /*       -0- -1- -2- -3- -4- -5- -6- -7-    This layout is valid for US only */
170 /*00*/    0,110,  2,  3,  4,  5,  6,  7,  /* ??  ESC 1   2   3   4   5   6   */
171 /*08*/    8,  9, 10, 11, 12, 13, 15, 16,  /* 7   8   9   0   -   =   BS  TAB */
172 /*10*/   17, 18, 19, 20, 21, 22, 23, 24,  /* Q   W   E   R   T   Y   U   I   */
173 /*18*/   25, 26, 27, 28,108, 64, 31, 32,  /* O   P   [   ]   KPE CTr A   S   */
174 /*20*/   33, 34, 35, 36, 37, 38, 39, 40,  /* D   F   G   H   J   K   L   ;   */
175 /*28*/   41,  1,128, 29, 46, 47, 48, 49,  /* '   `   vSh \   Z   X   C   V   */
176 /*30*/   50, 51, 52, 53, 54, 95, 57,124,  /* B   N   M   ,   .   KP/ SHr KP* */
177 /*38*/   62, 61, 30,112,113,114,115,116,  /* ALr SP  CAP F1  F2  F3  F4  F5  */
178 /*40*/  117,118,119,120,121, 90,126, 80,  /* F6  F7  F8  F9  F10 NUM Brk HOM */
179 /*48*/   83, 85,105, 79, 97, 89,106, 81,  /* UA  PU  KP- LA  KP5 RA  KP+ END */
180 /*50*/   84, 86, 75, 76,  0,  0, 45,122,  /* DA  PD  INS DEL ??  ??  NL1 F11 */
181 /*58*/  123,                              /* F12 */
182 };
183 #endif  /* PCVT_SCANSET == 2 */
184
185 static Keycap_def       key2ascii[] =
186 {
187 /* define some shorthands to make the table (almost) fit into 80 columns */
188 #define C (u_char *)
189 #define V (void *)
190 #define S STR
191 #define F FNC
192 #define I IDX0
193
194 /* DONT EVER OVERLOAD KEY 0, THIS IS A KEY THAT MUSTN'T EXIST */
195
196 /*      type   index   unshift        shift           ctrl         */
197 /*      ---------------------------------------------------------- */
198 /*  0*/ {KBD_NONE,  I, {S,{C "df"}},    {S,{C ""}},      {S,{C ""}}},
199 /*  1*/ {KBD_ASCII, I, {S,{C "`"}},     {S,{C "~"}},     {S,{C "`"}}},
200 /*  2*/ {KBD_ASCII, I, {S,{C "1"}},     {S,{C "!"}},     {S,{C "1"}}},
201 /*  3*/ {KBD_ASCII, I, {S,{C "2"}},     {S,{C "@"}},     {S,{C "\000"}}},
202 /*  4*/ {KBD_ASCII, I, {S,{C "3"}},     {S,{C "#"}},     {S,{C "3"}}},
203 /*  5*/ {KBD_ASCII, I, {S,{C "4"}},     {S,{C "$"}},     {S,{C "4"}}},
204 /*  6*/ {KBD_ASCII, I, {S,{C "5"}},     {S,{C "%"}},     {S,{C "5"}}},
205 /*  7*/ {KBD_ASCII, I, {S,{C "6"}},     {S,{C "^"}},     {S,{C "\036"}}},
206 /*  8*/ {KBD_ASCII, I, {S,{C "7"}},     {S,{C "&"}},     {S,{C "7"}}},
207 /*  9*/ {KBD_ASCII, I, {S,{C "8"}},     {S,{C "*"}},     {S,{C "8"}}},
208 /* 10*/ {KBD_ASCII, I, {S,{C "9"}},     {S,{C "("}},     {S,{C "9"}}},
209 /* 11*/ {KBD_ASCII, I, {S,{C "0"}},     {S,{C ")"}},     {S,{C "0"}}},
210 /* 12*/ {KBD_ASCII, I, {S,{C "-"}},     {S,{C "_"}},     {S,{C "\037"}}},
211 /* 13*/ {KBD_ASCII, I, {S,{C "="}},     {S,{C "+"}},     {S,{C "="}}},
212 /* 14*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
213 /* 15*/ {KBD_ASCII, I, {S,{C "\177"}},  {S,{C "\010"}},  {S,{C "\177"}}}, /* BS */
214 /* 16*/ {KBD_ASCII, I, {S,{C "\t"}},    {S,{C "\t"}},    {S,{C "\t"}}},   /* TAB */
215 /* 17*/ {KBD_ASCII, I, {S,{C "q"}},     {S,{C "Q"}},     {S,{C "\021"}}},
216 /* 18*/ {KBD_ASCII, I, {S,{C "w"}},     {S,{C "W"}},     {S,{C "\027"}}},
217 /* 19*/ {KBD_ASCII, I, {S,{C "e"}},     {S,{C "E"}},     {S,{C "\005"}}},
218 /* 20*/ {KBD_ASCII, I, {S,{C "r"}},     {S,{C "R"}},     {S,{C "\022"}}},
219 /* 21*/ {KBD_ASCII, I, {S,{C "t"}},     {S,{C "T"}},     {S,{C "\024"}}},
220 /* 22*/ {KBD_ASCII, I, {S,{C "y"}},     {S,{C "Y"}},     {S,{C "\031"}}},
221 /* 23*/ {KBD_ASCII, I, {S,{C "u"}},     {S,{C "U"}},     {S,{C "\025"}}},
222 /* 24*/ {KBD_ASCII, I, {S,{C "i"}},     {S,{C "I"}},     {S,{C "\011"}}},
223 /* 25*/ {KBD_ASCII, I, {S,{C "o"}},     {S,{C "O"}},     {S,{C "\017"}}},
224 /* 26*/ {KBD_ASCII, I, {S,{C "p"}},     {S,{C "P"}},     {S,{C "\020"}}},
225 /* 27*/ {KBD_ASCII, I, {S,{C "["}},     {S,{C "{"}},     {S,{C "\033"}}},
226 /* 28*/ {KBD_ASCII, I, {S,{C "]"}},     {S,{C "}"}},     {S,{C "\035"}}},
227 /* 29*/ {KBD_ASCII, I, {S,{C "\\"}},    {S,{C "|"}},     {S,{C "\034"}}},
228 /* 30*/ {KBD_CAPS,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
229 /* 31*/ {KBD_ASCII, I, {S,{C "a"}},     {S,{C "A"}},     {S,{C "\001"}}},
230 /* 32*/ {KBD_ASCII, I, {S,{C "s"}},     {S,{C "S"}},     {S,{C "\023"}}},
231 /* 33*/ {KBD_ASCII, I, {S,{C "d"}},     {S,{C "D"}},     {S,{C "\004"}}},
232 /* 34*/ {KBD_ASCII, I, {S,{C "f"}},     {S,{C "F"}},     {S,{C "\006"}}},
233 /* 35*/ {KBD_ASCII, I, {S,{C "g"}},     {S,{C "G"}},     {S,{C "\007"}}},
234 /* 36*/ {KBD_ASCII, I, {S,{C "h"}},     {S,{C "H"}},     {S,{C "\010"}}},
235 /* 37*/ {KBD_ASCII, I, {S,{C "j"}},     {S,{C "J"}},     {S,{C "\n"}}},
236 /* 38*/ {KBD_ASCII, I, {S,{C "k"}},     {S,{C "K"}},     {S,{C "\013"}}},
237 /* 39*/ {KBD_ASCII, I, {S,{C "l"}},     {S,{C "L"}},     {S,{C "\014"}}},
238 /* 40*/ {KBD_ASCII, I, {S,{C ";"}},     {S,{C ":"}},     {S,{C ";"}}},
239 /* 41*/ {KBD_ASCII, I, {S,{C "'"}},     {S,{C "\""}},    {S,{C "'"}}},
240 /* 42*/ {KBD_ASCII, I, {S,{C "\\"}},    {S,{C "|"}},     {S,{C "\034"}}}, /* special */
241 /* 43*/ {KBD_RETURN,I, {S,{C "\r"}},    {S,{C "\r"}},    {S,{C "\r"}}},   /* RETURN */
242 /* 44*/ {KBD_SHIFT, I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},     /* SHIFT left */
243 /* 45*/ {KBD_ASCII, I, {S,{C "<"}},     {S,{C ">"}},     {S,{C ""}}},
244 /* 46*/ {KBD_ASCII, I, {S,{C "z"}},     {S,{C "Z"}},     {S,{C "\032"}}},
245 /* 47*/ {KBD_ASCII, I, {S,{C "x"}},     {S,{C "X"}},     {S,{C "\030"}}},
246 /* 48*/ {KBD_ASCII, I, {S,{C "c"}},     {S,{C "C"}},     {S,{C "\003"}}},
247 /* 49*/ {KBD_ASCII, I, {S,{C "v"}},     {S,{C "V"}},     {S,{C "\026"}}},
248 /* 50*/ {KBD_ASCII, I, {S,{C "b"}},     {S,{C "B"}},     {S,{C "\002"}}},
249 /* 51*/ {KBD_ASCII, I, {S,{C "n"}},     {S,{C "N"}},     {S,{C "\016"}}},
250 /* 52*/ {KBD_ASCII, I, {S,{C "m"}},     {S,{C "M"}},     {S,{C "\r"}}},
251 /* 53*/ {KBD_ASCII, I, {S,{C ","}},     {S,{C "<"}},     {S,{C ","}}},
252 /* 54*/ {KBD_ASCII, I, {S,{C "."}},     {S,{C ">"}},     {S,{C "."}}},
253 /* 55*/ {KBD_ASCII, I, {S,{C "/"}},     {S,{C "?"}},     {S,{C "/"}}},
254 /* 56*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
255 /* 57*/ {KBD_SHIFT, I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},     /* SHIFT right */
256 /* 58*/ {KBD_CTL,   I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},     /* CTL left */
257 /* 59*/ {KBD_ASCII, I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
258 /* 60*/ {KBD_META,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},     /* ALT left */
259 #if !PCVT_NULLCHARS
260 /* 61*/ {KBD_ASCII, I, {S,{C " "}},     {S,{C " "}},     {S,{C " "}}},    /* SPACE */
261 #else
262 /* 61*/ {KBD_ASCII, I, {S,{C " "}},     {S,{C " "}},     {S,{C "\000"}}}, /* SPACE */
263 #endif /* PCVT_NULLCHARS */
264 /* 62*/ {KBD_META,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},     /* ALT right */
265 /* 63*/ {KBD_ASCII, I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
266 /* 64*/ {KBD_CTL,   I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},     /* CTL right */
267 /* 65*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
268 /* 66*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
269 /* 67*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
270 /* 68*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
271 /* 69*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
272 /* 70*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
273 /* 71*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
274 /* 72*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
275 /* 73*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
276 /* 74*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
277 /* 75*/ {KBD_FUNC,  I, {S,{C "\033[2~"}},{S,{C "\033[2~"}},{S,{C "\033[2~"}}},/* INS */
278 /* 76*/ {KBD_FUNC,  I, {S,{C "\033[3~"}},{S,{C "\033[3~"}},{S,{C "\033[3~"}}},/* DEL */
279 /* 77*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
280 /* 78*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
281 /* 79*/ {KBD_CURSOR,I, {S,{C "\033[D"}},{S,{C "\033OD"}},{S,{C "\033[D"}}},   /* CU <- */
282 /* 80*/ {KBD_FUNC,  I, {S,{C "\033[1~"}},{S,{C "\033[1~"}},{S,{C "\033[1~"}}},/* HOME = FIND*/
283 /* 81*/ {KBD_FUNC,  I, {S,{C "\033[4~"}},{S,{C "\033[4~"}},{S,{C "\033[4~"}}},/* END = SELECT */
284 /* 82*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
285 /* 83*/ {KBD_CURSOR,I, {S,{C "\033[A"}},{S,{C "\033OA"}},{S,{C "\033[A"}}},   /* CU ^ */
286 /* 84*/ {KBD_CURSOR,I, {S,{C "\033[B"}},{S,{C "\033OB"}},{S,{C "\033[B"}}},   /* CU v */
287 /* 85*/ {KBD_FUNC,  I, {S,{C "\033[5~"}},{S,{C "\033[5~"}},{S,{C "\033[5~"}}},/*PG UP*/
288 /* 86*/ {KBD_FUNC,  I, {S,{C "\033[6~"}},{S,{C "\033[6~"}},{S,{C "\033[6~"}}},/*PG DN*/
289 /* 87*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
290 /* 88*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
291 /* 89*/ {KBD_CURSOR,I, {S,{C "\033[C"}},{S,{C "\033OC"}},{S,{C "\033[C"}}},   /* CU -> */
292 /* 90*/ {KBD_NUM,   I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
293 /* 91*/ {KBD_KP,    I, {S,{C "7"}},     {S,{C "\033Ow"}},{S,{C "7"}}},
294 /* 92*/ {KBD_KP,    I, {S,{C "4"}},     {S,{C "\033Ot"}},{S,{C "4"}}},
295 /* 93*/ {KBD_KP,    I, {S,{C "1"}},     {S,{C "\033Oq"}},{S,{C "1"}}},
296 /* 94*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
297 /* 95*/ {KBD_KP,    I, {S,{C "/"}},     {S,{C "/"}},     {S,{C "/"}}},
298 /* 96*/ {KBD_KP,    I, {S,{C "8"}},     {S,{C "\033Ox"}},{S,{C "8"}}},
299 /* 97*/ {KBD_KP,    I, {S,{C "5"}},     {S,{C "\033Ou"}},{S,{C "5"}}},
300 /* 98*/ {KBD_KP,    I, {S,{C "2"}},     {S,{C "\033Or"}},{S,{C "2"}}},
301 /* 99*/ {KBD_KP,    I, {S,{C "0"}},     {S,{C "\033Op"}},{S,{C "0"}}},
302 /*100*/ {KBD_KP,    I, {S,{C "*"}},     {S,{C "*"}},     {S,{C "*"}}},
303 /*101*/ {KBD_KP,    I, {S,{C "9"}},     {S,{C "\033Oy"}},{S,{C "9"}}},
304 /*102*/ {KBD_KP,    I, {S,{C "6"}},     {S,{C "\033Ov"}},{S,{C "6"}}},
305 /*103*/ {KBD_KP,    I, {S,{C "3"}},     {S,{C "\033Os"}},{S,{C "3"}}},
306 /*104*/ {KBD_KP,    I, {S,{C "."}},     {S,{C "\033On"}},{S,{C "."}}},
307 /*105*/ {KBD_KP,    I, {S,{C "-"}},     {S,{C "\033Om"}},{S,{C "-"}}},
308 /*106*/ {KBD_KP,    I, {S,{C "+"}},     {S,{C "+"}},     {S,{C "+"}}},
309 /*107*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
310 /*108*/ {KBD_RETURN,I, {S,{C "\r"}},    {S,{C "\033OM"}},{S,{C "\r"}}},    /* KP ENTER */
311 /*109*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
312 /*110*/ {KBD_ASCII, I, {S,{C "\033"}},  {S,{C "\033"}},  {S,{C "\033"}}},
313 /*111*/ {KBD_NONE,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
314 /*112*/ {KBD_FUNC,  I, {F,{V fkey1}},   {F,{V sfkey1}},  {F,{V cfkey1}}},  /* F1 */
315 /*113*/ {KBD_FUNC,  I, {F,{V fkey2}},   {F,{V sfkey2}},  {F,{V cfkey2}}},  /* F2 */
316 /*114*/ {KBD_FUNC,  I, {F,{V fkey3}},   {F,{V sfkey3}},  {F,{V cfkey3}}},  /* F3 */
317 /*115*/ {KBD_FUNC,  I, {F,{V fkey4}},   {F,{V sfkey4}},  {F,{V cfkey4}}},  /* F4 */
318 /*116*/ {KBD_FUNC,  I, {F,{V fkey5}},   {F,{V sfkey5}},  {F,{V cfkey5}}},  /* F5 */
319 /*117*/ {KBD_FUNC,  I, {F,{V fkey6}},   {F,{V sfkey6}},  {F,{V cfkey6}}},  /* F6 */
320 /*118*/ {KBD_FUNC,  I, {F,{V fkey7}},   {F,{V sfkey7}},  {F,{V cfkey7}}},  /* F7 */
321 /*119*/ {KBD_FUNC,  I, {F,{V fkey8}},   {F,{V sfkey8}},  {F,{V cfkey8}}},  /* F8 */
322 /*120*/ {KBD_FUNC,  I, {F,{V fkey9}},   {F,{V sfkey9}},  {F,{V cfkey9}}},  /* F9 */
323 /*121*/ {KBD_FUNC,  I, {F,{V fkey10}},  {F,{V sfkey10}}, {F,{V cfkey10}}}, /* F10 */
324 /*122*/ {KBD_FUNC,  I, {F,{V fkey11}},  {F,{V sfkey11}}, {F,{V cfkey11}}}, /* F11 */
325 /*123*/ {KBD_FUNC,  I, {F,{V fkey12}},  {F,{V sfkey12}}, {F,{V cfkey12}}}, /* F12 */
326 /*124*/ {KBD_KP,    I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
327 /*125*/ {KBD_SCROLL,I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
328 /*126*/ {KBD_BREAK, I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},
329 /*127*/ {KBD_FUNC,  I, {S,{C ""}},      {S,{C ""}},      {S,{C ""}}},      /* SysRq */
330
331 #undef C
332 #undef V
333 #undef S
334 #undef F
335 #undef I
336 };
337
338 static short    keypad2num[] = {
339         7, 4, 1, -1, -1, 8, 5, 2, 0, -1, 9, 6, 3, -1, -1, -1, -1
340 };
341
342 #ifdef XSERVER
343
344 #define N_KEYNUMS 128
345
346 /*
347  * this is the reverse mapping from keynumbers to scanset 1 codes
348  * it is used to emulate the SysV-style GIO_KEYMAP ioctl cmd
349  */
350
351 static u_char key2scan1[N_KEYNUMS] = {
352            0,0x29,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, /*   0 */
353         0x0a,0x0b,0x0c,0x0d,   0,0x0e,0x0f,0x10,0x11,0x12, /*  10 */
354         0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x2b, /*  20 */
355         0x3a,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26, /*  30 */
356         0x27,0x28,   0,0x1c,0x2a,0x56,0x2c,0x2d,0x2e,0x2f, /*  40 */
357         0x30,0x31,0x32,0x33,0x34,0x35,0x56,0x36,0x1d,   0, /*  50 */
358         0x38,0x39,   0,   0,   0,   0,   0,   0,   0,   0, /*  60 */
359            0,   0,   0,   0,   0,   0,   0,   0,   0,   0, /*  70 */
360            0,   0,   0,   0,   0,   0,   0,   0,   0,   0, /*  80 */
361         0x45,0x47,0x4b,0x4f,   0,   0,0x48,0x4c,0x50,0x52, /*  90 */
362         0x37,0x49,0x4d,0x51,0x53,0x4a,0x4e,   0,   0,   0, /* 100 */
363         0x01,   0,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42, /* 110 */
364         0x43,0x44,0x57,0x58,   0,0x46,   0,0x54            /* 120 */
365 };
366
367 /*
368  * SysV is brain-dead enough to stick on the IBM code page 437. So we
369  * have to translate our keymapping into IBM 437 (possibly losing keys),
370  * in order to have the X server convert it back into ISO8859.1
371  */
372
373 /* NB: this table only contains the mapping for codes >= 128 */
374
375 static u_char iso2ibm437[] =
376 {
377            0,     0,     0,     0,     0,     0,     0,     0,
378            0,     0,     0,     0,     0,     0,     0,     0,
379            0,     0,     0,     0,     0,     0,     0,     0,
380            0,     0,     0,     0,     0,     0,     0,     0,
381         0xff,  0xad,  0x9b,  0x9c,     0,  0x9d,     0,  0x40,
382         0x6f,  0x63,  0x61,  0xae,     0,     0,     0,     0,
383         0xf8,  0xf1,  0xfd,  0x33,     0,  0xe6,     0,  0xfa,
384            0,  0x31,  0x6f,  0xaf,  0xac,  0xab,     0,  0xa8,
385         0x41,  0x41,  0x41,  0x41,  0x8e,  0x8f,  0x92,  0x80,
386         0x45,  0x90,  0x45,  0x45,  0x49,  0x49,  0x49,  0x49,
387         0x81,  0xa5,  0x4f,  0x4f,  0x4f,  0x4f,  0x99,  0x4f,
388         0x4f,  0x55,  0x55,  0x55,  0x9a,  0x59,     0,  0xe1,
389         0x85,  0xa0,  0x83,  0x61,  0x84,  0x86,  0x91,  0x87,
390         0x8a,  0x82,  0x88,  0x89,  0x8d,  0xa1,  0x8c,  0x8b,
391            0,  0xa4,  0x95,  0xa2,  0x93,  0x6f,  0x94,  0x6f,
392         0x6f,  0x97,  0xa3,  0x96,  0x81,  0x98,     0,     0
393 };
394
395 #endif /* XSERVER */
396