svn commit: trunk/busybox: console-tools coreutils include

vda at busybox.net vda at busybox.net
Tue Sep 16 19:35:42 UTC 2008


Author: vda
Date: 2008-09-16 12:35:42 -0700 (Tue, 16 Sep 2008)
New Revision: 23410

Log:
setfont: support -m and -C, support -m TEXTUAL_MAP (by Vladimir)
build system: fixlet for echo applet config

function                                             old     new   delta
setfont_main                                         157     387    +230
ctoi                                                   -      75     +75
packed_usage                                       24921   24950     +29



Modified:
   trunk/busybox/console-tools/Config.in
   trunk/busybox/console-tools/loadfont.c
   trunk/busybox/coreutils/Config.in
   trunk/busybox/include/usage.h


Changeset:
Modified: trunk/busybox/console-tools/Config.in
===================================================================
--- trunk/busybox/console-tools/Config.in	2008-09-16 18:44:54 UTC (rev 23409)
+++ trunk/busybox/console-tools/Config.in	2008-09-16 19:35:42 UTC (rev 23410)
@@ -101,6 +101,21 @@
 	help
 	  Allows to load console screen map. Useful for i18n.
 
+config FEATURE_SETFONT_TEXTUAL_MAP
+	bool "Support reading textual screen maps"
+	default n
+	depends on SETFONT
+	help
+	  Support reading textual screen maps.
+
+config DEFAULT_SETFONT_DIR
+	string "Default directory for console-tools files"
+	default ""
+	depends on SETFONT
+	help
+	  Directory to use if setfont's params are simple filenames
+	  (not /path/to/file or ./file). Default is "" (no default directory).
+
 config SETKEYCODES
 	bool "setkeycodes"
 	default n

Modified: trunk/busybox/console-tools/loadfont.c
===================================================================
--- trunk/busybox/console-tools/loadfont.c	2008-09-16 18:44:54 UTC (rev 23409)
+++ trunk/busybox/console-tools/loadfont.c	2008-09-16 19:35:42 UTC (rev 23410)
@@ -17,7 +17,7 @@
 	PSF_MODE512 = 0x01,
 	PSF_MODEHASTAB = 0x02,
 	PSF_MAXMODE = 0x03,
-	PSF_SEPARATOR = 0xFFFF
+	PSF_SEPARATOR = 0xffff
 };
 
 struct psf_header {
@@ -165,6 +165,8 @@
 }
 #endif
 
+#if ENABLE_SETFONT
+
 /*
 kbd-1.12:
 
@@ -198,36 +200,125 @@
 -V     Version
 */
 
-#if ENABLE_SETFONT
+#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
+static int ctoi(char *s)
+{
+	if (s[0] == '\'' && s[1] != '\0' && s[2] == '\'' && s[3] == '\0')
+		return s[1];
+	// U+ means 0x
+	if (s[0] == 'U' && s[1] == '+') {
+		s[0] = '0';
+		s[1] = 'x';
+	}
+	if (!isdigit(s[0]))
+		return -1;
+	return xstrtoul(s, 0);
+}
+#endif
+
 int setfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int setfont_main(int argc UNUSED_PARAM, char **argv)
 {
 	size_t len;
+	unsigned opts;
+	int fd;
 	struct psf_header *psfhdr;
 	char *mapfilename;
-	int fd;
+	const char *tty_name = CURRENT_TTY;
 
 	opt_complementary = "=1";
-	getopt32(argv, "m:", &mapfilename);
+	opts = getopt32(argv, "m:C:", &mapfilename, &tty_name);
 	argv += optind;
 
+	fd = xopen(tty_name, O_NONBLOCK);
+
+	if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
+		if (strchr(*argv, '/') != NULL) {
+			// goto default fonts location. don't die if doesn't exist
+			chdir(CONFIG_DEFAULT_SETFONT_DIR "/consolefonts");
+			// buglet: we don't return to current dir...
+			// affects "setfont FONT -m ./MAP" case
+		}
+	}
 	// load font
 	len = 32*1024; // can't be larger
 	psfhdr = (struct psf_header *) xmalloc_open_zipped_read_close(*argv, &len);
-	fd = get_console_fd_or_die();
 	do_load(fd, psfhdr, len);
 
 	// load the screen map, if any
