[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] Allow kbd_mode to choose tty
From:       Roy Marples <roy () marples ! name>
Date:       2008-01-30 17:56:42
Message-ID: 1201715802.4982.4.camel () uberlaptop ! marples ! name
[Download RAW message or body]

Hi

kbd_mode upstream has added the -C option so that options can be applied
to a specific tty instead of just the console. I've added this to
busybox kbd_mode applet, and hopefully cleaned up existing option
parsing a little.

I'm uncertain if I got opt_complementary right - basically all options
should conflict except for the new -C option.

Thanks

Roy

["kbd.patch" (kbd.patch)]

diff -ur busybox-1.9.0.orig/console-tools/kbd_mode.c busybox-1.9.0/console-tools/kbd_mode.c
--- busybox-1.9.0.orig/console-tools/kbd_mode.c	2007-12-21 22:00:27.000000000 +0000
+++ busybox-1.9.0/console-tools/kbd_mode.c	2008-01-30 17:55:49.000000000 +0000
@@ -17,53 +17,59 @@
 int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int kbd_mode_main(int argc, char **argv)
 {
-	static const char opts[] = "saku";
-
-	const char *opt = argv[1];
-	const char *p;
+	unsigned opt;
+	char *opt_C;
+	enum {
+		OPT_s = 1 << 0,
+		OPT_a = 1 << 1,
+		OPT_k = 1 << 2,
+		OPT_u = 1 << 3,
+		OPT_C = 1 << 4,
+	};
 	int fd;
+	int mode;
+
+	opt_complementary = "s--a:s--k:s--u:a--s:a--k:a--u:k--s:k--a:k--u:u--s:u--a:u--k";
+	opt = getopt32(argv, "sakuC:", &opt_C);
 
-	fd = get_console_fd();
+	if (opt & OPT_C)
+		fd = xopen(opt_C, O_RDWR);
+	else
+		fd = get_console_fd();
 	if (fd < 0) /* get_console_fd() already complained */
 		return EXIT_FAILURE;
 
-	if (opt == NULL) {
+	if (opt == 0 || opt == OPT_C) {
 		/* No arg */
 		const char *msg = "unknown";
-		int mode;
 
 		ioctl(fd, KDGKBMODE, &mode);
 		switch(mode) {
-		case K_RAW:
-			msg = "raw (scancode)";
-			break;
-		case K_XLATE:
-			msg = "default (ASCII)";
-			break;
-		case K_MEDIUMRAW:
-			msg = "mediumraw (keycode)";
-			break;
-		case K_UNICODE:
-			msg = "Unicode (UTF-8)";
-			break;
+			case K_RAW:
+				msg = "raw (scancode)";
+				break;
+			case K_XLATE:
+				msg = "default (ASCII)";
+				break;
+			case K_MEDIUMRAW:
+				msg = "mediumraw (keycode)";
+				break;
+			case K_UNICODE:
+				msg = "Unicode (UTF-8)";
+				break;
 		}
 		printf("The keyboard is in %s mode\n", msg);
 	}
-	else if (argc > 2 /* more than 1 arg */
-	 || *opt != '-' /* not an option */
-	 || (p = strchr(opts, opt[1])) == NULL /* not an option we expect */
-	 || opt[2] != '\0' /* more than one option char */
-	) {
-		bb_show_usage();
-		/* return EXIT_FAILURE; - not reached */
-	}
-	else {
-#if K_RAW != 0 || K_XLATE != 1 || K_MEDIUMRAW != 2 || K_UNICODE != 3
-#error kbd_mode must be changed
-#endif
-		/* The options are in the order of the various K_xxx */
-		ioctl(fd, KDSKBMODE, p - opts);
-	}
+
+	if (opt & OPT_s)
+		mode = K_RAW;
+	if (opt & OPT_a)
+		mode = K_XLATE;
+	if (opt & OPT_k)
+		mode = K_MEDIUMRAW;
+	if (opt & OPT_u)
+		mode = K_UNICODE;
+	ioctl(fd, KDSKBMODE, mode);
 
 	if (ENABLE_FEATURE_CLEAN_UP)
 		close(fd);


_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic