diff options
Diffstat (limited to 'console-tools/kbd_mode.c')
-rw-r--r-- | console-tools/kbd_mode.c | 73 |
1 files changed, 29 insertions, 44 deletions
diff --git a/console-tools/kbd_mode.c b/console-tools/kbd_mode.c index 46ec3fd28..161495719 100644 --- a/console-tools/kbd_mode.c +++ b/console-tools/kbd_mode.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Mini loadkmap implementation for busybox | 3 | * Mini kbd_mode implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 2007 Loïc Grenié <loic.grenie@gmail.com> | 5 | * Copyright (C) 2007 Loïc Grenié <loic.grenie@gmail.com> |
6 | * written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from | 6 | * written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from |
@@ -14,54 +14,39 @@ | |||
14 | #include <linux/kd.h> | 14 | #include <linux/kd.h> |
15 | 15 | ||
16 | int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 16 | int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
17 | int kbd_mode_main(int argc, char **argv) | 17 | int kbd_mode_main(int ATTRIBUTE_UNUSED argc, char **argv) |
18 | { | 18 | { |
19 | static const char opts[] = "saku"; | ||
20 | |||
21 | const char *opt = argv[1]; | ||
22 | const char *p; | ||
23 | int fd; | 19 | int fd; |
24 | 20 | unsigned opt; | |
21 | enum { | ||
22 | SCANCODE = (1<<0), | ||
23 | ASCII = (1<<1), | ||
24 | MEDIUMRAW= (1<<2), | ||
25 | UNICODE = (1<<3) | ||
26 | }; | ||
27 | static const char KD_xxx[] ALIGN1 = "saku"; | ||
28 | opt = getopt32(argv, KD_xxx); | ||
25 | fd = get_console_fd(); | 29 | fd = get_console_fd(); |
26 | if (fd < 0) /* get_console_fd() already complained */ | 30 | /* if (fd < 0) |
27 | return EXIT_FAILURE; | 31 | return EXIT_FAILURE; |
32 | */ | ||
33 | if (!opt) { /* print current setting */ | ||
34 | const char *mode = "unknown"; | ||
35 | int m; | ||
28 | 36 | ||
29 | if (opt == NULL) { | 37 | ioctl(fd, KDGKBMODE, &m); |
30 | /* No arg */ | 38 | if (m == K_RAW) |
31 | const char *msg = "unknown"; | 39 | mode = "raw (scancode)"; |
32 | int mode; | 40 | else if (m == K_XLATE) |
33 | 41 | mode = "default (ASCII)"; | |
34 | ioctl(fd, KDGKBMODE, &mode); | 42 | else if (m == K_MEDIUMRAW) |
35 | switch(mode) { | 43 | mode = "mediumraw (keycode)"; |
36 | case K_RAW: | 44 | else if (m == K_UNICODE) |
37 | msg = "raw (scancode)"; | 45 | mode = "Unicode (UTF-8)"; |
38 | break; | 46 | printf("The keyboard is in %s mode\n", mode); |
39 | case K_XLATE: | 47 | } else { |
40 | msg = "default (ASCII)"; | 48 | opt = opt & UNICODE ? 3 : opt >> 1; |
41 | break; | 49 | xioctl(fd, KDSKBMODE, &opt); |
42 | case K_MEDIUMRAW: | ||
43 | msg = "mediumraw (keycode)"; | ||
44 | break; | ||
45 | case K_UNICODE: | ||
46 | msg = "Unicode (UTF-8)"; | ||
47 | break; | ||
48 | } | ||
49 | printf("The keyboard is in %s mode\n", msg); | ||
50 | } | ||
51 | else if (argc > 2 /* more than 1 arg */ | ||
52 | || *opt != '-' /* not an option */ | ||
53 | || (p = strchr(opts, opt[1])) == NULL /* not an option we expect */ | ||
54 | || opt[2] != '\0' /* more than one option char */ | ||
55 | ) { | ||
56 | bb_show_usage(); | ||
57 | /* return EXIT_FAILURE; - not reached */ | ||
58 | } | ||
59 | else { | ||
60 | #if K_RAW != 0 || K_XLATE != 1 || K_MEDIUMRAW != 2 || K_UNICODE != 3 | ||
61 | #error kbd_mode must be changed | ||
62 | #endif | ||
63 | /* The options are in the order of the various K_xxx */ | ||
64 | ioctl(fd, KDSKBMODE, p - opts); | ||
65 | } | 50 | } |
66 | 51 | ||
67 | if (ENABLE_FEATURE_CLEAN_UP) | 52 | if (ENABLE_FEATURE_CLEAN_UP) |