From 237bedd499c58034a1355484d6d4d906f0180308 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 6 Jul 2016 21:58:02 +0200 Subject: getopt32: add new syntax of 'o:+' and 'o:*' for -o NUM and -o LIST In many cases, this aqllows to drop use of opt_complementary. Approximately -400 bytes: function old new delta getopt32 1423 1502 +79 opt_string 17 18 +1 OPT_STR 24 25 +1 uniq_main 416 406 -10 timeout_main 279 269 -10 sulogin_main 270 260 -10 readprofile_main 1825 1815 -10 ps_main 543 533 -10 pidof_main 245 235 -10 pgrep_main 611 601 -10 od_main 2600 2590 -10 mkfs_minix_main 2684 2674 -10 mkfs_ext2_main 2603 2593 -10 microcom_main 712 702 -10 makemime_main 315 305 -10 ionice_main 282 272 -10 inetd_main 2074 2064 -10 ifplugd_main 1144 1134 -10 halt_main 353 343 -10 getopt_main 636 626 -10 fdisk_main 2854 2844 -10 env_main 206 196 -10 dmesg_main 319 309 -10 conspy_main 1214 1204 -10 awk_main 981 971 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/22 up/down: 81/-220) Total: -139 bytes text data bss dec hex filename 919373 906 14060 934339 e41c3 busybox_old 918969 906 14060 933935 e402f busybox_unstripped Signed-off-by: Denys Vlasenko --- archival/tar.c | 15 ++++----- coreutils/du.c | 8 ++--- coreutils/env.c | 3 +- coreutils/od_bloaty.c | 3 +- coreutils/sort.c | 5 ++- coreutils/split.c | 4 +-- coreutils/tail.c | 4 +-- coreutils/uniq.c | 3 +- debianutils/run_parts.c | 4 +-- editors/awk.c | 8 ++--- editors/diff.c | 4 +-- editors/sed.c | 5 ++- findutils/grep.c | 8 ++--- init/halt.c | 3 +- libbb/getopt32.c | 82 ++++++++++++++++++++++++++++++++------------- libbb/parse_config.c | 4 +-- loginutils/cryptpw.c | 4 +-- loginutils/getty.c | 4 +-- loginutils/sulogin.c | 3 +- mailutils/makemime.c | 3 +- mailutils/popmaildir.c | 4 +-- mailutils/reformime.c | 4 +-- mailutils/sendmail.c | 4 +-- miscutils/conspy.c | 4 +-- miscutils/ionice.c | 3 +- miscutils/microcom.c | 3 +- miscutils/timeout.c | 3 +- miscutils/ubi_tools.c | 8 ++--- networking/arping.c | 4 +-- networking/ftpd.c | 6 ++-- networking/ifplugd.c | 5 ++- networking/inetd.c | 4 +-- networking/nc_bloaty.c | 4 +-- networking/ntpd.c | 4 +-- networking/ping.c | 4 +-- networking/tcpudp.c | 4 +-- networking/telnetd.c | 4 +-- networking/traceroute.c | 4 +-- networking/udhcp/d6_dhcpc.c | 4 +-- networking/udhcp/dhcpc.c | 4 +-- networking/wget.c | 3 +- networking/whois.c | 4 +-- procps/pgrep.c | 3 +- procps/pidof.c | 3 +- procps/ps.c | 3 +- procps/watch.c | 4 +-- runit/chpst.c | 4 +-- runit/sv.c | 4 +-- selinux/setfiles.c | 6 ++-- sysklogd/syslogd.c | 6 ++-- util-linux/dmesg.c | 3 +- util-linux/fdisk.c | 3 +- util-linux/getopt.c | 3 +- util-linux/mkfs_ext2.c | 3 +- util-linux/mkfs_minix.c | 3 +- util-linux/mkfs_reiser.c | 4 +-- util-linux/mount.c | 4 +-- util-linux/readprofile.c | 3 +- 58 files changed, 168 insertions(+), 159 deletions(-) diff --git a/archival/tar.c b/archival/tar.c index 7434e22e4..8e315c610 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -980,7 +980,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv) /* Prepend '-' to the first argument if required */ opt_complementary = "--:" // first arg is options "tt:vv:" // count -t,-v - IF_FEATURE_TAR_FROM("X::T::") // cumulative lists #if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM "\xff::" // --exclude=PATTERN is a list #endif @@ -1032,13 +1031,13 @@ int tar_main(int argc UNUSED_PARAM, char **argv) #endif opt = getopt32(argv, "txC:f:Oopvk" - IF_FEATURE_TAR_CREATE( "ch" ) - IF_FEATURE_SEAMLESS_BZ2( "j" ) - IF_FEATURE_SEAMLESS_LZMA("a" ) - IF_FEATURE_TAR_FROM( "T:X:") - IF_FEATURE_SEAMLESS_GZ( "z" ) - IF_FEATURE_SEAMLESS_XZ( "J" ) - IF_FEATURE_SEAMLESS_Z( "Z" ) + IF_FEATURE_TAR_CREATE( "ch" ) + IF_FEATURE_SEAMLESS_BZ2( "j" ) + IF_FEATURE_SEAMLESS_LZMA("a" ) + IF_FEATURE_TAR_FROM( "T:*X:*") + IF_FEATURE_SEAMLESS_GZ( "z" ) + IF_FEATURE_SEAMLESS_XZ( "J" ) + IF_FEATURE_SEAMLESS_Z( "Z" ) IF_FEATURE_TAR_NOPRESERVE_TIME("m") IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components , &base_dir // -C dir diff --git a/coreutils/du.c b/coreutils/du.c index 1240bcbbc..5f104736b 100644 --- a/coreutils/du.c +++ b/coreutils/du.c @@ -226,8 +226,8 @@ int du_main(int argc UNUSED_PARAM, 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:d+"; - opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth); + opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; + opt = getopt32(argv, "aHkLsx" "d:+" "lc" "hm", &G.max_print_depth); argv += optind; if (opt & OPT_h_for_humans) { G.disp_unit = 0; @@ -239,8 +239,8 @@ int du_main(int argc UNUSED_PARAM, char **argv) G.disp_unit = 1024; } #else - opt_complementary = "H-L:L-H:s-d:d-s:d+"; - opt = getopt32(argv, "aHkLsx" "d:" "lc", &G.max_print_depth); + opt_complementary = "H-L:L-H:s-d:d-s"; + opt = getopt32(argv, "aHkLsx" "d:+" "lc", &G.max_print_depth); argv += optind; #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K if (opt & OPT_k_kbytes) { diff --git a/coreutils/env.c b/coreutils/env.c index 807ef13e9..cdfc30e14 100644 --- a/coreutils/env.c +++ b/coreutils/env.c @@ -54,11 +54,10 @@ int env_main(int argc UNUSED_PARAM, char **argv) unsigned opts; llist_t *unset_env = NULL; - opt_complementary = "u::"; #if ENABLE_FEATURE_ENV_LONG_OPTIONS applet_long_options = env_longopts; #endif - opts = getopt32(argv, "+iu:", &unset_env); + opts = getopt32(argv, "+iu:+", &unset_env); argv += optind; if (argv[0] && LONE_DASH(argv[0])) { opts |= 1; diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index c8a654165..f13bdfc11 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -62,7 +62,7 @@ enum { }; #define OD_GETOPT32() getopt32(argv, \ - "A:N:abcdfhij:lot:vxsS:w::", \ + "A:N:abcdfhij:lot:*vxsS:w:+:", \ /* -w with optional param */ \ /* -S was -s and also had optional parameter */ \ /* but in coreutils 6.3 it was renamed and now has */ \ @@ -1212,7 +1212,6 @@ int od_main(int argc UNUSED_PARAM, char **argv) address_pad_len_char = '7'; /* Parse command line */ - opt_complementary = "w+:t::"; /* -w N, -t is a list */ #if ENABLE_LONG_OPTS applet_long_options = od_longopts; #endif diff --git a/coreutils/sort.c b/coreutils/sort.c index 9139d9f47..34a41999b 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -73,7 +73,7 @@ */ /* These are sort types */ -static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:t:"; +static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:*t:"; enum { FLAG_n = 1, /* Numeric sort */ FLAG_g = 2, /* Sort using strtod() */ @@ -358,8 +358,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv) /* Parse command line options */ /* -o and -t can be given at most once */ - opt_complementary = "o--o:t--t:" /* -t, -o: at most one of each */ - "k::"; /* -k takes list */ + opt_complementary = "o--o:t--t"; /* -t, -o: at most one of each */ opts = getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t); /* global b strips leading and trailing spaces */ if (opts & FLAG_b) diff --git a/coreutils/split.c b/coreutils/split.c index e67c3de66..19d58a21b 100644 --- a/coreutils/split.c +++ b/coreutils/split.c @@ -81,8 +81,8 @@ int split_main(int argc UNUSED_PARAM, char **argv) setup_common_bufsiz(); - opt_complementary = "?2:a+"; /* max 2 args; -a N */ - opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len); + opt_complementary = "?2"; /* max 2 args; -a N */ + opt = getopt32(argv, "l:b:a:+", &count_p, &count_p, &suffix_len); if (opt & SPLIT_OPT_l) cnt = XATOOFF(count_p); diff --git a/coreutils/tail.c b/coreutils/tail.c index 39f87679e..57ad0f3b7 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c @@ -121,8 +121,8 @@ int tail_main(int argc, char **argv) #endif /* -s NUM, -F imlies -f */ - IF_FEATURE_FANCY_TAIL(opt_complementary = "s+:Ff";) - opt = getopt32(argv, "fc:n:" IF_FEATURE_FANCY_TAIL("qs:vF"), + IF_FEATURE_FANCY_TAIL(opt_complementary = "Ff";) + opt = getopt32(argv, "fc:n:" IF_FEATURE_FANCY_TAIL("qs:+vF"), &str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period)); #define FOLLOW (opt & 0x1) #define COUNT_BYTES (opt & 0x2) diff --git a/coreutils/uniq.c b/coreutils/uniq.c index e0133998a..ec7bde418 100644 --- a/coreutils/uniq.c +++ b/coreutils/uniq.c @@ -50,8 +50,7 @@ int uniq_main(int argc UNUSED_PARAM, char **argv) skip_fields = skip_chars = 0; max_chars = INT_MAX; - opt_complementary = "f+:s+:w+"; - opt = getopt32(argv, "cduf:s:w:", &skip_fields, &skip_chars, &max_chars); + opt = getopt32(argv, "cduf:+s:+w:+", &skip_fields, &skip_chars, &max_chars); argv += optind; input_filename = argv[0]; diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index c671b9252..0bb666abc 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c @@ -181,8 +181,8 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv) applet_long_options = runparts_longopts; #endif /* We require exactly one argument: the directory name */ - opt_complementary = "=1:a::"; - getopt32(argv, "a:u:", &arg_list, &umask_p); + opt_complementary = "=1"; + getopt32(argv, "a:*u:", &arg_list, &umask_p); umask(xstrtou_range(umask_p, 8, 0, 07777)); diff --git a/editors/awk.c b/editors/awk.c index 69816464d..d0269b9f4 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -72,12 +72,9 @@ #define OPTSTR_AWK \ - "F:v:f:" \ - IF_FEATURE_AWK_GNU_EXTENSIONS("e:") \ + "F:v:*f:*" \ + IF_FEATURE_AWK_GNU_EXTENSIONS("e:*") \ "W:" -#define OPTCOMPLSTR_AWK \ - "v::f::" \ - IF_FEATURE_AWK_GNU_EXTENSIONS("e::") enum { OPTBIT_F, /* define field separator */ OPTBIT_v, /* define variable */ @@ -3209,7 +3206,6 @@ int awk_main(int argc, char **argv) *s1 = '='; } } - opt_complementary = OPTCOMPLSTR_AWK; opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL); argv += optind; argc -= optind; diff --git a/editors/diff.c b/editors/diff.c index ff269360f..75229ad8c 100644 --- a/editors/diff.c +++ b/editors/diff.c @@ -982,11 +982,11 @@ int diff_main(int argc UNUSED_PARAM, char **argv) INIT_G(); /* exactly 2 params; collect multiple -L