From 1d42665b6b0571b9fa5d3b10fbf2dd03382f0ba2 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Mon, 17 Mar 2008 09:09:09 +0000 Subject: [PATCH] *: shrink: use Vladimir's "o+" specifier instead of xatou(opt_param) function old new delta getopt32 1370 1385 +15 sulogin_main 490 494 +4 realpath_main 84 86 +2 sleep_main 76 77 +1 mt_main 256 257 +1 printenv_main 75 74 -1 fdformat_main 546 545 -1 usleep_main 44 42 -2 setlogcons_main 77 75 -2 ed_main 2654 2649 -5 deallocvt_main 69 64 -5 addgroup_main 373 368 -5 mkfs_minix_main 2989 2982 -7 tail_main 1221 1213 -8 sv_main 1254 1241 -13 du_main 348 328 -20 tftp_main 325 302 -23 split_main 581 558 -23 nc_main 1000 977 -23 diff_main 891 868 -23 arping_main 1797 1770 -27 ls_main 893 847 -46 od_main 2797 2750 -47 readprofile_main 1944 1895 -49 tcpudpsvd_main 1973 1922 -51 udhcpc_main 2590 2513 -77 grep_main 824 722 -102 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/22 up/down: 23/-560) Total: -537 bytes text data bss dec hex filename 796973 658 7428 805059 c48c3 busybox_old 796479 662 7420 804561 c46d1 busybox_unstripped --- console-tools/deallocvt.c | 12 +++------ console-tools/openvt.c | 7 ++--- console-tools/setkeycodes.c | 4 +-- console-tools/setlogcons.c | 6 ++--- coreutils/du.c | 13 +++------ coreutils/ls.c | 9 ++----- coreutils/od_bloaty.c | 10 +++---- coreutils/printenv.c | 4 +-- coreutils/realpath.c | 7 +++-- coreutils/sleep.c | 17 +++++------- coreutils/split.c | 12 ++++----- coreutils/tail.c | 5 ++-- coreutils/usleep.c | 4 +-- editors/diff.c | 9 +++---- editors/ed.c | 4 +-- findutils/grep.c | 48 +++++++++++++++------------------ init/halt.c | 7 ++--- init/init.c | 8 +++--- ipsvd/tcpudp.c | 19 ++++++------- libbb/getopt32.c | 15 ++++++----- loginutils/addgroup.c | 8 +++--- loginutils/login.c | 7 ++--- loginutils/sulogin.c | 7 +++-- miscutils/mt.c | 10 +++---- networking/arping.c | 8 +++--- networking/nc_bloaty.c | 10 +++---- networking/tftp.c | 16 ++++------- networking/udhcp/dhcpc.c | 17 ++++++------ runit/sv.c | 7 +++-- util-linux/fdformat.c | 6 ++--- util-linux/mkfs_minix.c | 6 ++--- util-linux/readprofile.c | 53 +++++++++++++++++++++++-------------- util-linux/setarch.c | 2 +- util-linux/swaponoff.c | 4 +-- 34 files changed, 172 insertions(+), 209 deletions(-) diff --git a/console-tools/deallocvt.c b/console-tools/deallocvt.c index 117224560..1200cae1d 100644 --- a/console-tools/deallocvt.c +++ b/console-tools/deallocvt.c @@ -16,19 +16,15 @@ enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */ int deallocvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int deallocvt_main(int argc, char **argv) +int deallocvt_main(int argc ATTRIBUTE_UNUSED, char **argv) { /* num = 0 deallocate all unused consoles */ int num = 0; - switch (argc) { - case 2: + if (argv[1]) { + if (argv[2]) + bb_show_usage(); num = xatou_range(argv[1], 1, 63); - /* Fallthrough */ - case 1: - break; - default: - bb_show_usage(); } /* double cast suppresses "cast to ptr from int of different size" */ diff --git a/console-tools/openvt.c b/console-tools/openvt.c index ff169530d..39b985995 100644 --- a/console-tools/openvt.c +++ b/console-tools/openvt.c @@ -27,9 +27,10 @@ int openvt_main(int argc, char **argv) /* grab new one */ close(0); xopen(vtname, O_RDWR); - dup2(0, STDOUT_FILENO); - dup2(0, STDERR_FILENO); + xdup2(0, STDOUT_FILENO); + xdup2(0, STDERR_FILENO); - BB_EXECVP(argv[2], &argv[2]); + argv += 2; + BB_EXECVP(argv[0], argv); _exit(1); } diff --git a/console-tools/setkeycodes.c b/console-tools/setkeycodes.c index ba3d2e44e..e9a050862 100644 --- a/console-tools/setkeycodes.c +++ b/console-tools/setkeycodes.c @@ -14,7 +14,7 @@ /* From */ struct kbkeycode { - unsigned int scancode, keycode; + unsigned scancode, keycode; }; enum { KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */ @@ -33,7 +33,7 @@ int setkeycodes_main(int argc, char **argv) fd = get_console_fd(); while (argc > 2) { - a.keycode = xatoul_range(argv[2], 0, 127); + a.keycode = xatou_range(argv[2], 0, 127); a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255); if (a.scancode > 127) { a.scancode -= 0xe000; diff --git a/console-tools/setlogcons.c b/console-tools/setlogcons.c index 0f6491c72..b312fa76e 100644 --- a/console-tools/setlogcons.c +++ b/console-tools/setlogcons.c @@ -12,7 +12,7 @@ #include "libbb.h" int setlogcons_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int setlogcons_main(int argc, char **argv) +int setlogcons_main(int argc ATTRIBUTE_UNUSED, char **argv) { struct { char fn; @@ -22,8 +22,8 @@ int setlogcons_main(int argc, char **argv) arg.fn = 11; /* redirect kernel messages */ arg.subarg = 0; /* to specified console (current as default) */ - if (argc == 2) - arg.subarg = xatoul_range(argv[1], 0, 63); + if (argv[1]) + arg.subarg = xatou_range(argv[1], 0, 63); xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg); diff --git a/coreutils/du.c b/coreutils/du.c index 7495f7a7b..b469824ea 100644 --- a/coreutils/du.c +++ b/coreutils/du.c @@ -146,7 +146,6 @@ int du_main(int argc ATTRIBUTE_UNUSED, char **argv) unsigned long total; int slink_depth_save; bool print_final_total; - char *smax_print_depth; unsigned opt; #if ENABLE_FEATURE_HUMAN_READABLE @@ -168,8 +167,8 @@ int du_main(int argc ATTRIBUTE_UNUSED, char **argv) * ignore -a. This is consistent with -s being equivalent to -d 0. */ #if ENABLE_FEATURE_HUMAN_READABLE - opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; - opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); + opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s:d+"; + opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth); argv += optind; if (opt & (1 << 9)) { /* -h opt */ @@ -184,8 +183,8 @@ int du_main(int argc ATTRIBUTE_UNUSED, char **argv) G.disp_hr = 1024; } #else - opt_complementary = "H-L:L-H:s-d:d-s"; - opt = getopt32(argv, "aHkLsx" "d:" "lc", &smax_print_depth); + opt_complementary = "H-L:L-H:s-d:d-s:d+"; + opt = getopt32(argv, "aHkLsx" "d:" "lc", &G.max_print_depth); argv += optind; #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K if (opt & (1 << 2)) { @@ -211,10 +210,6 @@ int du_main(int argc ATTRIBUTE_UNUSED, char **argv) G.max_print_depth = 0; } G.one_file_system = opt & (1 << 5); /* -x opt */ - if (opt & (1 << 6)) { - /* -d opt */ - G.max_print_depth = xatoi_u(smax_print_depth); - } if (opt & (1 << 7)) { /* -l opt */ G.count_hardlinks = MAXINT(nlink_t); diff --git a/coreutils/ls.c b/coreutils/ls.c index dbf1c5ba6..9e5c6dee9 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -799,8 +799,6 @@ int ls_main(int argc, char **argv) int ac; int i; char **av; - USE_FEATURE_AUTOWIDTH(char *tabstops_str = NULL;) - USE_FEATURE_AUTOWIDTH(char *terminal_width_str = NULL;) USE_FEATURE_LS_COLOR(char *color_opt;) #if ENABLE_FEATURE_LS_TIMESTAMPS @@ -820,12 +818,9 @@ int ls_main(int argc, char **argv) /* process options */ USE_FEATURE_LS_COLOR(applet_long_options = ls_color_opt;) #if ENABLE_FEATURE_AUTOWIDTH - opt = getopt32(argv, ls_options, &tabstops_str, &terminal_width_str + opt_complementary = "T+:w+"; /* -T N, -w N */ + opt = getopt32(argv, ls_options, &tabstops, &terminal_width USE_FEATURE_LS_COLOR(, &color_opt)); - if (tabstops_str) - tabstops = xatou(tabstops_str); - if (terminal_width_str) - terminal_width = xatou(terminal_width_str); #else opt = getopt32(argv, ls_options USE_FEATURE_LS_COLOR(, &color_opt)); #endif diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index a083114c9..4526f0ede 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -188,7 +188,7 @@ static off_t pseudo_offset; a multiple of the least common multiple of the sizes associated with the specified output types. It should be as large as possible, but no larger than 16 -- unless specified with the -w option. */ -static size_t bytes_per_block; +static unsigned bytes_per_block = 32; /* have to use unsigned, not size_t */ /* A NULL-terminated list of the file-arguments from the command line. */ static const char *const *file_list; @@ -1218,7 +1218,6 @@ int od_main(int argc, char **argv) ; #endif char *str_A, *str_N, *str_j, *str_S; - char *str_w = NULL; llist_t *lst_t = NULL; unsigned opt; int l_c_m; @@ -1239,7 +1238,7 @@ int od_main(int argc, char **argv) /* flag_dump_strings = 0; - already is */ /* Parse command line */ - opt_complementary = "t::"; // list + opt_complementary = "w+:t::"; /* -w N, -t is a list */ #if ENABLE_GETOPT_LONG applet_long_options = od_longopts; #endif @@ -1248,7 +1247,7 @@ int od_main(int argc, char **argv) // -S was -s and also had optional parameter // but in coreutils 6.3 it was renamed and now has // _mandatory_ parameter - &str_A, &str_N, &str_j, &lst_t, &str_S, &str_w); + &str_A, &str_N, &str_j, &lst_t, &str_S, &bytes_per_block); argc -= optind; argv += optind; if (opt & OPT_A) { @@ -1404,9 +1403,6 @@ int od_main(int argc, char **argv) l_c_m = get_lcm(); if (opt & OPT_w) { /* -w: width */ - bytes_per_block = 32; - if (str_w) - bytes_per_block = xatou(str_w); if (!bytes_per_block || bytes_per_block % l_c_m != 0) { bb_error_msg("warning: invalid width %u; using %d instead", (unsigned)bytes_per_block, l_c_m); diff --git a/coreutils/printenv.c b/coreutils/printenv.c index 06d68d0ef..31d76d712 100644 --- a/coreutils/printenv.c +++ b/coreutils/printenv.c @@ -11,10 +11,10 @@ #include "libbb.h" int printenv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int printenv_main(int argc, char **argv) +int printenv_main(int argc ATTRIBUTE_UNUSED, char **argv) { /* no variables specified, show whole env */ - if (argc == 1) { + if (!argv[1]) { int e = 0; while (environ[e]) puts(environ[e++]); diff --git a/coreutils/realpath.c b/coreutils/realpath.c index bcb73a8dc..6766524a7 100644 --- a/coreutils/realpath.c +++ b/coreutils/realpath.c @@ -13,7 +13,7 @@ #include "libbb.h" int realpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int realpath_main(int argc, char **argv) +int realpath_main(int argc ATTRIBUTE_UNUSED, char **argv) { int retval = EXIT_SUCCESS; @@ -25,19 +25,18 @@ int realpath_main(int argc, char **argv) # define resolved_path_MUST_FREE 0 #endif - if (--argc == 0) { + if (!*++argv) { bb_show_usage(); } do { - argv++; if (realpath(*argv, resolved_path) != NULL) { puts(resolved_path); } else { retval = EXIT_FAILURE; bb_simple_perror_msg(*argv); } - } while (--argc); + } while (*++argv); #if ENABLE_FEATURE_CLEAN_UP && resolved_path_MUST_FREE RELEASE_CONFIG_BUFFER(resolved_path); diff --git a/coreutils/sleep.c b/coreutils/sleep.c index 6890e35c1..78f9a8ebf 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c @@ -34,17 +34,16 @@ static const struct suffix_mult sfx[] = { #endif int sleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int sleep_main(int argc, char **argv) +int sleep_main(int argc ATTRIBUTE_UNUSED, char **argv) { unsigned duration; + ++argv; + if (!*argv) + bb_show_usage(); + #if ENABLE_FEATURE_FANCY_SLEEP - if (argc < 2) { - bb_show_usage(); - } - - ++argv; duration = 0; do { duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx); @@ -52,11 +51,7 @@ int sleep_main(int argc, char **argv) #else /* FEATURE_FANCY_SLEEP */ - if (argc != 2) { - bb_show_usage(); - } - - duration = xatou(argv[1]); + duration = xatou(*argv); #endif /* FEATURE_FANCY_SLEEP */ diff --git a/coreutils/split.c b/coreutils/split.c index cf26a9322..2306789f0 100644 --- a/coreutils/split.c +++ b/coreutils/split.c @@ -68,15 +68,13 @@ int split_main(int argc ATTRIBUTE_UNUSED, char **argv) ssize_t bytes_read, to_write; char *src; - opt_complementary = "?2"; - opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &sfx); + opt_complementary = "?2:a+"; /* max 2 args; -a N */ + opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len); if (opt & SPLIT_OPT_l) - cnt = xatoul(count_p); - if (opt & SPLIT_OPT_b) - cnt = xatoul_sfx(count_p, split_suffices); - if (opt & SPLIT_OPT_a) - suffix_len = xatou(sfx); + cnt = XATOOFF(count_p); + if (opt & SPLIT_OPT_b) // FIXME: also needs XATOOFF + cnt = xatoull_sfx(count_p, split_suffices); sfx = "x"; argv += optind; diff --git a/coreutils/tail.c b/coreutils/tail.c index 52aa8f69e..35b25a416 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c @@ -87,7 +87,6 @@ int tail_main(int argc, char **argv) bool from_top; int header_threshhold = 1; const char *str_c, *str_n; - USE_FEATURE_FANCY_TAIL(const char *str_s;) char *tailbuf; size_t tailbufsize; @@ -110,8 +109,9 @@ int tail_main(int argc, char **argv) } #endif + USE_FEATURE_FANCY_TAIL(opt_complementary = "s+";) /* -s N */ opt = getopt32(argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"), - &str_c, &str_n USE_FEATURE_FANCY_TAIL(,&str_s)); + &str_c, &str_n USE_FEATURE_FANCY_TAIL(,&sleep_period)); #define FOLLOW (opt & 0x1) #define COUNT_BYTES (opt & 0x2) //if (opt & 0x1) // -f @@ -119,7 +119,6 @@ int tail_main(int argc, char **argv) if (opt & 0x4) count = eat_num(str_n); // -n #if ENABLE_FEATURE_FANCY_TAIL if (opt & 0x8) header_threshhold = INT_MAX; // -q - if (opt & 0x10) sleep_period = xatou(str_s); // -s if (opt & 0x20) header_threshhold = 0; // -v #endif argc -= optind; diff --git a/coreutils/usleep.c b/coreutils/usleep.c index 1c9022325..d34880d3a 100644 --- a/coreutils/usleep.c +++ b/coreutils/usleep.c @@ -14,9 +14,9 @@ /* This is a NOFORK applet. Be very careful! */ int usleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int usleep_main(int argc, char **argv) +int usleep_main(int argc ATTRIBUTE_UNUSED, char **argv) { - if (argc != 2) { + if (!argv[1]) { bb_show_usage(); } diff --git a/editors/diff.c b/editors/diff.c index f9e82ba02..486077847 100644 --- a/editors/diff.c +++ b/editors/diff.c @@ -1208,17 +1208,16 @@ int diff_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int diff_main(int argc ATTRIBUTE_UNUSED, char **argv) { bool gotstdin = 0; - char *U_opt; char *f1, *f2; llist_t *L_arg = NULL; INIT_G(); - /* exactly 2 params; collect multiple -L