From: Denys Vlasenko Date: Tue, 8 Aug 2017 14:38:18 +0000 (+0200) Subject: getopt32: remove applet_long_options X-Git-Tag: 1_28_0~162 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=036585a911a5fe6c2cd77b808dd9150500f37272;p=oweals%2Fbusybox.git getopt32: remove applet_long_options FEATURE_GETOPT_LONG made dependent on LONG_OPTS. The folloving options are removed, now LONG_OPTS enables long options for affected applets: FEATURE_ENV_LONG_OPTIONS FEATURE_EXPAND_LONG_OPTIONS FEATURE_UNEXPAND_LONG_OPTIONS FEATURE_MKDIR_LONG_OPTIONS FEATURE_MV_LONG_OPTIONS FEATURE_RMDIR_LONG_OPTIONS FEATURE_ADDGROUP_LONG_OPTIONS FEATURE_ADDUSER_LONG_OPTIONS FEATURE_HWCLOCK_LONG_OPTIONS FEATURE_NSENTER_LONG_OPTS FEATURE_CHCON_LONG_OPTIONS FEATURE_RUNCON_LONG_OPTIONS They either had a small number of long options, or their long options are essential. Example: upstream addgroup and adduser have ONLY longopts, we should probably go further and get rid of non-standard short options. To this end, make addgroup and adduser "select LONG_OPTS". We had this breakage caused by us even in our own package! #if ENABLE_LONG_OPTS || !ENABLE_ADDGROUP /* We try to use --gid, not -g, because "standard" addgroup * has no short option -g, it has only long --gid. */ argv[1] = (char*)"--gid"; #else /* Breaks if system in fact does NOT use busybox addgroup */ argv[1] = (char*)"-g"; #endif xargs: its lone longopt no longer depends on DESKTOP, only on LONG_OPTS. hwclock TODO: get rid of incompatible -t, -l aliases to --systz, --localtime Shorten help texts by omitting long option when short opt alternative exists. Reduction of size comes from the fact that store of an immediate (an address of longopts) to a fixed address (global variable) is a longer insn than pushing that immediate or passing it in a register. This effect is CPU-agnostic. function old new delta getopt32 1350 22 -1328 vgetopt32 - 1318 +1318 getopt32long - 24 +24 tftpd_main 562 567 +5 scan_recursive 376 380 +4 collect_cpu 545 546 +1 date_main 1096 1095 -1 hostname_main 262 259 -3 uname_main 259 255 -4 setpriv_main 362 358 -4 rmdir_main 191 187 -4 mv_main 562 558 -4 ipcalc_main 548 544 -4 ifenslave_main 641 637 -4 gzip_main 192 188 -4 gunzip_main 77 73 -4 fsfreeze_main 81 77 -4 flock_main 318 314 -4 deluser_main 337 333 -4 cp_main 374 370 -4 chown_main 175 171 -4 applet_long_options 4 - -4 xargs_main 894 889 -5 wget_main 2540 2535 -5 udhcpc_main 2767 2762 -5 touch_main 436 431 -5 tar_main 1014 1009 -5 start_stop_daemon_main 1033 1028 -5 sed_main 682 677 -5 script_main 1082 1077 -5 run_parts_main 330 325 -5 rtcwake_main 459 454 -5 od_main 2169 2164 -5 nl_main 201 196 -5 modprobe_main 773 768 -5 mkdir_main 160 155 -5 ls_main 568 563 -5 install_main 773 768 -5 hwclock_main 411 406 -5 getopt_main 622 617 -5 fstrim_main 256 251 -5 env_main 198 193 -5 dumpleases_main 635 630 -5 dpkg_main 3991 3986 -5 diff_main 1355 1350 -5 cryptpw_main 233 228 -5 cpio_main 593 588 -5 conspy_main 1135 1130 -5 chpasswd_main 313 308 -5 adduser_main 887 882 -5 addgroup_main 416 411 -5 ftpgetput_main 351 345 -6 get_terminal_width_height 242 234 -8 expand_main 690 680 -10 static.expand_longopts 18 - -18 static.unexpand_longopts 27 - -27 mkdir_longopts 28 - -28 env_longopts 30 - -30 static.ifenslave_longopts 34 - -34 mv_longopts 46 - -46 static.rmdir_longopts 48 - -48 packed_usage 31739 31687 -52 ------------------------------------------------------------------------------ (add/remove: 2/8 grow/shrink: 3/49 up/down: 1352/-1840) Total: -488 bytes text data bss dec hex filename 915681 485 6880 923046 e15a6 busybox_old 915428 485 6876 922789 e14a5 busybox_unstripped Signed-off-by: Denys Vlasenko --- diff --git a/archival/bbunzip.c b/archival/bbunzip.c index 9b9fdc87b..20ab893da 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c @@ -389,9 +389,10 @@ int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int gunzip_main(int argc UNUSED_PARAM, char **argv) { #if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS - applet_long_options = gunzip_longopts; -#endif + getopt32long(argv, "cfkvqdtn", gunzip_longopts); +#else getopt32(argv, "cfkvqdtn"); +#endif argv += optind; /* If called as zcat... diff --git a/archival/cpio.c b/archival/cpio.c index 38bab8257..f2165be3a 100644 --- a/archival/cpio.c +++ b/archival/cpio.c @@ -360,9 +360,8 @@ int cpio_main(int argc UNUSED_PARAM, char **argv) char *cpio_owner; IF_FEATURE_CPIO_O(const char *cpio_fmt = "";) unsigned opt; - #if ENABLE_LONG_OPTS - applet_long_options = + const char *long_opts = "extract\0" No_argument "i" "list\0" No_argument "t" #if ENABLE_FEATURE_CPIO_O @@ -390,9 +389,9 @@ int cpio_main(int argc UNUSED_PARAM, char **argv) /* -L makes sense only with -o or -p */ #if !ENABLE_FEATURE_CPIO_O - opt = getopt32(argv, OPTION_STR, &cpio_filename, &cpio_owner); + opt = getopt32long(argv, OPTION_STR, long_opts, &cpio_filename, &cpio_owner); #else - opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), + opt = getopt32long(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), long_opts, &cpio_filename, &cpio_owner, &cpio_fmt); #endif argv += optind; diff --git a/archival/dpkg.c b/archival/dpkg.c index 90ad8766c..852e0cac2 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c @@ -1766,8 +1766,7 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv) INIT_G(); - IF_LONG_OPTS(applet_long_options = dpkg_longopts); - opt = getopt32(argv, "CilPruF:", &str_f); + opt = getopt32long(argv, "CilPruF:", dpkg_longopts, &str_f); argv += optind; //if (opt & OPT_configure) ... // -C if (opt & OPT_force) { // -F (--force in official dpkg) diff --git a/archival/gzip.c b/archival/gzip.c index 4cf34ac28..9c53895e9 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -2216,11 +2216,12 @@ int gzip_main(int argc UNUSED_PARAM, char **argv) SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2)) + sizeof(struct globals)); -#if ENABLE_FEATURE_GZIP_LONG_OPTIONS - applet_long_options = gzip_longopts; -#endif /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ +#if ENABLE_FEATURE_GZIP_LONG_OPTIONS + opt = getopt32long(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789", gzip_longopts); +#else opt = getopt32(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789"); +#endif #if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */ if (opt & 0x30) // -d and/or -t return gunzip_main(argc, argv); diff --git a/archival/tar.c b/archival/tar.c index f62b33005..44ab246c0 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -940,6 +940,11 @@ static const char tar_longopts[] ALIGN1 = "exclude\0" Required_argument "\xff" # endif ; +# define GETOPT32 getopt32long +# define LONGOPTS ,tar_longopts +#else +# define GETOPT32 getopt32 +# define LONGOPTS #endif int tar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; @@ -980,9 +985,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv) ":\xf9+" // --strip-components=NUM #endif ; -#if ENABLE_FEATURE_TAR_LONG_OPTIONS - applet_long_options = tar_longopts; -#endif #if ENABLE_DESKTOP /* Lie to buildroot when it starts asking stupid questions. */ if (argv[1] && strcmp(argv[1], "--version") == 0) { @@ -1019,7 +1021,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv) } } #endif - opt = getopt32(argv, + opt = GETOPT32(argv, "txC:f:Oopvk" IF_FEATURE_TAR_CREATE( "ch" ) IF_FEATURE_SEAMLESS_BZ2( "j" ) @@ -1030,6 +1032,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_SEAMLESS_Z( "Z" ) IF_FEATURE_TAR_NOPRESERVE_TIME("m") IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components + LONGOPTS , &base_dir // -C dir , &tar_filename // -f filename IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T diff --git a/coreutils/chown.c b/coreutils/chown.c index 1bfc725cc..0c77529ec 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c @@ -127,11 +127,12 @@ int chown_main(int argc UNUSED_PARAM, char **argv) int opt, flags; struct param_t param; -#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS - applet_long_options = chown_longopts; -#endif opt_complementary = "-2"; +#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS + opt = getopt32long(argv, OPT_STR, chown_longopts); +#else opt = getopt32(argv, OPT_STR); +#endif argv += optind; /* This matches coreutils behavior (almost - see below) */ diff --git a/coreutils/cp.c b/coreutils/cp.c index 092e39583..fe408950a 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c @@ -81,7 +81,7 @@ int cp_main(int argc, char **argv) // -a = -pdR opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR"; #if ENABLE_FEATURE_CP_LONG_OPTIONS - applet_long_options = + flags = getopt32long(argv, FILEUTILS_CP_OPTSTR, "archive\0" No_argument "a" "force\0" No_argument "f" "interactive\0" No_argument "i" @@ -94,9 +94,10 @@ int cp_main(int argc, char **argv) "update\0" No_argument "u" "remove-destination\0" No_argument "\xff" "parents\0" No_argument "\xfe" - ; -#endif + ); +#else flags = getopt32(argv, FILEUTILS_CP_OPTSTR); +#endif /* Options of cp from GNU coreutils 6.10: * -a, --archive * -f, --force diff --git a/coreutils/date.c b/coreutils/date.c index 5a4ad5fe5..33f210434 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -194,9 +194,8 @@ int date_main(int argc UNUSED_PARAM, char **argv) opt_complementary = "d--s:s--d" IF_FEATURE_DATE_ISOFMT(":R--I:I--R"); - IF_LONG_OPTS(applet_long_options = date_longopts;) - opt = getopt32(argv, "Rs:ud:r:" - IF_FEATURE_DATE_ISOFMT("I::D:"), + opt = getopt32long(argv, "Rs:ud:r:" + IF_FEATURE_DATE_ISOFMT("I::D:"), date_longopts, &date_str, &date_str, &filename IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt)); argv += optind; diff --git a/coreutils/env.c b/coreutils/env.c index 3242446f5..20453e871 100644 --- a/coreutils/env.c +++ b/coreutils/env.c @@ -30,11 +30,6 @@ //config: env is used to set an environment variable and run //config: a command; without options it displays the current //config: environment. -//config: -//config:config FEATURE_ENV_LONG_OPTIONS -//config: bool "Enable long options" -//config: default y -//config: depends on ENV && LONG_OPTS //applet:IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env)) @@ -53,23 +48,17 @@ #include "libbb.h" -#if ENABLE_FEATURE_ENV_LONG_OPTIONS -static const char env_longopts[] ALIGN1 = - "ignore-environment\0" No_argument "i" - "unset\0" Required_argument "u" - ; -#endif - int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int env_main(int argc UNUSED_PARAM, char **argv) { unsigned opts; llist_t *unset_env = NULL; -#if ENABLE_FEATURE_ENV_LONG_OPTIONS - applet_long_options = env_longopts; -#endif - opts = getopt32(argv, "+iu:+", &unset_env); + opts = getopt32long(argv, "+iu:+", + "ignore-environment\0" No_argument "i" + "unset\0" Required_argument "u" + , &unset_env + ); argv += optind; if (argv[0] && LONE_DASH(argv[0])) { opts |= 1; diff --git a/coreutils/expand.c b/coreutils/expand.c index 64f2a539d..fa3ff18f4 100644 --- a/coreutils/expand.c +++ b/coreutils/expand.c @@ -26,21 +26,11 @@ //config: help //config: By default, convert all tabs to spaces. //config: -//config:config FEATURE_EXPAND_LONG_OPTIONS -//config: bool "Enable long options" -//config: default y -//config: depends on EXPAND && LONG_OPTS -//config: //config:config UNEXPAND //config: bool "unexpand (6 kb)" //config: default y //config: help //config: By default, convert only leading sequences of blanks to tabs. -//config: -//config:config FEATURE_UNEXPAND_LONG_OPTIONS -//config: bool "Enable long options" -//config: default y -//config: depends on UNEXPAND && LONG_OPTS //applet:IF_EXPAND(APPLET(expand, BB_DIR_USR_BIN, BB_SUID_DROP)) // APPLET_ODDNAME:name main location suid_type help @@ -53,29 +43,16 @@ //usage: "[-i] [-t N] [FILE]..." //usage:#define expand_full_usage "\n\n" //usage: "Convert tabs to spaces, writing to stdout\n" -//usage: IF_FEATURE_EXPAND_LONG_OPTIONS( -//usage: "\n -i,--initial Don't convert tabs after non blanks" -//usage: "\n -t,--tabs N Tabstops every N chars" -//usage: ) -//usage: IF_NOT_FEATURE_EXPAND_LONG_OPTIONS( //usage: "\n -i Don't convert tabs after non blanks" //usage: "\n -t Tabstops every N chars" -//usage: ) //usage:#define unexpand_trivial_usage //usage: "[-fa][-t N] [FILE]..." //usage:#define unexpand_full_usage "\n\n" //usage: "Convert spaces to tabs, writing to stdout\n" -//usage: IF_FEATURE_UNEXPAND_LONG_OPTIONS( -//usage: "\n -a,--all Convert all blanks" -//usage: "\n -f,--first-only Convert only leading blanks" -//usage: "\n -t,--tabs N Tabstops every N chars" -//usage: ) -//usage: IF_NOT_FEATURE_UNEXPAND_LONG_OPTIONS( //usage: "\n -a Convert all blanks" //usage: "\n -f Convert only leading blanks" //usage: "\n -t N Tabstops every N chars" -//usage: ) #include "libbb.h" #include "unicode.h" @@ -188,31 +165,23 @@ int expand_main(int argc UNUSED_PARAM, char **argv) unsigned opt; int exit_status = EXIT_SUCCESS; -#if ENABLE_FEATURE_EXPAND_LONG_OPTIONS - static const char expand_longopts[] ALIGN1 = - /* name, has_arg, val */ - "initial\0" No_argument "i" - "tabs\0" Required_argument "t" - ; -#endif -#if ENABLE_FEATURE_UNEXPAND_LONG_OPTIONS - static const char unexpand_longopts[] ALIGN1 = - /* name, has_arg, val */ - "first-only\0" No_argument "i" - "tabs\0" Required_argument "t" - "all\0" No_argument "a" - ; -#endif init_unicode(); if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) { - IF_FEATURE_EXPAND_LONG_OPTIONS(applet_long_options = expand_longopts); - opt = getopt32(argv, "it:", &opt_t); + opt = getopt32long(argv, "it:", + "initial\0" No_argument "i" + "tabs\0" Required_argument "t" + , &opt_t + ); } else { - IF_FEATURE_UNEXPAND_LONG_OPTIONS(applet_long_options = unexpand_longopts); /* -t NUM sets also -a */ opt_complementary = "ta"; - opt = getopt32(argv, "ft:a", &opt_t); + opt = getopt32long(argv, "ft:a", + "first-only\0" No_argument "i" + "tabs\0" Required_argument "t" + "all\0" No_argument "a" + , &opt_t + ); /* -f --first-only is the default */ if (!(opt & OPT_ALL)) opt |= OPT_INITIAL; } diff --git a/coreutils/install.c b/coreutils/install.c index a1342bb13..c01750f81 100644 --- a/coreutils/install.c +++ b/coreutils/install.c @@ -55,12 +55,17 @@ static const char install_longopts[] ALIGN1 = "target-directory\0" Required_argument "t" /* autofs build insists of using -b --suffix=.orig */ /* TODO? (short option for --suffix is -S) */ -#if ENABLE_SELINUX +# if ENABLE_SELINUX "context\0" Required_argument "Z" "preserve_context\0" No_argument "\xff" "preserve-context\0" No_argument "\xff" -#endif +# endif ; +# define GETOPT32 getopt32long +# define LONGOPTS install_longopts, +#else +# define GETOPT32 getopt32 +# define LONGOPTS #endif @@ -135,15 +140,14 @@ int install_main(int argc, char **argv) #endif }; -#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS - applet_long_options = install_longopts; -#endif opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")); /* -c exists for backwards compatibility, it's needed */ /* -b is ignored ("make a backup of each existing destination file") */ - opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"), + opts = GETOPT32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"), + LONGOPTS &gid_str, &mode_str, &uid_str, &last - IF_SELINUX(, &scontext)); + IF_SELINUX(, &scontext) + ); argc -= optind; argv += optind; diff --git a/coreutils/ls.c b/coreutils/ls.c index 0fe0345b3..0834cdc63 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -1093,7 +1093,6 @@ int ls_main(int argc UNUSED_PARAM, char **argv) #endif /* process options */ - IF_LONG_OPTS(applet_long_options = ls_longopts;) opt_complementary = /* -n and -g imply -l */ "nl:gl" @@ -1111,7 +1110,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */ /* -w NUM: */ IF_FEATURE_LS_WIDTH(":w+"); - opt = getopt32(argv, ls_options + opt = getopt32long(argv, ls_options, ls_longopts IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width) IF_FEATURE_LS_COLOR(, &color_opt) ); diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c index 22851187c..986353dc6 100644 --- a/coreutils/mkdir.c +++ b/coreutils/mkdir.c @@ -18,11 +18,6 @@ //config: default y //config: help //config: mkdir is used to create directories with the specified names. -//config: -//config:config FEATURE_MKDIR_LONG_OPTIONS -//config: bool "Enable long options" -//config: default y -//config: depends on MKDIR && LONG_OPTS //applet:IF_MKDIR(APPLET_NOFORK(mkdir, mkdir, BB_DIR_BIN, BB_SUID_DROP, mkdir)) @@ -53,19 +48,6 @@ /* This is a NOFORK applet. Be very careful! */ -#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS -static const char mkdir_longopts[] ALIGN1 = - "mode\0" Required_argument "m" - "parents\0" No_argument "p" -#if ENABLE_SELINUX - "context\0" Required_argument "Z" -#endif -#if ENABLE_FEATURE_VERBOSE - "verbose\0" No_argument "v" -#endif - ; -#endif - int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int mkdir_main(int argc UNUSED_PARAM, char **argv) { @@ -78,10 +60,17 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv) security_context_t scontext; #endif -#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS - applet_long_options = mkdir_longopts; -#endif - opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext)); + opt = getopt32long(argv, "m:pv" IF_SELINUX("Z:"), + "mode\0" Required_argument "m" + "parents\0" No_argument "p" +# if ENABLE_SELINUX + "context\0" Required_argument "Z" +# endif +# if ENABLE_FEATURE_VERBOSE + "verbose\0" No_argument "v" +# endif + , &smode IF_SELINUX(,&scontext) + ); if (opt & 1) { mode_t mmode = bb_parse_mode(smode, 0777); if (mmode == (mode_t)-1) { diff --git a/coreutils/mv.c b/coreutils/mv.c index 147dd3bb2..7f6e9fef5 100644 --- a/coreutils/mv.c +++ b/coreutils/mv.c @@ -16,11 +16,6 @@ //config: default y //config: help //config: mv is used to move or rename files or directories. -//config: -//config:config FEATURE_MV_LONG_OPTIONS -//config: bool "Enable long options" -//config: default y -//config: depends on MV && LONG_OPTS //applet:IF_MV(APPLET(mv, BB_DIR_BIN, BB_SUID_DROP)) @@ -41,23 +36,6 @@ #include "libbb.h" #include "libcoreutils/coreutils.h" -#if ENABLE_FEATURE_MV_LONG_OPTIONS -static const char mv_longopts[] ALIGN1 = - "interactive\0" No_argument "i" - "force\0" No_argument "f" - "no-clobber\0" No_argument "n" - IF_FEATURE_VERBOSE( - "verbose\0" No_argument "v" - ) - ; -#endif - -#define OPT_FORCE (1 << 0) -#define OPT_INTERACTIVE (1 << 1) -#define OPT_NOCLOBBER (1 << 2) -#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE) - - int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int mv_main(int argc, char **argv) { @@ -69,15 +47,23 @@ int mv_main(int argc, char **argv) int status = 0; int copy_flag = 0; -#if ENABLE_FEATURE_MV_LONG_OPTIONS - applet_long_options = mv_longopts; -#endif +#define OPT_FORCE (1 << 0) +#define OPT_INTERACTIVE (1 << 1) +#define OPT_NOCLOBBER (1 << 2) +#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE) /* Need at least two arguments. * If more than one of -f, -i, -n is specified , only the final one * takes effect (it unsets previous options). */ opt_complementary = "-2:f-in:i-fn:n-fi"; - flags = getopt32(argv, "finv"); + flags = getopt32long(argv, "finv", + "interactive\0" No_argument "i" + "force\0" No_argument "f" + "no-clobber\0" No_argument "n" + IF_FEATURE_VERBOSE( + "verbose\0" No_argument "v" + ) + ); argc -= optind; argv += optind; last = argv[argc - 1]; diff --git a/coreutils/nl.c b/coreutils/nl.c index 93e78c490..c2f8b1042 100644 --- a/coreutils/nl.c +++ b/coreutils/nl.c @@ -57,14 +57,13 @@ int nl_main(int argc UNUSED_PARAM, char **argv) "starting-line-number\0"Required_argument "v" "number-width\0" Required_argument "w" ; - - applet_long_options = nl_longopts; #endif ns.width = 6; ns.start = 1; ns.inc = 1; ns.sep = "\t"; - getopt32(argv, "pw:+s:v:+i:+b:", &ns.width, &ns.sep, &ns.start, &ns.inc, &opt_b); + getopt32long(argv, "pw:+s:v:+i:+b:", nl_longopts, + &ns.width, &ns.sep, &ns.start, &ns.inc, &opt_b); ns.all = (opt_b[0] == 'a'); ns.nonempty = (opt_b[0] == 't'); ns.empty_str = xasprintf("%*s\n", ns.width + (int)strlen(ns.sep), ""); diff --git a/coreutils/nproc.c b/coreutils/nproc.c index 0ae55e70a..336b176ca 100644 --- a/coreutils/nproc.c +++ b/coreutils/nproc.c @@ -28,7 +28,6 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) unsigned long mask[1024]; unsigned i, count = 0; - //applet_long_options = ...; //getopt32(argv, ""); //if --all, count /sys/devices/system/cpu/cpuN dirs, else: diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index fa0196ca4..f19875c42 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -61,8 +61,8 @@ enum { OPT_traditional = (1 << 18) * ENABLE_LONG_OPTS, }; -#define OD_GETOPT32() getopt32(argv, \ - "A:N:abcdfhij:lot:*vxsS:w:+:", \ +#define OD_GETOPT32() getopt32long(argv, \ + "A:N:abcdfhij:lot:*vxsS:w:+:", od_longopts, \ /* -w with optional param */ \ /* -S was -s and also had optional parameter */ \ /* but in coreutils 6.3 it was renamed and now has */ \ @@ -1213,9 +1213,6 @@ int od_main(int argc UNUSED_PARAM, char **argv) address_pad_len_char = '7'; /* Parse command line */ -#if ENABLE_LONG_OPTS - applet_long_options = od_longopts; -#endif opt = OD_GETOPT32(); argv += optind; if (opt & OPT_A) { diff --git a/coreutils/rmdir.c b/coreutils/rmdir.c index c04ce78f8..955740494 100644 --- a/coreutils/rmdir.c +++ b/coreutils/rmdir.c @@ -11,14 +11,6 @@ //config: default y //config: help //config: rmdir is used to remove empty directories. -//config: -//config:config FEATURE_RMDIR_LONG_OPTIONS -//config: bool "Enable long options" -//config: default y -//config: depends on RMDIR && LONG_OPTS -//config: help -//config: Support long options for the rmdir applet, including -//config: --ignore-fail-on-non-empty for compatibility with GNU rmdir. //applet:IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, BB_DIR_BIN, BB_SUID_DROP, rmdir)) @@ -31,12 +23,9 @@ //usage: "[OPTIONS] DIRECTORY..." //usage:#define rmdir_full_usage "\n\n" //usage: "Remove DIRECTORY if it is empty\n" -//usage: IF_FEATURE_RMDIR_LONG_OPTIONS( -//usage: "\n -p|--parents Include parents" -//usage: "\n --ignore-fail-on-non-empty" -//usage: ) -//usage: IF_NOT_FEATURE_RMDIR_LONG_OPTIONS( //usage: "\n -p Include parents" +//usage: IF_LONG_OPTS( +//usage: "\n --ignore-fail-on-non-empty" //usage: ) //usage: //usage:#define rmdir_example_usage @@ -49,7 +38,7 @@ #define PARENTS (1 << 0) #define VERBOSE ((1 << 1) * ENABLE_FEATURE_VERBOSE) -#define IGNORE_NON_EMPTY (1 << 2) +#define IGNORE_NON_EMPTY ((1 << 2) * ENABLE_LONG_OPTS) int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int rmdir_main(int argc UNUSED_PARAM, char **argv) @@ -58,8 +47,7 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv) int flags; char *path; -#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS - static const char rmdir_longopts[] ALIGN1 = + flags = getopt32long(argv, "pv", "parents\0" No_argument "p" /* Debian etch: many packages fail to be purged or installed * because they desperately want this option: */ @@ -67,10 +55,7 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_VERBOSE( "verbose\0" No_argument "v" ) - ; - applet_long_options = rmdir_longopts; -#endif - flags = getopt32(argv, "pv"); + ); argv += optind; if (!*argv) { @@ -86,7 +71,7 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv) } if (rmdir(path) < 0) { -#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS +#if ENABLE_LONG_OPTS if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY) break; #endif diff --git a/coreutils/touch.c b/coreutils/touch.c index 11b40d427..857761578 100644 --- a/coreutils/touch.c +++ b/coreutils/touch.c @@ -103,6 +103,11 @@ int touch_main(int argc UNUSED_PARAM, char **argv) "date\0" Required_argument "d" IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h") ; +# define GETOPT32 getopt32long +# define LONGOPTS ,touch_longopts +# else +# define GETOPT32 getopt32 +# define LONGOPTS # endif char *reference_file = NULL; char *date_str = NULL; @@ -112,17 +117,17 @@ int touch_main(int argc UNUSED_PARAM, char **argv) # define reference_file NULL # define date_str NULL # define timebuf ((struct timeval*)NULL) +# define GETOPT32 getopt32 +# define LONGOPTS #endif -#if ENABLE_FEATURE_TOUCH_SUSV3 && ENABLE_LONG_OPTS - applet_long_options = touch_longopts; -#endif /* -d and -t both set time. In coreutils, * accepted data format differs a bit between -d and -t. * We accept the same formats for both */ - opts = getopt32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:") + opts = GETOPT32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:") IF_FEATURE_TOUCH_NODEREF("h") /*ignored:*/ "fma" + LONGOPTS IF_FEATURE_TOUCH_SUSV3(, &reference_file) IF_FEATURE_TOUCH_SUSV3(, &date_str) IF_FEATURE_TOUCH_SUSV3(, &date_str) diff --git a/coreutils/uname.c b/coreutils/uname.c index be9a3f90d..bb2d1fe8d 100644 --- a/coreutils/uname.c +++ b/coreutils/uname.c @@ -147,8 +147,7 @@ int uname_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) "operating-system\0" No_argument "o" ; # endif - IF_LONG_OPTS(applet_long_options = uname_longopts); - toprint = getopt32(argv, options); + toprint = getopt32long(argv, options, uname_longopts); if (argv[optind]) { /* coreutils-6.9 compat */ bb_show_usage(); } diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index c6a90a486..b770383c4 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c @@ -159,10 +159,15 @@ static const char runparts_longopts[] ALIGN1 = "reverse\0" No_argument "\xf0" "test\0" No_argument "\xf1" "exit-on-error\0" No_argument "\xf2" -#if ENABLE_FEATURE_RUN_PARTS_FANCY +# if ENABLE_FEATURE_RUN_PARTS_FANCY "list\0" No_argument "\xf3" -#endif +# endif ; +# define GETOPT32 getopt32long +# define LONGOPTS ,runparts_longopts +#else +# define GETOPT32 getopt32 +# define LONGOPTS #endif int run_parts_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; @@ -175,12 +180,9 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv) INIT_G(); -#if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS - applet_long_options = runparts_longopts; -#endif /* We require exactly one argument: the directory name */ opt_complementary = "=1"; - getopt32(argv, "a:*u:", &arg_list, &umask_p); + GETOPT32(argv, "a:*u:" LONGOPTS, &arg_list, &umask_p); umask(xstrtou_range(umask_p, 8, 0, 07777)); diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 9effdc80b..45c277a53 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c @@ -426,6 +426,11 @@ static const char start_stop_daemon_longopts[] ALIGN1 = "retry\0" Required_argument "R" # endif ; +# define GETOPT32 getopt32long +# define LONGOPTS start_stop_daemon_longopts, +#else +# define GETOPT32 getopt32 +# define LONGOPTS #endif int start_stop_daemon_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; @@ -446,10 +451,6 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) INIT_G(); -#if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS - applet_long_options = start_stop_daemon_longopts; -#endif - /* -K or -S is required; they are mutually exclusive */ /* -p is required if -m is given */ /* -xpun (at least one) is required if -K is given */ @@ -457,8 +458,9 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) /* -q turns off -v */ opt_complementary = "K:S:K--S:S--K:m?p:K?xpun:S?xa" IF_FEATURE_START_STOP_DAEMON_FANCY("q-v"); - opt = getopt32(argv, "KSbqtma:n:s:u:c:x:p:" + opt = GETOPT32(argv, "KSbqtma:n:s:u:c:x:p:" IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"), + LONGOPTS &startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile IF_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N) /* We accept and ignore -R / --retry */ diff --git a/editors/diff.c b/editors/diff.c index 03c13908e..d90ac8f94 100644 --- a/editors/diff.c +++ b/editors/diff.c @@ -967,6 +967,11 @@ static const char diff_longopts[] ALIGN1 = "starting-file\0" Required_argument "S" "minimal\0" No_argument "d" ; +# define GETOPT32 getopt32long +# define LONGOPTS ,diff_longopts +#else +# define GETOPT32 getopt32 +# define LONGOPTS #endif int diff_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; @@ -980,10 +985,7 @@ int diff_main(int argc UNUSED_PARAM, char **argv) /* exactly 2 params; collect multiple -L