xref: /titanic_50/usr/src/cmd/loadkeys/dumpkeys.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate #ifndef lint
23*7c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"
24*7c478bd9Sstevel@tonic-gate #endif
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1988 by Sun Microsystems, Inc.
28*7c478bd9Sstevel@tonic-gate  */
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
31*7c478bd9Sstevel@tonic-gate #include <ctype.h>
32*7c478bd9Sstevel@tonic-gate #include <stdio.h>
33*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/kbd.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/kbio.h>
36*7c478bd9Sstevel@tonic-gate #include <errno.h>
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate typedef enum {
39*7c478bd9Sstevel@tonic-gate 	SM_INVALID,	/* this shift mask is invalid for this keyboard */
40*7c478bd9Sstevel@tonic-gate 	SM_NORMAL,	/* "normal", valid shift mask */
41*7c478bd9Sstevel@tonic-gate 	SM_NUMLOCK,	/* "Num Lock" shift mask */
42*7c478bd9Sstevel@tonic-gate 	SM_UP		/* "Up" shift mask */
43*7c478bd9Sstevel@tonic-gate } smtype_t;
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate typedef struct {
46*7c478bd9Sstevel@tonic-gate 	char	*sm_name;
47*7c478bd9Sstevel@tonic-gate 	int	sm_mask;
48*7c478bd9Sstevel@tonic-gate 	smtype_t sm_type;
49*7c478bd9Sstevel@tonic-gate } smentry_t;
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate smentry_t shiftmasks[] = {
53*7c478bd9Sstevel@tonic-gate 	{ "base",	0,		SM_NORMAL },
54*7c478bd9Sstevel@tonic-gate 	{ "shift",	SHIFTMASK,	SM_NORMAL },
55*7c478bd9Sstevel@tonic-gate 	{ "caps",	CAPSMASK,	SM_NORMAL },
56*7c478bd9Sstevel@tonic-gate 	{ "ctrl",	CTRLMASK,	SM_NORMAL },
57*7c478bd9Sstevel@tonic-gate 	{ "altg",	ALTGRAPHMASK,	SM_NORMAL },
58*7c478bd9Sstevel@tonic-gate 	{ "numl",	NUMLOCKMASK,	SM_NUMLOCK },
59*7c478bd9Sstevel@tonic-gate 	{ "up",		UPMASK,		SM_UP },
60*7c478bd9Sstevel@tonic-gate };
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate #define	NSHIFTS	(sizeof (shiftmasks) / sizeof (shiftmasks[0]))
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate static void	printentry(struct kiockeymap *kio);
65*7c478bd9Sstevel@tonic-gate static void	printchar(int character, int delim);
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
68*7c478bd9Sstevel@tonic-gate int
main(argc,argv)69*7c478bd9Sstevel@tonic-gate main(argc, argv)
70*7c478bd9Sstevel@tonic-gate 	int argc;
71*7c478bd9Sstevel@tonic-gate 	char **argv;
72*7c478bd9Sstevel@tonic-gate {
73*7c478bd9Sstevel@tonic-gate 	register int kbdfd;
74*7c478bd9Sstevel@tonic-gate 	register int keystation;
75*7c478bd9Sstevel@tonic-gate 	register int shift;
76*7c478bd9Sstevel@tonic-gate 	int ktype;
77*7c478bd9Sstevel@tonic-gate 	struct kiockeymap keyentry[NSHIFTS];
78*7c478bd9Sstevel@tonic-gate 	register int allsame;
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate 	if ((kbdfd = open("/dev/kbd", O_WRONLY)) < 0) {
81*7c478bd9Sstevel@tonic-gate 		perror("dumpkeys: /dev/kbd");
82*7c478bd9Sstevel@tonic-gate 		return (1);
83*7c478bd9Sstevel@tonic-gate 	}
84*7c478bd9Sstevel@tonic-gate 	if (ioctl(kbdfd, KIOCTYPE, &ktype) < 0) {
85*7c478bd9Sstevel@tonic-gate 		perror("dumpkeys: ioctl(KIOCTYPE)");
86*7c478bd9Sstevel@tonic-gate 		return (1);
87*7c478bd9Sstevel@tonic-gate 	}
88*7c478bd9Sstevel@tonic-gate 	/* if no keyboard detected, or ascii terminal, exit silently */
89*7c478bd9Sstevel@tonic-gate 	if (ktype == KB_ASCII || ktype < 0)
90*7c478bd9Sstevel@tonic-gate 		exit(0);
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 	/*
93*7c478bd9Sstevel@tonic-gate 	 * See which shift masks are valid for this keyboard.
94*7c478bd9Sstevel@tonic-gate 	 * We do that by trying to get the entry for keystation 0 and that
95*7c478bd9Sstevel@tonic-gate 	 * shift mask; if the "ioctl" fails, we assume it's because the shift
96*7c478bd9Sstevel@tonic-gate 	 * mask is invalid.
97*7c478bd9Sstevel@tonic-gate 	 */
98*7c478bd9Sstevel@tonic-gate 	for (shift = 0; shift < NSHIFTS; shift++) {
99*7c478bd9Sstevel@tonic-gate 		keyentry[shift].kio_tablemask =
100*7c478bd9Sstevel@tonic-gate 		    shiftmasks[shift].sm_mask;
101*7c478bd9Sstevel@tonic-gate 		keyentry[shift].kio_station = 0;
102*7c478bd9Sstevel@tonic-gate 		if (ioctl(kbdfd, KIOCGKEY, &keyentry[shift]) < 0)
103*7c478bd9Sstevel@tonic-gate 			shiftmasks[shift].sm_type = SM_INVALID;
104*7c478bd9Sstevel@tonic-gate 	}
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate 	/*
107*7c478bd9Sstevel@tonic-gate 	 * Loop until we get an EINVAL, so we don't have to know
108*7c478bd9Sstevel@tonic-gate 	 * how big the table might be.
109*7c478bd9Sstevel@tonic-gate 	 */
110*7c478bd9Sstevel@tonic-gate 	for (keystation = 0; ; keystation++) {
111*7c478bd9Sstevel@tonic-gate 		for (shift = 0; shift < NSHIFTS; shift++) {
112*7c478bd9Sstevel@tonic-gate 			if (shiftmasks[shift].sm_type != SM_INVALID) {
113*7c478bd9Sstevel@tonic-gate 				keyentry[shift].kio_tablemask =
114*7c478bd9Sstevel@tonic-gate 				    shiftmasks[shift].sm_mask;
115*7c478bd9Sstevel@tonic-gate 				keyentry[shift].kio_station = keystation;
116*7c478bd9Sstevel@tonic-gate 				if (ioctl(kbdfd, KIOCGKEY,
117*7c478bd9Sstevel@tonic-gate 				    &keyentry[shift]) < 0) {
118*7c478bd9Sstevel@tonic-gate 					if (errno == EINVAL)
119*7c478bd9Sstevel@tonic-gate 						return (0);
120*7c478bd9Sstevel@tonic-gate 					perror("dumpkeys: KIOCGKEY");
121*7c478bd9Sstevel@tonic-gate 					return (1);
122*7c478bd9Sstevel@tonic-gate 				}
123*7c478bd9Sstevel@tonic-gate 			}
124*7c478bd9Sstevel@tonic-gate 		}
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 		(void) printf("key %d\t", keystation);
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 		/*
129*7c478bd9Sstevel@tonic-gate 		 * See if all the "normal" entries (all but the Num Lock and Up
130*7c478bd9Sstevel@tonic-gate 		 * entries) are the same.
131*7c478bd9Sstevel@tonic-gate 		 */
132*7c478bd9Sstevel@tonic-gate 		allsame = 1;
133*7c478bd9Sstevel@tonic-gate 		for (shift = 1; shift < NSHIFTS; shift++) {
134*7c478bd9Sstevel@tonic-gate 			if (shiftmasks[shift].sm_type == SM_NORMAL) {
135*7c478bd9Sstevel@tonic-gate 				if (keyentry[0].kio_entry
136*7c478bd9Sstevel@tonic-gate 				    != keyentry[shift].kio_entry) {
137*7c478bd9Sstevel@tonic-gate 					allsame = 0;
138*7c478bd9Sstevel@tonic-gate 					break;
139*7c478bd9Sstevel@tonic-gate 				}
140*7c478bd9Sstevel@tonic-gate 			}
141*7c478bd9Sstevel@tonic-gate 		}
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 		if (allsame) {
144*7c478bd9Sstevel@tonic-gate 			/*
145*7c478bd9Sstevel@tonic-gate 			 * All of the "normal" entries are the same; just print
146*7c478bd9Sstevel@tonic-gate 			 * "all".
147*7c478bd9Sstevel@tonic-gate 			 */
148*7c478bd9Sstevel@tonic-gate 			(void) printf(" all ");
149*7c478bd9Sstevel@tonic-gate 			printentry(&keyentry[0]);
150*7c478bd9Sstevel@tonic-gate 		} else {
151*7c478bd9Sstevel@tonic-gate 			/*
152*7c478bd9Sstevel@tonic-gate 			 * The normal entries aren't all the same; print them
153*7c478bd9Sstevel@tonic-gate 			 * individually.
154*7c478bd9Sstevel@tonic-gate 			 */
155*7c478bd9Sstevel@tonic-gate 			for (shift = 0; shift < NSHIFTS; shift++) {
156*7c478bd9Sstevel@tonic-gate 				if (shiftmasks[shift].sm_type == SM_NORMAL) {
157*7c478bd9Sstevel@tonic-gate 					(void) printf(" %s ",
158*7c478bd9Sstevel@tonic-gate 					    shiftmasks[shift].sm_name);
159*7c478bd9Sstevel@tonic-gate 					printentry(&keyentry[shift]);
160*7c478bd9Sstevel@tonic-gate 				}
161*7c478bd9Sstevel@tonic-gate 			}
162*7c478bd9Sstevel@tonic-gate 		}
163*7c478bd9Sstevel@tonic-gate 		if (allsame && keyentry[0].kio_entry == HOLE) {
164*7c478bd9Sstevel@tonic-gate 			/*
165*7c478bd9Sstevel@tonic-gate 			 * This key is a "hole"; if either the Num Lock or Up
166*7c478bd9Sstevel@tonic-gate 			 * entry isn't a "hole", print it.
167*7c478bd9Sstevel@tonic-gate 			 */
168*7c478bd9Sstevel@tonic-gate 			for (shift = 0; shift < NSHIFTS; shift++) {
169*7c478bd9Sstevel@tonic-gate 				switch (shiftmasks[shift].sm_type) {
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate 				case SM_NUMLOCK:
172*7c478bd9Sstevel@tonic-gate 				case SM_UP:
173*7c478bd9Sstevel@tonic-gate 					if (keyentry[shift].kio_entry
174*7c478bd9Sstevel@tonic-gate 					    != HOLE) {
175*7c478bd9Sstevel@tonic-gate 						(void) printf(" %s ",
176*7c478bd9Sstevel@tonic-gate 						    shiftmasks[shift].sm_name);
177*7c478bd9Sstevel@tonic-gate 						printentry(&keyentry[shift]);
178*7c478bd9Sstevel@tonic-gate 					}
179*7c478bd9Sstevel@tonic-gate 					break;
180*7c478bd9Sstevel@tonic-gate 				}
181*7c478bd9Sstevel@tonic-gate 			}
182*7c478bd9Sstevel@tonic-gate 		} else {
183*7c478bd9Sstevel@tonic-gate 			/*
184*7c478bd9Sstevel@tonic-gate 			 * This entry isn't a "hole"; if the Num Lock entry
185*7c478bd9Sstevel@tonic-gate 			 * isn't NONL (i.e, if Num Lock actually does
186*7c478bd9Sstevel@tonic-gate 			 * something) print it, and if the Up entry isn't NOP
187*7c478bd9Sstevel@tonic-gate 			 * (i.e., if up transitions on this key actually do
188*7c478bd9Sstevel@tonic-gate 			 * something) print it.
189*7c478bd9Sstevel@tonic-gate 			 */
190*7c478bd9Sstevel@tonic-gate 			for (shift = 0; shift < NSHIFTS; shift++) {
191*7c478bd9Sstevel@tonic-gate 				switch (shiftmasks[shift].sm_type) {
192*7c478bd9Sstevel@tonic-gate 
193*7c478bd9Sstevel@tonic-gate 				case SM_NUMLOCK:
194*7c478bd9Sstevel@tonic-gate 					if (keyentry[shift].kio_entry
195*7c478bd9Sstevel@tonic-gate 					    != NONL) {
196*7c478bd9Sstevel@tonic-gate 						(void) printf(" %s ",
197*7c478bd9Sstevel@tonic-gate 						    shiftmasks[shift].sm_name);
198*7c478bd9Sstevel@tonic-gate 						printentry(&keyentry[shift]);
199*7c478bd9Sstevel@tonic-gate 					}
200*7c478bd9Sstevel@tonic-gate 					break;
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate 				case SM_UP:
203*7c478bd9Sstevel@tonic-gate 					if (keyentry[shift].kio_entry
204*7c478bd9Sstevel@tonic-gate 					    != NOP) {
205*7c478bd9Sstevel@tonic-gate 						(void) printf(" %s ",
206*7c478bd9Sstevel@tonic-gate 						    shiftmasks[shift].sm_name);
207*7c478bd9Sstevel@tonic-gate 						printentry(&keyentry[shift]);
208*7c478bd9Sstevel@tonic-gate 					}
209*7c478bd9Sstevel@tonic-gate 					break;
210*7c478bd9Sstevel@tonic-gate 				}
211*7c478bd9Sstevel@tonic-gate 			}
212*7c478bd9Sstevel@tonic-gate 		}
213*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
214*7c478bd9Sstevel@tonic-gate 	}
215*7c478bd9Sstevel@tonic-gate }
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate static char *shiftkeys[] = {
218*7c478bd9Sstevel@tonic-gate 	"capslock",
219*7c478bd9Sstevel@tonic-gate 	"shiftlock",
220*7c478bd9Sstevel@tonic-gate 	"leftshift",
221*7c478bd9Sstevel@tonic-gate 	"rightshift",
222*7c478bd9Sstevel@tonic-gate 	"leftctrl",
223*7c478bd9Sstevel@tonic-gate 	"rightctrl",
224*7c478bd9Sstevel@tonic-gate 	"meta",			/* not used */
225*7c478bd9Sstevel@tonic-gate 	"top",			/* not used */
226*7c478bd9Sstevel@tonic-gate 	"cmd",			/* reserved */
227*7c478bd9Sstevel@tonic-gate 	"altgraph",
228*7c478bd9Sstevel@tonic-gate 	"alt",
229*7c478bd9Sstevel@tonic-gate 	"numlock",
230*7c478bd9Sstevel@tonic-gate };
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate #define	NSHIFTKEYS	(sizeof (shiftkeys) / sizeof (shiftkeys[0]))
233*7c478bd9Sstevel@tonic-gate 
234*7c478bd9Sstevel@tonic-gate static char *buckybits[] = {
235*7c478bd9Sstevel@tonic-gate 	"metabit",
236*7c478bd9Sstevel@tonic-gate 	"systembit",
237*7c478bd9Sstevel@tonic-gate };
238*7c478bd9Sstevel@tonic-gate 
239*7c478bd9Sstevel@tonic-gate #define	NBUCKYBITS	(sizeof (buckybits) / sizeof (buckybits[0]))
240*7c478bd9Sstevel@tonic-gate 
241*7c478bd9Sstevel@tonic-gate static char *funnies[] = {
242*7c478bd9Sstevel@tonic-gate 	"nop",
243*7c478bd9Sstevel@tonic-gate 	"oops",
244*7c478bd9Sstevel@tonic-gate 	"hole",
245*7c478bd9Sstevel@tonic-gate 	"reset",
246*7c478bd9Sstevel@tonic-gate 	"error",
247*7c478bd9Sstevel@tonic-gate 	"idle",
248*7c478bd9Sstevel@tonic-gate 	"compose",
249*7c478bd9Sstevel@tonic-gate 	"nonl",
250*7c478bd9Sstevel@tonic-gate };
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate #define	NFUNNIES	(sizeof (funnies) / sizeof (funnies[0]))
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate static char *fa_class[] = {
255*7c478bd9Sstevel@tonic-gate 	"fa_umlaut",
256*7c478bd9Sstevel@tonic-gate 	"fa_cflex",
257*7c478bd9Sstevel@tonic-gate 	"fa_tilde",
258*7c478bd9Sstevel@tonic-gate 	"fa_cedilla",
259*7c478bd9Sstevel@tonic-gate 	"fa_acute",
260*7c478bd9Sstevel@tonic-gate 	"fa_grave",
261*7c478bd9Sstevel@tonic-gate };
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate #define	NFA_CLASS	(sizeof (fa_class) / sizeof (fa_class[0]))
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate typedef struct {
266*7c478bd9Sstevel@tonic-gate 	char	*string;
267*7c478bd9Sstevel@tonic-gate 	char	*name;
268*7c478bd9Sstevel@tonic-gate } builtin_string_t;
269*7c478bd9Sstevel@tonic-gate 
270*7c478bd9Sstevel@tonic-gate builtin_string_t builtin_strings[] = {
271*7c478bd9Sstevel@tonic-gate 	{ "\033[H",	"homearrow" },
272*7c478bd9Sstevel@tonic-gate 	{ "\033[A",	"uparrow" },
273*7c478bd9Sstevel@tonic-gate 	{ "\033[B",	"downarrow" },
274*7c478bd9Sstevel@tonic-gate 	{ "\033[D",	"leftarrow" },
275*7c478bd9Sstevel@tonic-gate 	{ "\033[C",	"rightarrow" },
276*7c478bd9Sstevel@tonic-gate };
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate #define	NBUILTIN_STRINGS	(sizeof (builtin_strings) / \
279*7c478bd9Sstevel@tonic-gate 					sizeof (builtin_strings[0]))
280*7c478bd9Sstevel@tonic-gate 
281*7c478bd9Sstevel@tonic-gate static char	*fkeysets[] = {
282*7c478bd9Sstevel@tonic-gate 	"lf",
283*7c478bd9Sstevel@tonic-gate 	"rf",
284*7c478bd9Sstevel@tonic-gate 	"tf",
285*7c478bd9Sstevel@tonic-gate 	"bf",
286*7c478bd9Sstevel@tonic-gate };
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate #define	NFKEYSETS	(sizeof (fkeysets) / sizeof (fkeysets[0]))
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate static char	*padkeys[] = {
291*7c478bd9Sstevel@tonic-gate 	"padequal",
292*7c478bd9Sstevel@tonic-gate 	"padslash",
293*7c478bd9Sstevel@tonic-gate 	"padstar",
294*7c478bd9Sstevel@tonic-gate 	"padminus",
295*7c478bd9Sstevel@tonic-gate 	"padsep",
296*7c478bd9Sstevel@tonic-gate 	"pad7",
297*7c478bd9Sstevel@tonic-gate 	"pad8",
298*7c478bd9Sstevel@tonic-gate 	"pad9",
299*7c478bd9Sstevel@tonic-gate 	"padplus",
300*7c478bd9Sstevel@tonic-gate 	"pad4",
301*7c478bd9Sstevel@tonic-gate 	"pad5",
302*7c478bd9Sstevel@tonic-gate 	"pad6",
303*7c478bd9Sstevel@tonic-gate 	"pad1",
304*7c478bd9Sstevel@tonic-gate 	"pad2",
305*7c478bd9Sstevel@tonic-gate 	"pad3",
306*7c478bd9Sstevel@tonic-gate 	"pad0",
307*7c478bd9Sstevel@tonic-gate 	"paddot",
308*7c478bd9Sstevel@tonic-gate 	"padenter",
309*7c478bd9Sstevel@tonic-gate };
310*7c478bd9Sstevel@tonic-gate 
311*7c478bd9Sstevel@tonic-gate #define	NPADKEYS	(sizeof (padkeys) / sizeof (padkeys[0]))
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate static void
printentry(kio)314*7c478bd9Sstevel@tonic-gate printentry(kio)
315*7c478bd9Sstevel@tonic-gate 	register struct kiockeymap *kio;
316*7c478bd9Sstevel@tonic-gate {
317*7c478bd9Sstevel@tonic-gate 	register int entry = (kio->kio_entry & 0x1F);
318*7c478bd9Sstevel@tonic-gate 	register int fkeyset;
319*7c478bd9Sstevel@tonic-gate 	register int i;
320*7c478bd9Sstevel@tonic-gate 	register int c;
321*7c478bd9Sstevel@tonic-gate 
322*7c478bd9Sstevel@tonic-gate 	switch (kio->kio_entry >> 8) {
323*7c478bd9Sstevel@tonic-gate 
324*7c478bd9Sstevel@tonic-gate 	case 0x0:
325*7c478bd9Sstevel@tonic-gate 		if (kio->kio_entry == '"')
326*7c478bd9Sstevel@tonic-gate 			(void) printf("'\"'");	/* special case */
327*7c478bd9Sstevel@tonic-gate 		else if (kio->kio_entry == ' ')
328*7c478bd9Sstevel@tonic-gate 			(void) printf("' '");	/* special case */
329*7c478bd9Sstevel@tonic-gate 		else
330*7c478bd9Sstevel@tonic-gate 			printchar((int)kio->kio_entry, '\'');
331*7c478bd9Sstevel@tonic-gate 		break;
332*7c478bd9Sstevel@tonic-gate 
333*7c478bd9Sstevel@tonic-gate 	case SHIFTKEYS >> 8:
334*7c478bd9Sstevel@tonic-gate 		if (entry < NSHIFTKEYS)
335*7c478bd9Sstevel@tonic-gate 			(void) printf("shiftkeys+%s", shiftkeys[entry]);
336*7c478bd9Sstevel@tonic-gate 		else
337*7c478bd9Sstevel@tonic-gate 			(void) printf("%#4x", kio->kio_entry);
338*7c478bd9Sstevel@tonic-gate 		break;
339*7c478bd9Sstevel@tonic-gate 
340*7c478bd9Sstevel@tonic-gate 	case BUCKYBITS >> 8:
341*7c478bd9Sstevel@tonic-gate 		if (entry < NBUCKYBITS)
342*7c478bd9Sstevel@tonic-gate 			(void) printf("buckybits+%s", buckybits[entry]);
343*7c478bd9Sstevel@tonic-gate 		else
344*7c478bd9Sstevel@tonic-gate 			(void) printf("%#4x", kio->kio_entry);
345*7c478bd9Sstevel@tonic-gate 		break;
346*7c478bd9Sstevel@tonic-gate 
347*7c478bd9Sstevel@tonic-gate 	case FUNNY >> 8:
348*7c478bd9Sstevel@tonic-gate 		if (entry < NFUNNIES)
349*7c478bd9Sstevel@tonic-gate 			(void) printf("%s", funnies[entry]);
350*7c478bd9Sstevel@tonic-gate 		else
351*7c478bd9Sstevel@tonic-gate 			(void) printf("%#4x", kio->kio_entry);
352*7c478bd9Sstevel@tonic-gate 		break;
353*7c478bd9Sstevel@tonic-gate 
354*7c478bd9Sstevel@tonic-gate 	case FA_CLASS >> 8:
355*7c478bd9Sstevel@tonic-gate 		if (entry < NFA_CLASS)
356*7c478bd9Sstevel@tonic-gate 			(void) printf("%s", fa_class[entry]);
357*7c478bd9Sstevel@tonic-gate 		else
358*7c478bd9Sstevel@tonic-gate 			(void) printf("%#4x", kio->kio_entry);
359*7c478bd9Sstevel@tonic-gate 		break;
360*7c478bd9Sstevel@tonic-gate 
361*7c478bd9Sstevel@tonic-gate 	case STRING >> 8:
362*7c478bd9Sstevel@tonic-gate 		if (entry < NBUILTIN_STRINGS && strncmp(kio->kio_string,
363*7c478bd9Sstevel@tonic-gate 			builtin_strings[entry].string, KTAB_STRLEN) == 0)
364*7c478bd9Sstevel@tonic-gate 			(void) printf("string+%s", builtin_strings[entry].name);
365*7c478bd9Sstevel@tonic-gate 		else {
366*7c478bd9Sstevel@tonic-gate 			(void) printf("\"");
367*7c478bd9Sstevel@tonic-gate 			for (i = 0;
368*7c478bd9Sstevel@tonic-gate 			    i < KTAB_STRLEN && (c = kio->kio_string[i]) != '\0';
369*7c478bd9Sstevel@tonic-gate 			    i++)
370*7c478bd9Sstevel@tonic-gate 				printchar(c, '"');
371*7c478bd9Sstevel@tonic-gate 			(void) printf("\"");
372*7c478bd9Sstevel@tonic-gate 		}
373*7c478bd9Sstevel@tonic-gate 		break;
374*7c478bd9Sstevel@tonic-gate 
375*7c478bd9Sstevel@tonic-gate 	case FUNCKEYS >> 8:
376*7c478bd9Sstevel@tonic-gate 		fkeyset = (int)(kio->kio_entry & 0xF0) >> 4;
377*7c478bd9Sstevel@tonic-gate 		if (fkeyset < NFKEYSETS)
378*7c478bd9Sstevel@tonic-gate 			(void) printf("%s(%d)", fkeysets[fkeyset],
379*7c478bd9Sstevel@tonic-gate 					(entry&0x0F) + 1);
380*7c478bd9Sstevel@tonic-gate 		else
381*7c478bd9Sstevel@tonic-gate 			(void) printf("%#4x", kio->kio_entry);
382*7c478bd9Sstevel@tonic-gate 		break;
383*7c478bd9Sstevel@tonic-gate 
384*7c478bd9Sstevel@tonic-gate 	case PADKEYS >> 8:
385*7c478bd9Sstevel@tonic-gate 		if (entry < NPADKEYS)
386*7c478bd9Sstevel@tonic-gate 			(void) printf("%s", padkeys[entry]);
387*7c478bd9Sstevel@tonic-gate 		else
388*7c478bd9Sstevel@tonic-gate 			(void) printf("%#4x", kio->kio_entry);
389*7c478bd9Sstevel@tonic-gate 		break;
390*7c478bd9Sstevel@tonic-gate 
391*7c478bd9Sstevel@tonic-gate 	default:
392*7c478bd9Sstevel@tonic-gate 		(void) printf("%#4x", kio->kio_entry);
393*7c478bd9Sstevel@tonic-gate 		break;
394*7c478bd9Sstevel@tonic-gate 	}
395*7c478bd9Sstevel@tonic-gate }
396*7c478bd9Sstevel@tonic-gate 
397*7c478bd9Sstevel@tonic-gate static void
printchar(character,delim)398*7c478bd9Sstevel@tonic-gate printchar(character, delim)
399*7c478bd9Sstevel@tonic-gate 	int character;
400*7c478bd9Sstevel@tonic-gate 	int delim;
401*7c478bd9Sstevel@tonic-gate {
402*7c478bd9Sstevel@tonic-gate 	switch (character) {
403*7c478bd9Sstevel@tonic-gate 
404*7c478bd9Sstevel@tonic-gate 	case '\n':
405*7c478bd9Sstevel@tonic-gate 		(void) printf("'\\n'");
406*7c478bd9Sstevel@tonic-gate 		break;
407*7c478bd9Sstevel@tonic-gate 
408*7c478bd9Sstevel@tonic-gate 	case '\t':
409*7c478bd9Sstevel@tonic-gate 		(void) printf("'\\t'");
410*7c478bd9Sstevel@tonic-gate 		break;
411*7c478bd9Sstevel@tonic-gate 
412*7c478bd9Sstevel@tonic-gate 	case '\b':
413*7c478bd9Sstevel@tonic-gate 		(void) printf("'\\b'");
414*7c478bd9Sstevel@tonic-gate 		break;
415*7c478bd9Sstevel@tonic-gate 
416*7c478bd9Sstevel@tonic-gate 	case '\r':
417*7c478bd9Sstevel@tonic-gate 		(void) printf("'\\r'");
418*7c478bd9Sstevel@tonic-gate 		break;
419*7c478bd9Sstevel@tonic-gate 
420*7c478bd9Sstevel@tonic-gate 	case '\v':
421*7c478bd9Sstevel@tonic-gate 		(void) printf("'\\v'");
422*7c478bd9Sstevel@tonic-gate 		break;
423*7c478bd9Sstevel@tonic-gate 
424*7c478bd9Sstevel@tonic-gate 	case '\\':
425*7c478bd9Sstevel@tonic-gate 		(void) printf("'\\\\'");
426*7c478bd9Sstevel@tonic-gate 		break;
427*7c478bd9Sstevel@tonic-gate 
428*7c478bd9Sstevel@tonic-gate 	default:
429*7c478bd9Sstevel@tonic-gate 		if (isprint(character)) {
430*7c478bd9Sstevel@tonic-gate 			if (character == delim)
431*7c478bd9Sstevel@tonic-gate 				(void) printf("'\\'");
432*7c478bd9Sstevel@tonic-gate 			(void) printf("%c", character);
433*7c478bd9Sstevel@tonic-gate 		} else {
434*7c478bd9Sstevel@tonic-gate 			if (character < 040)
435*7c478bd9Sstevel@tonic-gate 				(void) printf("^%c", character + 0100);
436*7c478bd9Sstevel@tonic-gate 			else
437*7c478bd9Sstevel@tonic-gate 				(void) printf("'\\%.3o'", character);
438*7c478bd9Sstevel@tonic-gate 		}
439*7c478bd9Sstevel@tonic-gate 		break;
440*7c478bd9Sstevel@tonic-gate 	}
441*7c478bd9Sstevel@tonic-gate }
442