Obsolete VTE pre-2.91 ABI
[oi-userland.git] / components / x11 / kbd_mode / src / kbd_mode.c
blob691ac0b29b2658b570ea9901705e2f3b86e43b30
1 /* $XConsortium: kbd_mode.c,v 4.6 94/04/17 20:29:33 kaleb Exp $ */
2 /* Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 * kbd_mode: set keyboard encoding mode
28 #include <sys/types.h>
29 #include <sys/file.h>
30 #include <unistd.h>
31 #include <fcntl.h>
32 #include <sys/kbio.h>
33 #include <sys/kbd.h>
34 #include <stdio.h>
35 #include <stdlib.h>
37 static void die(const char *);
38 static void usage(void);
39 static int kbd_fd;
41 int
42 main(int argc, char** argv)
44 int code = 0, translate, direct = -1;
45 char led;
46 int click;
48 if ((kbd_fd = open("/dev/kbd", O_RDONLY, 0)) < 0) {
49 die("Couldn't open /dev/kbd");
51 argc--; argv++;
52 if (argc-- && **argv == '-') {
53 code = *(++*argv);
54 } else {
55 usage();
57 switch (code) {
58 case 'a':
59 case 'A':
60 translate = TR_ASCII;
61 direct = 0;
62 break;
63 case 'e':
64 case 'E':
65 translate = TR_EVENT;
66 break;
67 case 'n':
68 case 'N':
69 translate = TR_NONE;
70 break;
71 case 'u':
72 case 'U':
73 translate = TR_UNTRANS_EVENT;
74 break;
75 default:
76 usage();
78 #ifdef KIOCSLED
79 led = 0;
80 if (ioctl(kbd_fd, KIOCSLED, &led))
81 die("Couldn't set LEDs");
82 #endif
83 #ifdef KIOCCMD
84 click = KBD_CMD_NOCLICK;
85 if (ioctl(kbd_fd, KIOCCMD, &click))
86 die("Couldn't set click");
87 #endif
88 if (ioctl(kbd_fd, KIOCTRANS, (caddr_t) &translate))
89 die("Couldn't set translation");
90 if (direct != -1 && ioctl(kbd_fd, KIOCSDIRECT, (caddr_t) &direct))
91 die("Couldn't set redirect");
92 return 0;
95 static void
96 die(const char *msg)
98 fprintf(stderr, "%s\n", msg);
99 exit(1);
102 static void
103 usage(void)
105 int translate;
107 if (ioctl(kbd_fd, KIOCGTRANS, (caddr_t) &translate)) {
108 die("Couldn't inquire current translation");
110 fprintf(stderr, "kbd_mode {-a | -e | -n | -u }\n");
111 fprintf(stderr, "\tfor ascii, encoded (normal) SunView events,\n");
112 fprintf(stderr, " \tnon-encoded, or unencoded SunView events, resp.\n");
113 fprintf(stderr, "Current mode is %s.\n",
114 ( translate == 0 ? "n (non-translated bytes)" :
115 ( translate == 1 ? "a (ascii bytes)" :
116 ( translate == 2 ? "e (encoded events)" :
117 /* translate == 3 */ "u (unencoded events)"))));
118 exit(1);