On Tuesday 04 November 2008 15:46:56 Bernhard Reutner-Fischer wrote:
> Given these stats you should add a
> get_console_fd_from_name_or_die(const char *dev) instead of adding
> penalties for the NULL arg everywhere.
That saves a futher 30 bytes.
uberlaptop busybox-1.12.1 # ./scripts/bloat-o-meter ../*orig/busybox busybox
function old new delta
get_console_fd_from_name_or_die - 47 +47
.rodata 163385 163426 +41
packed_usage 24130 24151 +21
kbd_mode_main 223 241 +18
setfont_main 194 208 +14
loadfont_main 103 117 +14
static.KD_xxx 5 7 +2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 6/0 up/down: 157/0) Total: 157 bytes
Thanks
Roy
diff -ur busybox-1.12.1.orig/console-tools/kbd_mode.c busybox-1.12.1/console-tools/kbd_mode.c
--- busybox-1.12.1.orig/console-tools/kbd_mode.c 2008-09-28 19:04:15.000000000 +0100
+++ busybox-1.12.1/console-tools/kbd_mode.c 2008-11-04 16:29:21.000000000 +0000
@@ -22,11 +22,14 @@
SCANCODE = (1 << 0),
ASCII = (1 << 1),
MEDIUMRAW = (1 << 2),
- UNICODE = (1 << 3)
+ UNICODE = (1 << 3),
+ OPT_C = (1 << 4)
};
- static const char KD_xxx[] ALIGN1 = "saku";
- opt = getopt32(argv, KD_xxx);
- fd = get_console_fd_or_die();
+ char *dev = NULL;
+ static const char KD_xxx[] ALIGN1 = "sakuC:";
+ opt = getopt32(argv, KD_xxx, &dev);
+ fd = get_console_fd_from_name_or_die(dev);
+ opt &= ~OPT_C;
if (!opt) { /* print current setting */
const char *mode = "unknown";
diff -ur busybox-1.12.1.orig/console-tools/loadfont.c busybox-1.12.1/console-tools/loadfont.c
--- busybox-1.12.1.orig/console-tools/loadfont.c 2008-09-28 19:04:15.000000000 +0100
+++ busybox-1.12.1/console-tools/loadfont.c 2008-11-04 16:29:21.000000000 +0000
@@ -144,10 +144,11 @@
{
size_t len;
struct psf_header *psfhdr;
+ char *dev = NULL;
// no arguments allowed!
opt_complementary = "=0";
- getopt32(argv, "");
+ getopt32(argv, "C:", &dev);
/*
* We used to look at the length of the input file
@@ -159,7 +160,7 @@
// xmalloc_open_zipped_read_close(filename, &len);
if (!psfhdr)
bb_perror_msg_and_die("error reading input font");
- do_load(get_console_fd_or_die(), psfhdr, len);
+ do_load(get_console_fd_from_name_or_die(dev), psfhdr, len);
return EXIT_SUCCESS;
}
@@ -171,17 +172,17 @@
{
size_t len;
struct psf_header *psfhdr;
- char *mapfilename;
+ char *mapfilename, *dev = NULL;
int fd;
opt_complementary = "=1";
- getopt32(argv, "m:", &mapfilename);
+ getopt32(argv, "m:C:", &mapfilename, &dev);
argv += optind;
// 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();
+ fd = get_console_fd_from_name_or_die(dev);
do_load(fd, psfhdr, len);
// load the screen map, if any
diff -ur busybox-1.12.1.orig/include/libbb.h busybox-1.12.1/include/libbb.h
--- busybox-1.12.1.orig/include/libbb.h 2008-09-28 19:04:26.000000000 +0100
+++ busybox-1.12.1/include/libbb.h 2008-11-04 16:29:53.000000000 +0000
@@ -287,6 +287,7 @@
extern int device_open(const char *device, int mode) FAST_FUNC;
enum { GETPTY_BUFSIZE = 16 }; /* more than enough for "/dev/ttyXXX" */
extern int xgetpty(char *line) FAST_FUNC;
+extern int get_console_fd_from_name_or_die(const char *device) FAST_FUNC;
extern int get_console_fd_or_die(void) FAST_FUNC;
extern void console_make_active(int fd, const int vt_num) FAST_FUNC;
extern char *find_block_device(const char *path) FAST_FUNC;
Only in busybox-1.12.1/include: usage_compressed.h
diff -ur busybox-1.12.1.orig/include/usage.h busybox-1.12.1/include/usage.h
--- busybox-1.12.1.orig/include/usage.h 2008-11-04 13:46:17.000000000 +0000
+++ busybox-1.12.1/include/usage.h 2008-11-04 16:29:21.000000000 +0000
@@ -2019,14 +2019,15 @@
" [ttl TTL] [tos TOS] [[no]pmtudisc] [dev PHYS_DEV]" \
#define kbd_mode_trivial_usage \
- "[-a|k|s|u]"
+ "[-C device] [-a|k|s|u]"
#define kbd_mode_full_usage "\n\n" \
"Report or set the keyboard mode\n" \
"\nOptions set mode:" \
- "\n -a Default (ASCII)" \
- "\n -k Medium-raw (keyboard)" \
- "\n -s Raw (scancode)" \
- "\n -u Unicode (utf-8)" \
+ "\n -C device Device to use (default console)" \
+ "\n -a Default (ASCII)" \
+ "\n -k Medium-raw (keyboard)" \
+ "\n -s Raw (scancode)" \
+ "\n -u Unicode (utf-8)" \
#define kill_trivial_usage \
"[-l] [-signal] process-id..."
@@ -3520,10 +3521,11 @@
"\n -W Display warnings about entries that had no matching files" \
#define setfont_trivial_usage \
- "[-m mapfile] font"
+ "[-C device] [-m mapfile] font"
#define setfont_full_usage "\n\n" \
"Load a console font\n" \
"\nOptions:" \
+ "\n -C device Device to set font on (default console)" \
"\n -m mapfile Load console screen map from mapfile"
#define setfont_example_usage \
"$ setfont -m koi8-r /etc/i18n/fontname\n"
diff -ur busybox-1.12.1.orig/libbb/get_console.c busybox-1.12.1/libbb/get_console.c
--- busybox-1.12.1.orig/libbb/get_console.c 2008-09-28 19:04:20.000000000 +0100
+++ busybox-1.12.1/libbb/get_console.c 2008-11-04 16:43:31.000000000 +0000
@@ -43,7 +43,6 @@
static const char *const console_names[] = {
DEV_CONSOLE, CURRENT_VC, CURRENT_TTY
};
-
int fd;
for (fd = 2; fd >= 0; fd--) {
@@ -69,6 +68,17 @@
/*return fd; - total failure */
}
+int FAST_FUNC get_console_fd_from_name_or_die(const char *device)
+{
+ int fd;
+
+ fd = open_a_console(device);
+ if (fd != -1)
+ return fd;
+
+ bb_error_msg_and_die("can't open %s", device);
+}
+
/* From <linux/vt.h> */
enum {
VT_ACTIVATE = 0x5606, /* make vt active */
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox