4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 #ident "%Z%%M% %I% %E% SMI"
27 * Copyright (c) 1988 by Sun Microsystems, Inc.
30 #include <sys/types.h>
39 SM_INVALID
, /* this shift mask is invalid for this keyboard */
40 SM_NORMAL
, /* "normal", valid shift mask */
41 SM_NUMLOCK
, /* "Num Lock" shift mask */
42 SM_UP
/* "Up" shift mask */
52 smentry_t shiftmasks
[] = {
53 { "base", 0, SM_NORMAL
},
54 { "shift", SHIFTMASK
, SM_NORMAL
},
55 { "caps", CAPSMASK
, SM_NORMAL
},
56 { "ctrl", CTRLMASK
, SM_NORMAL
},
57 { "altg", ALTGRAPHMASK
, SM_NORMAL
},
58 { "numl", NUMLOCKMASK
, SM_NUMLOCK
},
59 { "up", UPMASK
, SM_UP
},
62 #define NSHIFTS (sizeof (shiftmasks) / sizeof (shiftmasks[0]))
64 static void printentry(struct kiockeymap
*kio
);
65 static void printchar(int character
, int delim
);
74 register int keystation
;
77 struct kiockeymap keyentry
[NSHIFTS
];
80 if ((kbdfd
= open("/dev/kbd", O_WRONLY
)) < 0) {
81 perror("dumpkeys: /dev/kbd");
84 if (ioctl(kbdfd
, KIOCTYPE
, &ktype
) < 0) {
85 perror("dumpkeys: ioctl(KIOCTYPE)");
88 /* if no keyboard detected, or ascii terminal, exit silently */
89 if (ktype
== KB_ASCII
|| ktype
< 0)
93 * See which shift masks are valid for this keyboard.
94 * We do that by trying to get the entry for keystation 0 and that
95 * shift mask; if the "ioctl" fails, we assume it's because the shift
98 for (shift
= 0; shift
< NSHIFTS
; shift
++) {
99 keyentry
[shift
].kio_tablemask
=
100 shiftmasks
[shift
].sm_mask
;
101 keyentry
[shift
].kio_station
= 0;
102 if (ioctl(kbdfd
, KIOCGKEY
, &keyentry
[shift
]) < 0)
103 shiftmasks
[shift
].sm_type
= SM_INVALID
;
107 * Loop until we get an EINVAL, so we don't have to know
108 * how big the table might be.
110 for (keystation
= 0; ; keystation
++) {
111 for (shift
= 0; shift
< NSHIFTS
; shift
++) {
112 if (shiftmasks
[shift
].sm_type
!= SM_INVALID
) {
113 keyentry
[shift
].kio_tablemask
=
114 shiftmasks
[shift
].sm_mask
;
115 keyentry
[shift
].kio_station
= keystation
;
116 if (ioctl(kbdfd
, KIOCGKEY
,
117 &keyentry
[shift
]) < 0) {
120 perror("dumpkeys: KIOCGKEY");
126 (void) printf("key %d\t", keystation
);
129 * See if all the "normal" entries (all but the Num Lock and Up
130 * entries) are the same.
133 for (shift
= 1; shift
< NSHIFTS
; shift
++) {
134 if (shiftmasks
[shift
].sm_type
== SM_NORMAL
) {
135 if (keyentry
[0].kio_entry
136 != keyentry
[shift
].kio_entry
) {
145 * All of the "normal" entries are the same; just print
148 (void) printf(" all ");
149 printentry(&keyentry
[0]);
152 * The normal entries aren't all the same; print them
155 for (shift
= 0; shift
< NSHIFTS
; shift
++) {
156 if (shiftmasks
[shift
].sm_type
== SM_NORMAL
) {
157 (void) printf(" %s ",
158 shiftmasks
[shift
].sm_name
);
159 printentry(&keyentry
[shift
]);
163 if (allsame
&& keyentry
[0].kio_entry
== HOLE
) {
165 * This key is a "hole"; if either the Num Lock or Up
166 * entry isn't a "hole", print it.
168 for (shift
= 0; shift
< NSHIFTS
; shift
++) {
169 switch (shiftmasks
[shift
].sm_type
) {
173 if (keyentry
[shift
].kio_entry
175 (void) printf(" %s ",
176 shiftmasks
[shift
].sm_name
);
177 printentry(&keyentry
[shift
]);
184 * This entry isn't a "hole"; if the Num Lock entry
185 * isn't NONL (i.e, if Num Lock actually does
186 * something) print it, and if the Up entry isn't NOP
187 * (i.e., if up transitions on this key actually do
188 * something) print it.
190 for (shift
= 0; shift
< NSHIFTS
; shift
++) {
191 switch (shiftmasks
[shift
].sm_type
) {
194 if (keyentry
[shift
].kio_entry
196 (void) printf(" %s ",
197 shiftmasks
[shift
].sm_name
);
198 printentry(&keyentry
[shift
]);
203 if (keyentry
[shift
].kio_entry
205 (void) printf(" %s ",
206 shiftmasks
[shift
].sm_name
);
207 printentry(&keyentry
[shift
]);
217 static char *shiftkeys
[] = {
224 "meta", /* not used */
225 "top", /* not used */
226 "cmd", /* reserved */
232 #define NSHIFTKEYS (sizeof (shiftkeys) / sizeof (shiftkeys[0]))
234 static char *buckybits
[] = {
239 #define NBUCKYBITS (sizeof (buckybits) / sizeof (buckybits[0]))
241 static char *funnies
[] = {
252 #define NFUNNIES (sizeof (funnies) / sizeof (funnies[0]))
254 static char *fa_class
[] = {
263 #define NFA_CLASS (sizeof (fa_class) / sizeof (fa_class[0]))
270 builtin_string_t builtin_strings
[] = {
271 { "\033[H", "homearrow" },
272 { "\033[A", "uparrow" },
273 { "\033[B", "downarrow" },
274 { "\033[D", "leftarrow" },
275 { "\033[C", "rightarrow" },
278 #define NBUILTIN_STRINGS (sizeof (builtin_strings) / \
279 sizeof (builtin_strings[0]))
281 static char *fkeysets
[] = {
288 #define NFKEYSETS (sizeof (fkeysets) / sizeof (fkeysets[0]))
290 static char *padkeys
[] = {
311 #define NPADKEYS (sizeof (padkeys) / sizeof (padkeys[0]))
315 register struct kiockeymap
*kio
;
317 register int entry
= (kio
->kio_entry
& 0x1F);
318 register int fkeyset
;
322 switch (kio
->kio_entry
>> 8) {
325 if (kio
->kio_entry
== '"')
326 (void) printf("'\"'"); /* special case */
327 else if (kio
->kio_entry
== ' ')
328 (void) printf("' '"); /* special case */
330 printchar((int)kio
->kio_entry
, '\'');
334 if (entry
< NSHIFTKEYS
)
335 (void) printf("shiftkeys+%s", shiftkeys
[entry
]);
337 (void) printf("%#4x", kio
->kio_entry
);
341 if (entry
< NBUCKYBITS
)
342 (void) printf("buckybits+%s", buckybits
[entry
]);
344 (void) printf("%#4x", kio
->kio_entry
);
348 if (entry
< NFUNNIES
)
349 (void) printf("%s", funnies
[entry
]);
351 (void) printf("%#4x", kio
->kio_entry
);
355 if (entry
< NFA_CLASS
)
356 (void) printf("%s", fa_class
[entry
]);
358 (void) printf("%#4x", kio
->kio_entry
);
362 if (entry
< NBUILTIN_STRINGS
&& strncmp(kio
->kio_string
,
363 builtin_strings
[entry
].string
, KTAB_STRLEN
) == 0)
364 (void) printf("string+%s", builtin_strings
[entry
].name
);
368 i
< KTAB_STRLEN
&& (c
= kio
->kio_string
[i
]) != '\0';
376 fkeyset
= (int)(kio
->kio_entry
& 0xF0) >> 4;
377 if (fkeyset
< NFKEYSETS
)
378 (void) printf("%s(%d)", fkeysets
[fkeyset
],
381 (void) printf("%#4x", kio
->kio_entry
);
385 if (entry
< NPADKEYS
)
386 (void) printf("%s", padkeys
[entry
]);
388 (void) printf("%#4x", kio
->kio_entry
);
392 (void) printf("%#4x", kio
->kio_entry
);
398 printchar(character
, delim
)
405 (void) printf("'\\n'");
409 (void) printf("'\\t'");
413 (void) printf("'\\b'");
417 (void) printf("'\\r'");
421 (void) printf("'\\v'");
425 (void) printf("'\\\\'");
429 if (isprint(character
)) {
430 if (character
== delim
)
431 (void) printf("'\\'");
432 (void) printf("%c", character
);
435 (void) printf("^%c", character
+ 0100);
437 (void) printf("'\\%.3o'", character
);