-	if (option_mask32 & 1) { // -m
-		void *map = xmalloc_open_zipped_read_close(mapfilename, &len);
+	if (opts & 1) { // -m
+		unsigned mode = PIO_SCRNMAP;
+		void *map;
+
+		if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
+			if (strchr(mapfilename, '/') != NULL) {
+				// goto default keymaps location
+				chdir(CONFIG_DEFAULT_SETFONT_DIR "/consoletrans");
+			}
+		}
+		// fetch keymap
+		map = xmalloc_open_zipped_read_close(mapfilename, &len);
+		if (!map)
+			bb_simple_perror_msg_and_die(mapfilename);
+		// file size is 256 or 512 bytes? -> assume binary map
 		if (len == E_TABSZ || len == 2*E_TABSZ) {
-			//TODO: support textual Unicode console maps:
-			// 0x00 U+0000  #  NULL (NUL)
-			// 0x01 U+0001  #  START OF HEADING (SOH)
-			// 0x02 U+0002  #  START OF TEXT (STX)
-			// 0x03 U+0003  #  END OF TEXT (ETX)
-			xioctl(fd, (len == 2*E_TABSZ) ? PIO_UNISCRNMAP : PIO_SCRNMAP, map);
+			if (len == 2*E_TABSZ)
+				mode = PIO_UNISCRNMAP;
 		}
+#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
+		// assume textual Unicode console maps:
+		// 0x00 U+0000  #  NULL (NUL)
+		// 0x01 U+0001  #  START OF HEADING (SOH)
+		// 0x02 U+0002  #  START OF TEXT (STX)
+		// 0x03 U+0003  #  END OF TEXT (ETX)
+		else {
+			int i;
+			char *token[2];
+			parser_t *parser;
+
+			if (ENABLE_FEATURE_CLEAN_UP)
+				free(map);
+			map = xmalloc(E_TABSZ * sizeof(unsigned short));
+
+#define unicodes ((unsigned short *)map)
+			// fill vanilla map
+			for (i = 0; i < E_TABSZ; i++)
+				unicodes[i] = 0xf000 + i;
+
+			parser = config_open(mapfilename);
+			while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL | PARSE_MIN_DIE)) {
+				// parse code/value pair
+				int a = ctoi(token[0]);
+				int b = ctoi(token[1]);
+				if (a < 0 || a >= E_TABSZ
+				 || b < 0 || b > 65535
+				) {
+					bb_error_msg_and_die("map format");
+				}
+				// patch map
+				unicodes[a] = b;
+				// unicode character is met?
+				if (b > 255)
+					mode = PIO_UNISCRNMAP;
+			}
+			if (ENABLE_FEATURE_CLEAN_UP)
+				config_close(parser);
+
+			if (mode != PIO_UNISCRNMAP) {
+#define asciis ((unsigned char *)map)
+				for (i = 0; i < E_TABSZ; i++)
+					asciis[i] = unicodes[i];
+#undef asciis
+			}
+#undef unicodes
+		}
+#endif // ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
+
+		// do set screen map
+		xioctl(fd, mode, map);
+
+		if (ENABLE_FEATURE_CLEAN_UP)
+			free(map);
 	}
 
 	return EXIT_SUCCESS;

Modified: trunk/busybox/coreutils/Config.in
===================================================================
--- trunk/busybox/coreutils/Config.in	2008-09-16 18:44:54 UTC (rev 23409)
+++ trunk/busybox/coreutils/Config.in	2008-09-16 19:35:42 UTC (rev 23410)
@@ -649,7 +649,7 @@
 config FEATURE_TEST_64
 	bool "Extend test to 64 bit"
 	default n
-	depends on TEST || FEATURE_TEST_64
+	depends on TEST || ASH_BUILTIN_TEST
 	help
 	  Enable 64-bit support in test.
 

Modified: trunk/busybox/include/usage.h
===================================================================
--- trunk/busybox/include/usage.h	2008-09-16 18:44:54 UTC (rev 23409)
+++ trunk/busybox/include/usage.h	2008-09-16 19:35:42 UTC (rev 23410)
@@ -3533,11 +3533,13 @@
      "\n	-W	Display warnings about entries that had no matching files" \
 
 #define setfont_trivial_usage \
-       "[-m mapfile] font"
+       "FONT [-m MAPFILE] [-C TTY]"
 #define setfont_full_usage "\n\n" \
        "Load a console font\n" \
      "\nOptions:" \
-     "\n	-m mapfile	Load console screen map from mapfile"
+     "\n	-m MAPFILE	Load console screen map" \
+     "\n	-C TTY		Affect TTY instead of /dev/tty" \
+
 #define setfont_example_usage \
        "$ setfont -m koi8-r /etc/i18n/fontname\n"
 




More information about the busybox-cvs mailing list