wskbdutil.c revision 1.12.4.1 1 /* $NetBSD: wskbdutil.c,v 1.12.4.1 2006/09/09 02:56:07 rpaulo Exp $ */
2
3 /*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Juergen Hannken-Illjes.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: wskbdutil.c,v 1.12.4.1 2006/09/09 02:56:07 rpaulo Exp $");
41
42 #include <sys/param.h>
43 #include <sys/cdefs.h>
44 #include <sys/errno.h>
45 #include <sys/systm.h>
46 #include <sys/malloc.h>
47 #include <dev/wscons/wsksymdef.h>
48 #include <dev/wscons/wsksymvar.h>
49
50 static struct compose_tab_s {
51 keysym_t elem[2];
52 keysym_t result;
53 } compose_tab[] = {
54 { { KS_plus, KS_plus }, KS_numbersign },
55 { { KS_a, KS_a }, KS_at },
56 { { KS_parenleft, KS_parenleft }, KS_bracketleft },
57 { { KS_slash, KS_slash }, KS_backslash },
58 { { KS_parenright, KS_parenright }, KS_bracketright },
59 { { KS_parenleft, KS_minus }, KS_braceleft },
60 { { KS_slash, KS_minus }, KS_bar },
61 { { KS_parenright, KS_minus }, KS_braceright },
62 { { KS_exclam, KS_exclam }, KS_exclamdown },
63 { { KS_c, KS_slash }, KS_cent },
64 { { KS_l, KS_minus }, KS_sterling },
65 { { KS_y, KS_minus }, KS_yen },
66 { { KS_s, KS_o }, KS_section },
67 { { KS_x, KS_o }, KS_currency },
68 { { KS_c, KS_o }, KS_copyright },
69 { { KS_less, KS_less }, KS_guillemotleft },
70 { { KS_greater, KS_greater }, KS_guillemotright },
71 { { KS_question, KS_question }, KS_questiondown },
72 { { KS_dead_acute, KS_space }, KS_acute },
73 { { KS_dead_grave, KS_space }, KS_grave },
74 { { KS_dead_tilde, KS_space }, KS_asciitilde },
75 { { KS_dead_circumflex, KS_space }, KS_asciicircum },
76 { { KS_dead_circumflex, KS_A }, KS_Acircumflex },
77 { { KS_dead_diaeresis, KS_A }, KS_Adiaeresis },
78 { { KS_dead_grave, KS_A }, KS_Agrave },
79 { { KS_dead_abovering, KS_A }, KS_Aring },
80 { { KS_dead_tilde, KS_A }, KS_Atilde },
81 { { KS_dead_cedilla, KS_C }, KS_Ccedilla },
82 { { KS_dead_acute, KS_E }, KS_Eacute },
83 { { KS_dead_circumflex, KS_E }, KS_Ecircumflex },
84 { { KS_dead_diaeresis, KS_E }, KS_Ediaeresis },
85 { { KS_dead_grave, KS_E }, KS_Egrave },
86 { { KS_dead_acute, KS_I }, KS_Iacute },
87 { { KS_dead_circumflex, KS_I }, KS_Icircumflex },
88 { { KS_dead_diaeresis, KS_I }, KS_Idiaeresis },
89 { { KS_dead_grave, KS_I }, KS_Igrave },
90 { { KS_dead_tilde, KS_N }, KS_Ntilde },
91 { { KS_dead_acute, KS_O }, KS_Oacute },
92 { { KS_dead_circumflex, KS_O }, KS_Ocircumflex },
93 { { KS_dead_diaeresis, KS_O }, KS_Odiaeresis },
94 { { KS_dead_grave, KS_O }, KS_Ograve },
95 { { KS_dead_tilde, KS_O }, KS_Otilde },
96 { { KS_dead_acute, KS_U }, KS_Uacute },
97 { { KS_dead_circumflex, KS_U }, KS_Ucircumflex },
98 { { KS_dead_diaeresis, KS_U }, KS_Udiaeresis },
99 { { KS_dead_grave, KS_U }, KS_Ugrave },
100 { { KS_dead_acute, KS_Y }, KS_Yacute },
101 { { KS_dead_acute, KS_a }, KS_aacute },
102 { { KS_dead_circumflex, KS_a }, KS_acircumflex },
103 { { KS_dead_diaeresis, KS_a }, KS_adiaeresis },
104 { { KS_dead_grave, KS_a }, KS_agrave },
105 { { KS_dead_abovering, KS_a }, KS_aring },
106 { { KS_dead_tilde, KS_a }, KS_atilde },
107 { { KS_dead_cedilla, KS_c }, KS_ccedilla },
108 { { KS_dead_acute, KS_e }, KS_eacute },
109 { { KS_dead_circumflex, KS_e }, KS_ecircumflex },
110 { { KS_dead_diaeresis, KS_e }, KS_ediaeresis },
111 { { KS_dead_grave, KS_e }, KS_egrave },
112 { { KS_dead_acute, KS_i }, KS_iacute },
113 { { KS_dead_circumflex, KS_i }, KS_icircumflex },
114 { { KS_dead_diaeresis, KS_i }, KS_idiaeresis },
115 { { KS_dead_grave, KS_i }, KS_igrave },
116 { { KS_dead_tilde, KS_n }, KS_ntilde },
117 { { KS_dead_acute, KS_o }, KS_oacute },
118 { { KS_dead_circumflex, KS_o }, KS_ocircumflex },
119 { { KS_dead_diaeresis, KS_o }, KS_odiaeresis },
120 { { KS_dead_grave, KS_o }, KS_ograve },
121 { { KS_dead_tilde, KS_o }, KS_otilde },
122 { { KS_dead_acute, KS_u }, KS_uacute },
123 { { KS_dead_circumflex, KS_u }, KS_ucircumflex },
124 { { KS_dead_diaeresis, KS_u }, KS_udiaeresis },
125 { { KS_dead_grave, KS_u }, KS_ugrave },
126 { { KS_dead_acute, KS_y }, KS_yacute },
127 { { KS_dead_diaeresis, KS_y }, KS_ydiaeresis },
128 { { KS_quotedbl, KS_A }, KS_Adiaeresis },
129 { { KS_quotedbl, KS_E }, KS_Ediaeresis },
130 { { KS_quotedbl, KS_I }, KS_Idiaeresis },
131 { { KS_quotedbl, KS_O }, KS_Odiaeresis },
132 { { KS_quotedbl, KS_U }, KS_Udiaeresis },
133 { { KS_quotedbl, KS_a }, KS_adiaeresis },
134 { { KS_quotedbl, KS_e }, KS_ediaeresis },
135 { { KS_quotedbl, KS_i }, KS_idiaeresis },
136 { { KS_quotedbl, KS_o }, KS_odiaeresis },
137 { { KS_quotedbl, KS_u }, KS_udiaeresis },
138 { { KS_quotedbl, KS_y }, KS_ydiaeresis },
139 { { KS_acute, KS_A }, KS_Aacute },
140 { { KS_asciicircum, KS_A }, KS_Acircumflex },
141 { { KS_grave, KS_A }, KS_Agrave },
142 { { KS_asterisk, KS_A }, KS_Aring },
143 { { KS_asciitilde, KS_A }, KS_Atilde },
144 { { KS_cedilla, KS_C }, KS_Ccedilla },
145 { { KS_acute, KS_E }, KS_Eacute },
146 { { KS_asciicircum, KS_E }, KS_Ecircumflex },
147 { { KS_grave, KS_E }, KS_Egrave },
148 { { KS_acute, KS_I }, KS_Iacute },
149 { { KS_asciicircum, KS_I }, KS_Icircumflex },
150 { { KS_grave, KS_I }, KS_Igrave },
151 { { KS_asciitilde, KS_N }, KS_Ntilde },
152 { { KS_acute, KS_O }, KS_Oacute },
153 { { KS_asciicircum, KS_O }, KS_Ocircumflex },
154 { { KS_grave, KS_O }, KS_Ograve },
155 { { KS_asciitilde, KS_O }, KS_Otilde },
156 { { KS_acute, KS_U }, KS_Uacute },
157 { { KS_asciicircum, KS_U }, KS_Ucircumflex },
158 { { KS_grave, KS_U }, KS_Ugrave },
159 { { KS_acute, KS_Y }, KS_Yacute },
160 { { KS_acute, KS_a }, KS_aacute },
161 { { KS_asciicircum, KS_a }, KS_acircumflex },
162 { { KS_grave, KS_a }, KS_agrave },
163 { { KS_asterisk, KS_a }, KS_aring },
164 { { KS_asciitilde, KS_a }, KS_atilde },
165 { { KS_cedilla, KS_c }, KS_ccedilla },
166 { { KS_acute, KS_e }, KS_eacute },
167 { { KS_asciicircum, KS_e }, KS_ecircumflex },
168 { { KS_grave, KS_e }, KS_egrave },
169 { { KS_acute, KS_i }, KS_iacute },
170 { { KS_asciicircum, KS_i }, KS_icircumflex },
171 { { KS_grave, KS_i }, KS_igrave },
172 { { KS_asciitilde, KS_n }, KS_ntilde },
173 { { KS_acute, KS_o }, KS_oacute },
174 { { KS_asciicircum, KS_o }, KS_ocircumflex },
175 { { KS_grave, KS_o }, KS_ograve },
176 { { KS_asciitilde, KS_o }, KS_otilde },
177 { { KS_acute, KS_u }, KS_uacute },
178 { { KS_asciicircum, KS_u }, KS_ucircumflex },
179 { { KS_grave, KS_u }, KS_ugrave },
180 { { KS_acute, KS_y }, KS_yacute },
181 { { KS_dead_semi, KS_gr_A }, KS_gr_At },
182 { { KS_dead_semi, KS_gr_E }, KS_gr_Et },
183 { { KS_dead_semi, KS_gr_H }, KS_gr_Ht },
184 { { KS_dead_semi, KS_gr_I }, KS_gr_It },
185 { { KS_dead_semi, KS_gr_O }, KS_gr_Ot },
186 { { KS_dead_semi, KS_gr_Y }, KS_gr_Yt },
187 { { KS_dead_semi, KS_gr_V }, KS_gr_Vt },
188 { { KS_dead_colon, KS_gr_I }, KS_gr_Id },
189 { { KS_dead_colon, KS_gr_Y }, KS_gr_Yd },
190 { { KS_dead_semi, KS_gr_a }, KS_gr_at },
191 { { KS_dead_semi, KS_gr_e }, KS_gr_et },
192 { { KS_dead_semi, KS_gr_h }, KS_gr_ht },
193 { { KS_dead_semi, KS_gr_i }, KS_gr_it },
194 { { KS_dead_semi, KS_gr_o }, KS_gr_ot },
195 { { KS_dead_semi, KS_gr_y }, KS_gr_yt },
196 { { KS_dead_semi, KS_gr_v }, KS_gr_vt },
197 { { KS_dead_colon, KS_gr_i }, KS_gr_id },
198 { { KS_dead_colon, KS_gr_y }, KS_gr_yd }
199 };
200
201 #define COMPOSE_SIZE sizeof(compose_tab)/sizeof(compose_tab[0])
202
203 static int compose_tab_inorder = 0;
204
205 static inline int compose_tab_cmp(struct compose_tab_s *, struct compose_tab_s *);
206 static keysym_t ksym_upcase(keysym_t);
207 static void fillmapentry(const keysym_t *, int, struct wscons_keymap *);
208
209 static inline int
210 compose_tab_cmp(struct compose_tab_s *i, struct compose_tab_s *j)
211 {
212 if (i->elem[0] == j->elem[0])
213 return(i->elem[1] - j->elem[1]);
214 else
215 return(i->elem[0] - j->elem[0]);
216 }
217
218 keysym_t
219 wskbd_compose_value(keysym_t *compose_buf)
220 {
221 int i, j, r;
222 struct compose_tab_s v;
223
224 if (! compose_tab_inorder) {
225 /* Insertion sort. */
226 for (i = 1; i < COMPOSE_SIZE; i++) {
227 v = compose_tab[i];
228 /* find correct slot, moving others up */
229 for (j = i; --j >= 0 && compose_tab_cmp(& v, & compose_tab[j]) < 0; )
230 compose_tab[j + 1] = compose_tab[j];
231 compose_tab[j + 1] = v;
232 }
233 compose_tab_inorder = 1;
234 }
235
236 for (j = 0, i = COMPOSE_SIZE; i != 0; i /= 2) {
237 if (compose_tab[j + i/2].elem[0] == compose_buf[0]) {
238 if (compose_tab[j + i/2].elem[1] == compose_buf[1])
239 return(compose_tab[j + i/2].result);
240 r = compose_tab[j + i/2].elem[1] < compose_buf[1];
241 } else
242 r = compose_tab[j + i/2].elem[0] < compose_buf[0];
243 if (r) {
244 j += i/2 + 1;
245 i--;
246 }
247 }
248
249 return(KS_voidSymbol);
250 }
251
252 static const u_char latin1_to_upper[256] = {
253 /* 0 8 1 9 2 a 3 b 4 c 5 d 6 e 7 f */
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1 */
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1 */
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3 */
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3 */
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 4 */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 4 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 5 */
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 5 */
266 0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', /* 6 */
267 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', /* 6 */
268 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', /* 7 */
269 'X', 'Y', 'Z', 0x00, 0x00, 0x00, 0x00, 0x00, /* 7 */
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8 */
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8 */
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9 */
273 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9 */
274 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */
275 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a */
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b */
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b */
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c */
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c */
280 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d */
282 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* e */
283 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, /* e */
284 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0x00, /* f */
285 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0x00, /* f */
286 };
287
288 static keysym_t
289 ksym_upcase(keysym_t ksym)
290 {
291 if (ksym >= KS_f1 && ksym <= KS_f20)
292 return(KS_F1 - KS_f1 + ksym);
293
294 if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff &&
295 latin1_to_upper[ksym] != 0x00)
296 return(latin1_to_upper[ksym]);
297
298 return(ksym);
299 }
300
301 static void
302 fillmapentry(const keysym_t *kp, int len, struct wscons_keymap *mapentry)
303 {
304 switch (len) {
305 case 0:
306 mapentry->group1[0] = KS_voidSymbol;
307 mapentry->group1[1] = KS_voidSymbol;
308 mapentry->group2[0] = KS_voidSymbol;
309 mapentry->group2[1] = KS_voidSymbol;
310 break;
311
312 case 1:
313 mapentry->group1[0] = kp[0];
314 mapentry->group1[1] = ksym_upcase(kp[0]);
315 mapentry->group2[0] = mapentry->group1[0];
316 mapentry->group2[1] = mapentry->group1[1];
317 break;
318
319 case 2:
320 mapentry->group1[0] = kp[0];
321 mapentry->group1[1] = kp[1];
322 mapentry->group2[0] = mapentry->group1[0];
323 mapentry->group2[1] = mapentry->group1[1];
324 break;
325
326 case 3:
327 mapentry->group1[0] = kp[0];
328 mapentry->group1[1] = kp[1];
329 mapentry->group2[0] = kp[2];
330 mapentry->group2[1] = ksym_upcase(kp[2]);
331 break;
332
333 case 4:
334 mapentry->group1[0] = kp[0];
335 mapentry->group1[1] = kp[1];
336 mapentry->group2[0] = kp[2];
337 mapentry->group2[1] = kp[3];
338 break;
339
340 }
341 }
342
343 void
344 wskbd_get_mapentry(const struct wskbd_mapdata *mapdata, int kc,
345 struct wscons_keymap *mapentry)
346 {
347 kbd_t cur;
348 const keysym_t *kp;
349 const struct wscons_keydesc *mp;
350 int l;
351
352 mapentry->command = KS_voidSymbol;
353 mapentry->group1[0] = KS_voidSymbol;
354 mapentry->group1[1] = KS_voidSymbol;
355 mapentry->group2[0] = KS_voidSymbol;
356 mapentry->group2[1] = KS_voidSymbol;
357
358 for (cur = mapdata->layout & ~KB_HANDLEDBYWSKBD; cur != 0; ) {
359 mp = mapdata->keydesc;
360 while (mp->map_size > 0) {
361 if (mp->name == cur)
362 break;
363 mp++;
364 }
365
366 /* If map not found, return */
367 if (mp->map_size <= 0)
368 return;
369
370 for (kp = mp->map; kp < mp->map + mp->map_size; kp++)
371 if (KS_GROUP(*kp) == KS_GROUP_Keycode &&
372 KS_VALUE(*kp) == kc) {
373 /* First skip keycode and possible command */
374 kp++;
375 if (KS_GROUP(*kp) == KS_GROUP_Command ||
376 *kp == KS_Cmd || *kp == KS_Cmd1 || *kp == KS_Cmd2)
377 mapentry->command = *kp++;
378
379 for (l = 0; kp + l < mp->map + mp->map_size; l++)
380 if (KS_GROUP(kp[l]) == KS_GROUP_Keycode)
381 break;
382 if (l > 4)
383 panic("wskbd_get_mapentry: %d(%d): bad entry",
384 mp->name, *kp);
385 fillmapentry(kp, l, mapentry);
386 return;
387 }
388
389 cur = mp->base;
390 }
391 }
392
393 void
394 wskbd_init_keymap(int newlen, struct wscons_keymap **map, int *maplen)
395 {
396 int i;
397
398 if (newlen != *maplen) {
399 if (*maplen > 0)
400 free(*map, M_TEMP);
401 *maplen = newlen;
402 *map = malloc(newlen*sizeof(struct wscons_keymap),
403 M_TEMP, M_WAITOK);
404 }
405
406 for (i = 0; i < *maplen; i++) {
407 (*map)[i].command = KS_voidSymbol;
408 (*map)[i].group1[0] = KS_voidSymbol;
409 (*map)[i].group1[1] = KS_voidSymbol;
410 (*map)[i].group2[0] = KS_voidSymbol;
411 (*map)[i].group2[1] = KS_voidSymbol;
412 }
413 }
414
415 int
416 wskbd_load_keymap(const struct wskbd_mapdata *mapdata,
417 struct wscons_keymap **map, int *maplen)
418 {
419 int i, s, kc, stack_ptr;
420 const keysym_t *kp;
421 const struct wscons_keydesc *mp, *stack[10];
422 kbd_t cur;
423
424 for (cur = mapdata->layout & ~KB_HANDLEDBYWSKBD, stack_ptr = 0;
425 cur != 0; stack_ptr++) {
426 mp = mapdata->keydesc;
427 while (mp->map_size > 0) {
428 if (cur == 0 || mp->name == cur) {
429 break;
430 }
431 mp++;
432 }
433
434 if (stack_ptr == sizeof(stack)/sizeof(stack[0]))
435 panic("wskbd_load_keymap: %d: recursion too deep",
436 mapdata->layout);
437 if (mp->map_size <= 0)
438 return(EINVAL);
439
440 stack[stack_ptr] = mp;
441 cur = mp->base;
442 }
443
444 for (i = 0, s = stack_ptr - 1; s >= 0; s--) {
445 mp = stack[s];
446 for (kp = mp->map; kp < mp->map + mp->map_size; kp++)
447 if (KS_GROUP(*kp) == KS_GROUP_Keycode && KS_VALUE(*kp) > i)
448 i = KS_VALUE(*kp);
449 }
450
451 wskbd_init_keymap(i + 1, map, maplen);
452
453 for (s = stack_ptr - 1; s >= 0; s--) {
454 mp = stack[s];
455 for (kp = mp->map; kp < mp->map + mp->map_size; ) {
456 if (KS_GROUP(*kp) != KS_GROUP_Keycode)
457 panic("wskbd_load_keymap: %d(%d): bad entry",
458 mp->name, *kp);
459
460 kc = KS_VALUE(*kp);
461 kp++;
462
463 if (KS_GROUP(*kp) == KS_GROUP_Command ||
464 *kp == KS_Cmd || *kp == KS_Cmd1 || *kp == KS_Cmd2) {
465 (*map)[kc].command = *kp;
466 kp++;
467 }
468
469 for (i = 0; kp + i < mp->map + mp->map_size; i++)
470 if (KS_GROUP(kp[i]) == KS_GROUP_Keycode)
471 break;
472
473 if (i > 4)
474 panic("wskbd_load_keymap: %d(%d): bad entry",
475 mp->name, *kp);
476
477 fillmapentry(kp, i, &(*map)[kc]);
478 kp += i;
479 }
480 }
481
482 return(0);
483 }
484