diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-20 00:17:34 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-20 00:17:34 +0000 |
commit | aa7a888e423fc85daa8af0ac3aabe8fc7af86312 (patch) | |
tree | 9eb65800fef6933a416ee2bc3a57610bbc205136 | |
parent | 85ff862753be5b7b5d3855681f9234c131659b8a (diff) | |
download | busybox-w32-aa7a888e423fc85daa8af0ac3aabe8fc7af86312.tar.gz busybox-w32-aa7a888e423fc85daa8af0ac3aabe8fc7af86312.tar.bz2 busybox-w32-aa7a888e423fc85daa8af0ac3aabe8fc7af86312.zip |
kbd_mode: new applet by Loïc Grenié <loic.grenie@gmail.com>
kbd_mode_main - 189 +189
packed_usage 22745 22833 +88
applets 3132 3144 +12
static.opts 7 12 +5
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/0 up/down: 294/0) Total: 294 bytes
text data bss dec hex filename
777210 1000 9532 787742 c051e busybox_old
777575 1000 9532 788107 c068b busybox_unstripped
-rw-r--r-- | console-tools/Config.in | 6 | ||||
-rw-r--r-- | console-tools/Kbuild | 1 | ||||
-rw-r--r-- | console-tools/kbd_mode.c | 71 | ||||
-rw-r--r-- | include/applets.h | 1 | ||||
-rw-r--r-- | include/usage.h | 10 | ||||
-rw-r--r-- | libbb/get_console.c | 2 |
6 files changed, 90 insertions, 1 deletions
diff --git a/console-tools/Config.in b/console-tools/Config.in index f82d4ce13..bd9dfb381 100644 --- a/console-tools/Config.in +++ b/console-tools/Config.in | |||
@@ -31,6 +31,12 @@ config DUMPKMAP | |||
31 | This program dumps the kernel's keyboard translation table to | 31 | This program dumps the kernel's keyboard translation table to |
32 | stdout, in binary format. You can then use loadkmap to load it. | 32 | stdout, in binary format. You can then use loadkmap to load it. |
33 | 33 | ||
34 | config KBD_MODE | ||
35 | bool "kbd_mode" | ||
36 | default n | ||
37 | help | ||
38 | This program reports and sets keyboard mode. | ||
39 | |||
34 | config LOADFONT | 40 | config LOADFONT |
35 | bool "loadfont" | 41 | bool "loadfont" |
36 | default n | 42 | default n |
diff --git a/console-tools/Kbuild b/console-tools/Kbuild index a55bc087c..cf3825ec6 100644 --- a/console-tools/Kbuild +++ b/console-tools/Kbuild | |||
@@ -10,6 +10,7 @@ lib-$(CONFIG_CLEAR) += clear.o | |||
10 | lib-$(CONFIG_DEALLOCVT) += deallocvt.o | 10 | lib-$(CONFIG_DEALLOCVT) += deallocvt.o |
11 | lib-$(CONFIG_DUMPKMAP) += dumpkmap.o | 11 | lib-$(CONFIG_DUMPKMAP) += dumpkmap.o |
12 | lib-$(CONFIG_SETCONSOLE) += setconsole.o | 12 | lib-$(CONFIG_SETCONSOLE) += setconsole.o |
13 | lib-$(CONFIG_KBD_MODE) += kbd_mode.o | ||
13 | lib-$(CONFIG_LOADFONT) += loadfont.o | 14 | lib-$(CONFIG_LOADFONT) += loadfont.o |
14 | lib-$(CONFIG_LOADKMAP) += loadkmap.o | 15 | lib-$(CONFIG_LOADKMAP) += loadkmap.o |
15 | lib-$(CONFIG_OPENVT) += openvt.o | 16 | lib-$(CONFIG_OPENVT) += openvt.o |
diff --git a/console-tools/kbd_mode.c b/console-tools/kbd_mode.c new file mode 100644 index 000000000..0000ea180 --- /dev/null +++ b/console-tools/kbd_mode.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Mini loadkmap implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2007 Loïc Grenié <loic.grenie@gmail.com> | ||
6 | * written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from | ||
7 | * console-utils v0.2.3, licensed under GNU GPLv2 | ||
8 | * | ||
9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <getopt.h> | ||
14 | #include "libbb.h" | ||
15 | #include <linux/kd.h> | ||
16 | |||
17 | int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
18 | int kbd_mode_main(int argc, char **argv) | ||
19 | { | ||
20 | static const char opts[] = "saku"; | ||
21 | |||
22 | const char *opt = argv[1]; | ||
23 | const char *p; | ||
24 | int fd; | ||
25 | |||
26 | fd = get_console_fd(); | ||
27 | if (fd < 0) /* get_console_fd() already complained */ | ||
28 | return EXIT_FAILURE; | ||
29 | |||
30 | if (opt == NULL) { | ||
31 | /* No arg */ | ||
32 | const char *msg = "unknown"; | ||
33 | int mode; | ||
34 | |||
35 | ioctl(fd, KDGKBMODE, &mode); | ||
36 | switch(mode) { | ||
37 | case K_RAW: | ||
38 | msg = "raw (scancode)"; | ||
39 | break; | ||
40 | case K_XLATE: | ||
41 | msg = "default (ASCII)"; | ||
42 | break; | ||
43 | case K_MEDIUMRAW: | ||
44 | msg = "mediumraw (keycode)"; | ||
45 | break; | ||
46 | case K_UNICODE: | ||
47 | msg = "Unicode (UTF-8)"; | ||
48 | break; | ||
49 | } | ||
50 | printf("The keyboard is in %s mode\n", msg); | ||
51 | } | ||
52 | else if (argc > 2 /* more than 1 arg */ | ||
53 | || *opt != '-' /* not an option */ | ||
54 | || (p = strchr(opts, opt[1])) == NULL /* not an option we expect */ | ||
55 | || opt[2] != '\0' /* more than one option char */ | ||
56 | ) { | ||
57 | bb_show_usage(); | ||
58 | /* return EXIT_FAILURE; - not reached */ | ||
59 | } | ||
60 | else { | ||
61 | #if K_RAW != 0 || K_XLATE != 1 || K_MEDIUMRAW != 2 || K_UNICODE != 3 | ||
62 | #error kbd_mode must be changed | ||
63 | #endif | ||
64 | /* The options are in the order of the various K_xxx */ | ||
65 | ioctl(fd, KDSKBMODE, p - opts); | ||
66 | } | ||
67 | |||
68 | if (ENABLE_FEATURE_CLEAN_UP) | ||
69 | close(fd); | ||
70 | return EXIT_SUCCESS; | ||
71 | } | ||
diff --git a/include/applets.h b/include/applets.h index 5b64e3a5a..587ccbf51 100644 --- a/include/applets.h +++ b/include/applets.h | |||
@@ -202,6 +202,7 @@ USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER)) | |||
202 | USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER)) | 202 | USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER)) |
203 | USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER)) | 203 | USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER)) |
204 | USE_IPTUNNEL(APPLET(iptunnel, _BB_DIR_BIN, _BB_SUID_NEVER)) | 204 | USE_IPTUNNEL(APPLET(iptunnel, _BB_DIR_BIN, _BB_SUID_NEVER)) |
205 | USE_KBD_MODE(APPLET(kbd_mode, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | ||
205 | USE_KILL(APPLET(kill, _BB_DIR_BIN, _BB_SUID_NEVER)) | 206 | USE_KILL(APPLET(kill, _BB_DIR_BIN, _BB_SUID_NEVER)) |
206 | USE_KILLALL(APPLET_ODDNAME(killall, kill, _BB_DIR_USR_BIN, _BB_SUID_NEVER, killall)) | 207 | USE_KILLALL(APPLET_ODDNAME(killall, kill, _BB_DIR_USR_BIN, _BB_SUID_NEVER, killall)) |
207 | USE_KILLALL5(APPLET_ODDNAME(killall5, kill, _BB_DIR_USR_BIN, _BB_SUID_NEVER, killall5)) | 208 | USE_KILLALL5(APPLET_ODDNAME(killall5, kill, _BB_DIR_USR_BIN, _BB_SUID_NEVER, killall5)) |
diff --git a/include/usage.h b/include/usage.h index d9a6ae729..8f0a13c32 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -1805,6 +1805,16 @@ | |||
1805 | " [[i|o]seq] [[i|o]key KEY] [[i|o]csum]\n" \ | 1805 | " [[i|o]seq] [[i|o]key KEY] [[i|o]csum]\n" \ |
1806 | " [ttl TTL] [tos TOS] [[no]pmtudisc] [dev PHYS_DEV]" | 1806 | " [ttl TTL] [tos TOS] [[no]pmtudisc] [dev PHYS_DEV]" |
1807 | 1807 | ||
1808 | #define kbd_mode_trivial_usage \ | ||
1809 | "[-a|k|s|u]" | ||
1810 | #define kbd_mode_full_usage \ | ||
1811 | "Report or set the keyboard mode" \ | ||
1812 | "\n\nOptions set mode:\n" \ | ||
1813 | " -a Default (ASCII)\n" \ | ||
1814 | " -k Medium-raw (keyboard)\n" \ | ||
1815 | " -s Raw (scancode)\n" \ | ||
1816 | " -u Unicode (utf-8)" | ||
1817 | |||
1808 | #define kill_trivial_usage \ | 1818 | #define kill_trivial_usage \ |
1809 | "[-l] [-signal] process-id [process-id ...]" | 1819 | "[-l] [-signal] process-id [process-id ...]" |
1810 | #define kill_full_usage \ | 1820 | #define kill_full_usage \ |
diff --git a/libbb/get_console.c b/libbb/get_console.c index b12951823..0da27b1e2 100644 --- a/libbb/get_console.c +++ b/libbb/get_console.c | |||
@@ -67,6 +67,6 @@ int get_console_fd(void) | |||
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | bb_error_msg("cannot get file descriptor referring to console"); | 70 | bb_error_msg("can't open console"); |
71 | return fd; /* total failure */ | 71 | return fd; /* total failure */ |
72 | } | 72 | } |