First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / utils / kbd_mode / sun-kbd_mode.c
blobf2802a6b880e84bd6a039a45591df951d11225d2
1 /************************************************************
2 Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
4 All Rights Reserved
6 Permission to use, copy, modify, and distribute this
7 software and its documentation for any purpose and without
8 fee is hereby granted, provided that the above copyright no-
9 tice appear in all copies and that both that copyright no-
10 tice and this permission notice appear in supporting docu-
11 mentation, and that the names of Sun or The Open Group
12 not be used in advertising or publicity pertaining to
13 distribution of the software without specific prior
14 written permission. Sun and The Open Group make no
15 representations about the suitability of this software for
16 any purpose. It is provided "as is" without any express or
17 implied warranty.
19 SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
20 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
21 NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI-
22 ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
23 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
24 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
25 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
26 THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 ********************************************************/
31 static char sccsid[] = "@(#)kbd_mode.c 7.1 87/04/13";
35 * Copyright 1986 by Sun Microsystems, Inc.
37 * kbd_mode: set keyboard encoding mode
40 #include <sys/types.h>
41 #include <sys/file.h>
42 #include <sys/ioctl.h>
43 #if defined(SVR4) || defined(__SVR4) || defined(__bsdi__)
44 #include <fcntl.h>
45 #ifndef __bsdi__
46 #include <sys/kbio.h>
47 #include <sys/kbd.h>
48 #else
49 #include <unistd.h>
50 #include </sys/sparc/dev/kbio.h>
51 #include </sys/sparc/dev/kbd.h>
52 #endif
53 #else
54 #ifndef CSRG_BASED
55 #include <sundev/kbio.h>
56 #include <sundev/kbd.h>
57 #else
58 #include <machine/kbio.h>
59 #include <machine/kbd.h>
60 #endif
61 #endif
62 #include <stdio.h>
63 #include <stdlib.h>
64 #include <unistd.h>
66 static void die(char*);
67 static void usage(void);
68 static int kbd_fd;
70 int
71 main(argc, argv)
72 int argc;
73 char** argv;
75 int code = 0, translate, direct = -1;
76 char led;
77 int click;
79 if ((kbd_fd = open("/dev/kbd", O_RDONLY, 0)) < 0) {
80 die("Couldn't open /dev/kbd");
82 argc--; argv++;
83 if (argc-- && **argv == '-') {
84 code = *(++*argv);
85 } else {
86 usage();
88 switch (code) {
89 case 'a':
90 case 'A':
91 translate = TR_ASCII;
92 direct = 0;
93 break;
94 case 'e':
95 case 'E':
96 translate = TR_EVENT;
97 break;
98 case 'n':
99 case 'N':
100 translate = TR_NONE;
101 break;
102 case 'u':
103 case 'U':
104 translate = TR_UNTRANS_EVENT;
105 break;
106 default:
107 usage();
109 #ifdef KIOCSLED
110 led = 0;
111 if (ioctl(kbd_fd, KIOCSLED, &led))
112 die("Couldn't set LEDs");
113 #endif
114 #ifdef KIOCCMD
115 click = KBD_CMD_NOCLICK;
116 if (ioctl(kbd_fd, KIOCCMD, &click))
117 die("Couldn't set click");
118 #endif
119 if (ioctl(kbd_fd, KIOCTRANS, (caddr_t) &translate))
120 die("Couldn't set translation");
121 if (direct != -1 && ioctl(kbd_fd, KIOCSDIRECT, (caddr_t) &direct))
122 die("Couldn't set redirect");
123 return 0;
126 static void
127 die(char *msg)
129 fprintf(stderr, "%s\n", msg);
130 exit(1);
133 static void
134 usage(void)
136 int translate;
138 if (ioctl(kbd_fd, KIOCGTRANS, (caddr_t) &translate)) {
139 die("Couldn't inquire current translation");
141 fprintf(stderr, "kbd_mode {-a | -e | -n | -u }\n");
142 fprintf(stderr, "\tfor ascii, encoded (normal) SunView events,\n");
143 fprintf(stderr, " \tnon-encoded, or unencoded SunView events, resp.\n");
144 fprintf(stderr, "Current mode is %s.\n",
145 ( translate == 0 ? "n (non-translated bytes)" :
146 ( translate == 1 ? "a (ascii bytes)" :
147 ( translate == 2 ? "e (encoded events)" :
148 /* translate == 3 */ "u (unencoded events)"))));
149 exit(1);