getopt32: remove opt_complementary

function                                             old     new   delta
vgetopt32                                           1318    1392     +74
runsvdir_main                                        703     713     +10
bb_make_directory                                    423     425      +2
collect_cpu                                          546     545      -1
opt_chars                                              3       -      -3
opt_complementary                                      4       -      -4
tftpd_main                                           567     562      -5
ntp_init                                             476     471      -5
zcip_main                                           1266    1256     -10
xxd_main                                             428     418     -10
whois_main                                           140     130     -10
who_main                                             463     453     -10
which_main                                           212     202     -10
wget_main                                           2535    2525     -10
watchdog_main                                        291     281     -10
watch_main                                           222     212     -10
vlock_main                                           399     389     -10
uuencode_main                                        332     322     -10
uudecode_main                                        316     306     -10
unlink_main                                           45      35     -10
udhcpd_main                                         1482    1472     -10
udhcpc_main                                         2762    2752     -10
tune2fs_main                                         290     280     -10
tunctl_main                                          366     356     -10
truncate_main                                        218     208     -10
tr_main                                              518     508     -10
time_main                                           1134    1124     -10
tftp_main                                            286     276     -10
telnetd_main                                        1873    1863     -10
tcpudpsvd_main                                      1785    1775     -10
taskset_main                                         521     511     -10
tar_main                                            1009     999     -10
tail_main                                           1644    1634     -10
syslogd_main                                        1967    1957     -10
switch_root_main                                     368     358     -10
svlogd_main                                         1454    1444     -10
sv                                                  1296    1286     -10
stat_main                                            104      94     -10
start_stop_daemon_main                              1028    1018     -10
split_main                                           542     532     -10
sort_main                                            796     786     -10
slattach_main                                        624     614     -10
shuf_main                                            504     494     -10
setsid_main                                           96      86     -10
setserial_main                                      1132    1122     -10
setfont_main                                         388     378     -10
setconsole_main                                       78      68     -10
sendmail_main                                       1209    1199     -10
sed_main                                             677     667     -10
script_main                                         1077    1067     -10
run_parts_main                                       325     315     -10
rtcwake_main                                         454     444     -10
rm_main                                              175     165     -10
reformime_main                                       119     109     -10
readlink_main                                        123     113     -10
rdate_main                                           246     236     -10
pwdx_main                                            189     179     -10
pstree_main                                          317     307     -10
pscan_main                                           663     653     -10
popmaildir_main                                      818     808     -10
pmap_main                                             80      70     -10
nc_main                                             1042    1032     -10
mv_main                                              558     548     -10
mountpoint_main                                      477     467     -10
mount_main                                          1264    1254     -10
modprobe_main                                        768     758     -10
modinfo_main                                         333     323     -10
mktemp_main                                          200     190     -10
mkswap_main                                          324     314     -10
mkfs_vfat_main                                      1489    1479     -10
microcom_main                                        715     705     -10
md5_sha1_sum_main                                    521     511     -10
man_main                                             867     857     -10
makedevs_main                                       1052    1042     -10
ls_main                                              563     553     -10
losetup_main                                         432     422     -10
loadfont_main                                         89      79     -10
ln_main                                              524     514     -10
link_main                                             75      65     -10
ipcalc_main                                          544     534     -10
iostat_main                                         2397    2387     -10
install_main                                         768     758     -10
id_main                                              480     470     -10
i2cset_main                                         1239    1229     -10
i2cget_main                                          380     370     -10
i2cdump_main                                        1482    1472     -10
i2cdetect_main                                       682     672     -10
hwclock_main                                         406     396     -10
httpd_main                                           741     731     -10
grep_main                                            837     827     -10
getty_main                                          1559    1549     -10
fuser_main                                           297     287     -10
ftpgetput_main                                       345     335     -10
ftpd_main                                           2232    2222     -10
fstrim_main                                          251     241     -10
fsfreeze_main                                         77      67     -10
fsck_minix_main                                     2921    2911     -10
flock_main                                           314     304     -10
flashcp_main                                         740     730     -10
flash_eraseall_main                                  833     823     -10
fdformat_main                                        532     522     -10
expand_main                                          680     670     -10
eject_main                                           335     325     -10
dumpleases_main                                      630     620     -10
du_main                                              314     304     -10
dos2unix_main                                        441     431     -10
diff_main                                           1350    1340     -10
df_main                                             1064    1054     -10
date_main                                           1095    1085     -10
cut_main                                             961     951     -10
cryptpw_main                                         228     218     -10
crontab_main                                         575     565     -10
crond_main                                          1149    1139     -10
cp_main                                              370     360     -10
common_traceroute_main                              3834    3824     -10
common_ping_main                                    1767    1757     -10
comm_main                                            239     229     -10
cmp_main                                             655     645     -10
chrt_main                                            379     369     -10
chpst_main                                           704     694     -10
chpasswd_main                                        308     298     -10
chown_main                                           171     161     -10
chmod_main                                           158     148     -10
cat_main                                             428     418     -10
bzip2_main                                           120     110     -10
blkdiscard_main                                      264     254     -10
base64_main                                          221     211     -10
arping_main                                         1665    1655     -10
ar_main                                              556     546     -10
adjtimex_main                                        406     396     -10
adduser_main                                         882     872     -10
addgroup_main                                        411     401     -10
acpid_main                                          1198    1188     -10
optstring                                             11       -     -11
opt_string                                            18       -     -18
OPT_STR                                               25       -     -25
ubi_tools_main                                      1288    1258     -30
ls_options                                            31       -     -31
------------------------------------------------------------------------------
(add/remove: 0/6 grow/shrink: 3/129 up/down: 86/-1383)      Total: -1297 bytes
   text	   data	    bss	    dec	    hex	filename
 915428	    485	   6876	 922789	  e14a5	busybox_old
 914629	    485	   6872	 921986	  e1182	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2017-08-08 21:55:02 +02:00
parent 036585a911
commit 22542eca18
143 changed files with 598 additions and 503 deletions

View File

@ -243,10 +243,13 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
/* prepend '-' to the first argument if required */ /* prepend '-' to the first argument if required */
if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0')
argv[1] = xasprintf("-%s", argv[1]); argv[1] = xasprintf("-%s", argv[1]);
/* -1: at least one param is reqd */ opt = getopt32(argv, "^"
/* one of p,t,x[,r] is required */ "voc""ptx"IF_FEATURE_AR_CREATE("r")
opt_complementary = "-1:p:t:x"IF_FEATURE_AR_CREATE(":r"); "\0"
opt = getopt32(argv, "voc""ptx"IF_FEATURE_AR_CREATE("r")); /* -1: at least one arg is reqd */
/* one of p,t,x[,r] is required */
"-1:p:t:x"IF_FEATURE_AR_CREATE(":r")
);
argv += optind; argv += optind;
t = opt / FIRST_CMD; t = opt / FIRST_CMD;

View File

@ -195,9 +195,11 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
* --best alias for -9 * --best alias for -9
*/ */
opt_complementary = "s2"; /* -s means -2 (compatibility) */ opt = getopt32(argv, "^"
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfkv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs"); "cfkv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs"
"\0" "s2" /* -s means -2 (compatibility) */
);
#if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */ #if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */
if (opt & 0x30) // -d and/or -t if (opt & 0x30) // -d and/or -t
return bunzip2_main(argc, argv); return bunzip2_main(argc, argv);

View File

@ -80,8 +80,9 @@ int dpkg_deb_main(int argc UNUSED_PARAM, char **argv)
#endif #endif
/* Must have 1 or 2 args */ /* Must have 1 or 2 args */
opt_complementary = "-1:?2:c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"; opt = getopt32(argv, "^" "cefXx"
opt = getopt32(argv, "cefXx"); "\0" "-1:?2:c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"
);
argv += optind; argv += optind;
//argc -= optind; //argc -= optind;

View File

@ -1138,7 +1138,7 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
/* -U is "anti -k", invert bit for bbunpack(): */ /* -U is "anti -k", invert bit for bbunpack(): */
option_mask32 ^= OPT_KEEP; option_mask32 ^= OPT_KEEP;
/* -k disables -U (if any): */ /* -k disables -U (if any): */
/* opt_complementary = "k-U"; - nope, only handles -Uk, not -kU */ /* opt_complementary "k-U"? - nope, only handles -Uk, not -kU */
if (option_mask32 & OPT_k) if (option_mask32 & OPT_k)
option_mask32 |= OPT_KEEP; option_mask32 |= OPT_KEEP;

View File

@ -973,18 +973,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
/* Prepend '-' to the first argument if required */ /* Prepend '-' to the first argument if required */
if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0')
argv[1] = xasprintf("-%s", argv[1]); argv[1] = xasprintf("-%s", argv[1]);
opt_complementary =
"tt:vv:" // count -t,-v
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
"\xff::" // --exclude=PATTERN is a list
#endif
IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
":\xf9+" // --strip-components=NUM
#endif
;
#if ENABLE_DESKTOP #if ENABLE_DESKTOP
/* Lie to buildroot when it starts asking stupid questions. */ /* Lie to buildroot when it starts asking stupid questions. */
if (argv[1] && strcmp(argv[1], "--version") == 0) { if (argv[1] && strcmp(argv[1], "--version") == 0) {
@ -1021,7 +1009,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
} }
} }
#endif #endif
opt = GETOPT32(argv, opt = GETOPT32(argv, "^"
"txC:f:Oopvk" "txC:f:Oopvk"
IF_FEATURE_TAR_CREATE( "ch" ) IF_FEATURE_TAR_CREATE( "ch" )
IF_FEATURE_SEAMLESS_BZ2( "j" ) IF_FEATURE_SEAMLESS_BZ2( "j" )
@ -1032,6 +1020,17 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
IF_FEATURE_SEAMLESS_Z( "Z" ) IF_FEATURE_SEAMLESS_Z( "Z" )
IF_FEATURE_TAR_NOPRESERVE_TIME("m") IF_FEATURE_TAR_NOPRESERVE_TIME("m")
IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
"\0"
"tt:vv:" // count -t,-v
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
"\xff::" // --exclude=PATTERN is a list
#endif
IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
":\xf9+" // --strip-components=NUM
#endif
LONGOPTS LONGOPTS
, &base_dir // -C dir , &base_dir // -C dir
, &tar_filename // -f filename , &tar_filename // -f filename

View File

@ -348,8 +348,7 @@ int loadfont_main(int argc UNUSED_PARAM, char **argv)
unsigned char *buffer; unsigned char *buffer;
// no arguments allowed! // no arguments allowed!
opt_complementary = "=0"; getopt32(argv, "^" "" "\0" "=0");
getopt32(argv, "");
/* /*
* We used to look at the length of the input file * We used to look at the length of the input file
@ -437,8 +436,7 @@ int setfont_main(int argc UNUSED_PARAM, char **argv)
char *mapfilename; char *mapfilename;
const char *tty_name = CURRENT_TTY; const char *tty_name = CURRENT_TTY;
opt_complementary = "=1"; opts = getopt32(argv, "^" "m:C:" "\0" "=1", &mapfilename, &tty_name);
opts = getopt32(argv, "m:C:", &mapfilename, &tty_name);
argv += optind; argv += optind;
fd = xopen_nonblocking(tty_name); fd = xopen_nonblocking(tty_name);

View File

@ -47,8 +47,7 @@ int setconsole_main(int argc UNUSED_PARAM, char **argv)
int reset; int reset;
/* at most one non-option argument */ /* at most one non-option argument */
opt_complementary = "?1"; reset = getopt32(argv, "^" "r" "\0" "?1");
reset = getopt32(argv, "r");
argv += 1 + reset; argv += 1 + reset;
if (*argv) { if (*argv) {

View File

@ -170,9 +170,11 @@ int cat_main(int argc UNUSED_PARAM, char **argv)
{ {
unsigned opts; unsigned opts;
IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */) opts = getopt32(argv, IF_FEATURE_CATV("^")
/* -u is ignored ("unbuffered") */ /* -u is ignored ("unbuffered") */
opts = getopt32(argv, IF_FEATURE_CATV("etvA") IF_FEATURE_CATN("nb") "u"); IF_FEATURE_CATV("etvA")IF_FEATURE_CATN("nb")"u"
IF_FEATURE_CATV("\0" "Aetv" /* -A == -vet */)
);
argv += optind; argv += optind;
/* Read from stdin if there's nothing else to do. */ /* Read from stdin if there's nothing else to do. */

View File

@ -123,8 +123,7 @@ int chmod_main(int argc UNUSED_PARAM, char **argv)
} }
/* Parse options */ /* Parse options */
opt_complementary = "-2"; getopt32(argv, "^" OPT_STR "\0" "-2");
getopt32(argv, ("-"OPT_STR) + 1); /* Reuse string */
argv += optind; argv += optind;
/* Restore option-like mode if needed */ /* Restore option-like mode if needed */

View File

@ -55,7 +55,7 @@
/* This is a NOEXEC applet. Be very careful! */ /* This is a NOEXEC applet. Be very careful! */
#define OPT_STR ("Rh" IF_DESKTOP("vcfLHP")) #define OPT_STR "Rh" IF_DESKTOP("vcfLHP")
#define BIT_RECURSE 1 #define BIT_RECURSE 1
#define OPT_RECURSE (opt & 1) #define OPT_RECURSE (opt & 1)
#define OPT_NODEREF (opt & 2) #define OPT_NODEREF (opt & 2)
@ -127,11 +127,10 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
int opt, flags; int opt, flags;
struct param_t param; struct param_t param;
opt_complementary = "-2";
#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS #if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
opt = getopt32long(argv, OPT_STR, chown_longopts); opt = getopt32long(argv, "^" OPT_STR "\0" "=2", chown_longopts);
#else #else
opt = getopt32(argv, OPT_STR); opt = getopt32(argv, "^" OPT_STR "\0" "=2");
#endif #endif
argv += optind; argv += optind;

View File

@ -62,8 +62,7 @@ int comm_main(int argc UNUSED_PARAM, char **argv)
int i; int i;
int order; int order;
opt_complementary = "=2"; getopt32(argv, "^" "123" "\0" "=2");
getopt32(argv, "123");
argv += optind; argv += optind;
for (i = 0; i < 2; ++i) { for (i = 0; i < 2; ++i) {

View File

@ -73,15 +73,17 @@ int cp_main(int argc, char **argv)
#endif #endif
}; };
// Need at least two arguments
// Soft- and hardlinking doesn't mix
// -P and -d are the same (-P is POSIX, -d is GNU)
// -r and -R are the same
// -R (and therefore -r) turns on -d (coreutils does this)
// -a = -pdR
opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR";
#if ENABLE_FEATURE_CP_LONG_OPTIONS #if ENABLE_FEATURE_CP_LONG_OPTIONS
flags = getopt32long(argv, FILEUTILS_CP_OPTSTR, flags = getopt32long(argv, "^"
FILEUTILS_CP_OPTSTR
"\0"
// Need at least two arguments
// Soft- and hardlinking doesn't mix
// -P and -d are the same (-P is POSIX, -d is GNU)
// -r and -R are the same
// -R (and therefore -r) turns on -d (coreutils does this)
// -a = -pdR
"-2:l--s:s--l:Pd:rRd:Rd:apdR",
"archive\0" No_argument "a" "archive\0" No_argument "a"
"force\0" No_argument "f" "force\0" No_argument "f"
"interactive\0" No_argument "i" "interactive\0" No_argument "i"

View File

@ -42,7 +42,7 @@
/* option vars */ /* option vars */
static const char optstring[] ALIGN1 = "b:c:f:d:sn"; #define OPT_STR "b:c:f:d:sn"
#define CUT_OPT_BYTE_FLGS (1 << 0) #define CUT_OPT_BYTE_FLGS (1 << 0)
#define CUT_OPT_CHAR_FLGS (1 << 1) #define CUT_OPT_CHAR_FLGS (1 << 1)
#define CUT_OPT_FIELDS_FLGS (1 << 2) #define CUT_OPT_FIELDS_FLGS (1 << 2)
@ -201,8 +201,11 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
char *sopt, *ltok; char *sopt, *ltok;
unsigned opt; unsigned opt;
opt_complementary = "b--bcf:c--bcf:f--bcf"; opt = getopt32(argv, "^"
opt = getopt32(argv, optstring, &sopt, &sopt, &sopt, &ltok); OPT_STR
"\0" "b--bcf:c--bcf:f--bcf",
&sopt, &sopt, &sopt, &ltok
);
// argc -= optind; // argc -= optind;
argv += optind; argv += optind;
if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))

View File

@ -192,12 +192,16 @@ int date_main(int argc UNUSED_PARAM, char **argv)
char *filename; char *filename;
char *isofmt_arg = NULL; char *isofmt_arg = NULL;
opt_complementary = "d--s:s--d" opt = getopt32long(argv, "^"
IF_FEATURE_DATE_ISOFMT(":R--I:I--R"); "Rs:ud:r:"
opt = getopt32long(argv, "Rs:ud:r:" IF_FEATURE_DATE_ISOFMT("I::D:")
IF_FEATURE_DATE_ISOFMT("I::D:"), date_longopts, "\0"
"d--s:s--d"
IF_FEATURE_DATE_ISOFMT(":R--I:I--R"),
date_longopts,
&date_str, &date_str, &filename &date_str, &date_str, &filename
IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt)); IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt)
);
argv += optind; argv += optind;
maybe_set_utc(opt); maybe_set_utc(opt);

View File

@ -115,15 +115,18 @@ int df_main(int argc UNUSED_PARAM, char **argv)
init_unicode(); init_unicode();
#if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY opt = getopt32(argv, "^"
opt_complementary = "k-mB:m-Bk:B-km"; "kPT"
#elif ENABLE_FEATURE_HUMAN_READABLE
opt_complementary = "k-m:m-k";
#endif
opt = getopt32(argv, "kPT"
IF_FEATURE_DF_FANCY("aiB:") IF_FEATURE_DF_FANCY("aiB:")
IF_FEATURE_HUMAN_READABLE("hm") IF_FEATURE_HUMAN_READABLE("hm")
IF_FEATURE_DF_FANCY(, &chp)); "\0"
#if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY
"k-mB:m-Bk:B-km"
#elif ENABLE_FEATURE_HUMAN_READABLE
"k-m:m-k"
#endif
IF_FEATURE_DF_FANCY(, &chp)
);
if (opt & OPT_MEGA) if (opt & OPT_MEGA)
df_disp_hr = 1024*1024; df_disp_hr = 1024*1024;

View File

@ -120,8 +120,7 @@ int dos2unix_main(int argc UNUSED_PARAM, char **argv)
} }
/* -u convert to unix, -d convert to dos */ /* -u convert to unix, -d convert to dos */
opt_complementary = "u--d:d--u"; /* mutually exclusive */ o = getopt32(argv, "^" "du" "\0" "u--d:d--u"); /* mutually exclusive */
o = getopt32(argv, "du");
/* Do the conversion requested by an argument else do the default /* Do the conversion requested by an argument else do the default
* conversion depending on our name. */ * conversion depending on our name. */

View File

@ -242,8 +242,11 @@ int du_main(int argc UNUSED_PARAM, char **argv)
* ignore -a. This is consistent with -s being equivalent to -d 0. * ignore -a. This is consistent with -s being equivalent to -d 0.
*/ */
#if ENABLE_FEATURE_HUMAN_READABLE #if ENABLE_FEATURE_HUMAN_READABLE
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; opt = getopt32(argv, "^"
opt = getopt32(argv, "aHkLsx" "d:+" "lc" "hm", &G.max_print_depth); "aHkLsxd:+lchm"
"\0" "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s",
&G.max_print_depth
);
argv += optind; argv += optind;
if (opt & OPT_h_for_humans) { if (opt & OPT_h_for_humans) {
G.disp_unit = 0; G.disp_unit = 0;
@ -255,8 +258,11 @@ int du_main(int argc UNUSED_PARAM, char **argv)
G.disp_unit = 1024; G.disp_unit = 1024;
} }
#else #else
opt_complementary = "H-L:L-H:s-d:d-s"; opt = getopt32(argv, "^"
opt = getopt32(argv, "aHkLsx" "d:+" "lc", &G.max_print_depth); "aHkLsxd:+lc"
"\0" "H-L:L-H:s-d:d-s",
&G.max_print_depth
);
argv += optind; argv += optind;
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
if (opt & OPT_k_kbytes) { if (opt & OPT_k_kbytes) {

View File

@ -174,9 +174,10 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
, &opt_t , &opt_t
); );
} else { } else {
/* -t NUM sets also -a */ opt = getopt32long(argv, "^"
opt_complementary = "ta"; "ft:a"
opt = getopt32long(argv, "ft:a", "\0"
"ta" /* -t NUM sets -a */,
"first-only\0" No_argument "i" "first-only\0" No_argument "i"
"tabs\0" Required_argument "t" "tabs\0" Required_argument "t"
"all\0" No_argument "a" "all\0" No_argument "a"

View File

@ -170,9 +170,12 @@ int id_main(int argc UNUSED_PARAM, char **argv)
} else { } else {
/* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/ /* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/
/* Don't allow more than one username */ /* Don't allow more than one username */
opt_complementary = "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG" opt = getopt32(argv, "^"
IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G"); "rnugG" IF_SELINUX("Z")
opt = getopt32(argv, "rnugG" IF_SELINUX("Z")); "\0"
"?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG"
IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G")
);
} }
username = argv[optind]; username = argv[optind];

View File

@ -140,13 +140,16 @@ int install_main(int argc, char **argv)
#endif #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 */ /* -c exists for backwards compatibility, it's needed */
/* -b is ignored ("make a backup of each existing destination file") */ /* -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, "^"
LONGOPTS "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:")
&gid_str, &mode_str, &uid_str, &last "\0"
IF_SELINUX(, &scontext) "t--d:d--t:s--d:d--s"
IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")),
LONGOPTS
&gid_str, &mode_str, &uid_str, &last
IF_SELINUX(, &scontext)
); );
argc -= optind; argc -= optind;
argv += optind; argv += optind;

View File

@ -27,8 +27,7 @@
int link_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int link_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int link_main(int argc UNUSED_PARAM, char **argv) int link_main(int argc UNUSED_PARAM, char **argv)
{ {
opt_complementary = "=2"; /* exactly 2 params */ getopt32(argv, "^" "" "\0" "=2");
getopt32(argv, "");
argv += optind; argv += optind;
if (link(argv[0], argv[1]) != 0) { if (link(argv[0], argv[1]) != 0) {
/* shared message */ /* shared message */

View File

@ -62,8 +62,7 @@ int ln_main(int argc, char **argv)
struct stat statbuf; struct stat statbuf;
int (*link_func)(const char *, const char *); int (*link_func)(const char *, const char *);
opt_complementary = "-1"; /* min one arg */ opts = getopt32(argv, "^" "sfnbS:vT" "\0" "-1", &suffix);
opts = getopt32(argv, "sfnbS:vT", &suffix);
last = argv[argc - 1]; last = argv[argc - 1];
argv += optind; argv += optind;

View File

@ -206,18 +206,18 @@ SPLIT_SUBDIR = 2,
/* -SXvhTw GNU options, busybox optionally supports */ /* -SXvhTw GNU options, busybox optionally supports */
/* -T WIDTH Ignored (we don't use tabs on output) */ /* -T WIDTH Ignored (we don't use tabs on output) */
/* -Z SELinux mandated option, busybox optionally supports */ /* -Z SELinux mandated option, busybox optionally supports */
static const char ls_options[] ALIGN1 = #define ls_options \
"Cadi1lgnsxAk" /* 12 opts, total 12 */ "Cadi1lgnsxAk" /* 12 opts, total 12 */ \
IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */ IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */ \
IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */ IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */ \
IF_SELINUX("Z") /* 1, 16 */ IF_SELINUX("Z") /* 1, 16 */ \
"Q" /* 1, 17 */ "Q" /* 1, 17 */ \
IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */ IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */ \
IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */ IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */ \
IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */ IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */ \
IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */ IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */ \
IF_FEATURE_LS_WIDTH("T:w:") /* 2, 29 */ IF_FEATURE_LS_WIDTH("T:w:") /* 2, 29 */
;
enum { enum {
OPT_C = (1 << 0), OPT_C = (1 << 0),
OPT_a = (1 << 1), OPT_a = (1 << 1),
@ -1093,24 +1093,26 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
#endif #endif
/* process options */ /* process options */
opt_complementary = opt = getopt32long(argv, "^"
/* -n and -g imply -l */ ls_options
"nl:gl" "\0"
/* --full-time implies -l */ /* -n and -g imply -l */
IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l")) "nl:gl"
/* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html: /* --full-time implies -l */
* in some pairs of opts, only last one takes effect: IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l"))
*/ /* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html:
IF_FEATURE_LS_TIMESTAMPS(IF_FEATURE_LS_SORTFILES(":t-S:S-t")) /* time/size */ * in some pairs of opts, only last one takes effect:
// ":m-l:l-m" - we don't have -m */
IF_FEATURE_LS_FOLLOWLINKS(":H-L:L-H") IF_FEATURE_LS_TIMESTAMPS(IF_FEATURE_LS_SORTFILES(":t-S:S-t")) /* time/size */
":C-xl:x-Cl:l-xC" /* bycols/bylines/long */ // ":m-l:l-m" - we don't have -m
":C-1:1-C" /* bycols/oneline */ IF_FEATURE_LS_FOLLOWLINKS(":H-L:L-H")
":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */ ":C-xl:x-Cl:l-xC" /* bycols/bylines/long */
IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */ ":C-1:1-C" /* bycols/oneline */
/* -w NUM: */ ":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */
IF_FEATURE_LS_WIDTH(":w+"); IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */
opt = getopt32long(argv, ls_options, ls_longopts /* -w NUM: */
IF_FEATURE_LS_WIDTH(":w+")
, ls_longopts
IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width) IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width)
IF_FEATURE_LS_COLOR(, &color_opt) IF_FEATURE_LS_COLOR(, &color_opt)
); );

View File

@ -258,15 +258,14 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
#endif #endif
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) { if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) {
/* -s and -w require -c */
opt_complementary = "s?c:w?c";
/* -b "binary", -t "text" are ignored (shaNNNsum compat) */ /* -b "binary", -t "text" are ignored (shaNNNsum compat) */
/* -s and -w require -c */
#if ENABLE_SHA3SUM #if ENABLE_SHA3SUM
if (applet_name[3] == HASH_SHA3) if (applet_name[3] == HASH_SHA3)
flags = getopt32(argv, "scwbta:+", &sha3_width); flags = getopt32(argv, "^" "scwbta:+" "\0" "s?c:w?c", &sha3_width);
else else
#endif #endif
flags = getopt32(argv, "scwbt"); flags = getopt32(argv, "^" "scwbt" "\0" "s?c:w?c");
} else { } else {
#if ENABLE_SHA3SUM #if ENABLE_SHA3SUM
if (applet_name[3] == HASH_SHA3) if (applet_name[3] == HASH_SHA3)

View File

@ -80,8 +80,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv)
if (!path || path[0] == '\0') if (!path || path[0] == '\0')
path = "/tmp"; path = "/tmp";
opt_complementary = "?1"; /* 1 argument max */ opts = getopt32(argv, "^" "dqtp:u" "\0" "?1"/*1 arg max*/, &path);
opts = getopt32(argv, "dqtp:u", &path);
chp = argv[optind]; chp = argv[optind];
if (!chp) { if (!chp) {

View File

@ -55,8 +55,10 @@ int mv_main(int argc, char **argv)
* If more than one of -f, -i, -n is specified , only the final one * If more than one of -f, -i, -n is specified , only the final one
* takes effect (it unsets previous options). * takes effect (it unsets previous options).
*/ */
opt_complementary = "-2:f-in:i-fn:n-fi"; flags = getopt32long(argv, "^"
flags = getopt32long(argv, "finv", "finv"
"\0"
"-2:f-in:i-fn:n-fi",
"interactive\0" No_argument "i" "interactive\0" No_argument "i"
"force\0" No_argument "f" "force\0" No_argument "f"
"no-clobber\0" No_argument "n" "no-clobber\0" No_argument "n"

View File

@ -71,8 +71,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv)
IF_FEATURE_READLINK_FOLLOW( IF_FEATURE_READLINK_FOLLOW(
unsigned opt; unsigned opt;
/* We need exactly one non-option argument. */ /* We need exactly one non-option argument. */
opt_complementary = "=1"; opt = getopt32(argv, "^" "fnvsq" "\0" "=1");
opt = getopt32(argv, "fnvsq");
fname = argv[optind]; fname = argv[optind];
) )
IF_NOT_FEATURE_READLINK_FOLLOW( IF_NOT_FEATURE_READLINK_FOLLOW(

View File

@ -46,8 +46,7 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
int flags = 0; int flags = 0;
unsigned opt; unsigned opt;
opt_complementary = "f-i:i-f"; opt = getopt32(argv, "^" "fiRrv" "\0" "f-i:i-f");
opt = getopt32(argv, "fiRrv");
argv += optind; argv += optind;
if (opt & 1) if (opt & 1)
flags |= FILEUTILS_FORCE; flags |= FILEUTILS_FORCE;

View File

@ -70,8 +70,11 @@ int shuf_main(int argc, char **argv)
unsigned numlines; unsigned numlines;
char eol; char eol;
opt_complementary = "e--i:i--e"; /* mutually exclusive */ opts = getopt32(argv, "^"
opts = getopt32(argv, OPT_STR, &opt_i_str, &opt_n_str, &opt_o_str); OPT_STR
"\0" "e--i:i--e"/* mutually exclusive */,
&opt_i_str, &opt_n_str, &opt_o_str
);
argc -= optind; argc -= optind;
argv += optind; argv += optind;

View File

@ -94,7 +94,7 @@
*/ */
/* These are sort types */ /* These are sort types */
static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:*t:"; #define OPT_STR "ngMucszbrdfimS:T:o:k:*t:"
enum { enum {
FLAG_n = 1, /* Numeric sort */ FLAG_n = 1, /* Numeric sort */
FLAG_g = 2, /* Sort using strtod() */ FLAG_g = 2, /* Sort using strtod() */
@ -378,9 +378,11 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
xfunc_error_retval = 2; xfunc_error_retval = 2;
/* Parse command line options */ /* Parse command line options */
/* -o and -t can be given at most once */ opts = getopt32(argv, "^"
opt_complementary = "o--o:t--t"; /* -t, -o: at most one of each */ OPT_STR
opts = getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t); "\0" "o--o:t--t"/*-t, -o: at most one of each*/,
&str_ignored, &str_ignored, &str_o, &lst_k, &str_t
);
/* global b strips leading and trailing spaces */ /* global b strips leading and trailing spaces */
if (opts & FLAG_b) if (opts & FLAG_b)
option_mask32 |= FLAG_bb; option_mask32 |= FLAG_bb;

View File

@ -100,8 +100,11 @@ int split_main(int argc UNUSED_PARAM, char **argv)
setup_common_bufsiz(); setup_common_bufsiz();
opt_complementary = "?2"; /* max 2 args; -a N */ opt = getopt32(argv, "^"
opt = getopt32(argv, "l:b:a:+", &count_p, &count_p, &suffix_len); "l:b:a:+" /* -a N */
"\0" "?2"/*max 2 args*/,
&count_p, &count_p, &suffix_len
);
if (opt & SPLIT_OPT_l) if (opt & SPLIT_OPT_l)
cnt = XATOOFF(count_p); cnt = XATOOFF(count_p);

View File

@ -762,11 +762,13 @@ int stat_main(int argc UNUSED_PARAM, char **argv)
unsigned opts; unsigned opts;
statfunc_ptr statfunc = do_stat; statfunc_ptr statfunc = do_stat;
opt_complementary = "-1"; /* min one arg */ opts = getopt32(argv, "^"
opts = getopt32(argv, "tL" "tL"
IF_FEATURE_STAT_FILESYSTEM("f") IF_FEATURE_STAT_FILESYSTEM("f")
IF_SELINUX("Z") IF_SELINUX("Z")
IF_FEATURE_STAT_FORMAT("c:", &format) IF_FEATURE_STAT_FORMAT("c:")
"\0" "-1" /* min one arg */
IF_FEATURE_STAT_FORMAT(,&format)
); );
#if ENABLE_FEATURE_STAT_FILESYSTEM #if ENABLE_FEATURE_STAT_FILESYSTEM
if (opts & OPT_FILESYS) /* -f */ if (opts & OPT_FILESYS) /* -f */

View File

@ -59,8 +59,7 @@ int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
OPT_SYNCFS = (1 << 1), OPT_SYNCFS = (1 << 1),
}; };
opt_complementary = "d--f:f--d"; opts = getopt32(argv, "^" "df" "\0" "d--f:f--d");
opts = getopt32(argv, "df");
argv += optind; argv += optind;
/* Handle the no-argument case. */ /* Handle the no-argument case. */

View File

@ -140,9 +140,11 @@ int tail_main(int argc, char **argv)
#endif #endif
/* -s NUM, -F imlies -f */ /* -s NUM, -F imlies -f */
IF_FEATURE_FANCY_TAIL(opt_complementary = "Ff";) opt = getopt32(argv, IF_FEATURE_FANCY_TAIL("^")
opt = getopt32(argv, "fc:n:" IF_FEATURE_FANCY_TAIL("qs:+vF"), "fc:n:"IF_FEATURE_FANCY_TAIL("qs:+vF")
&str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period)); IF_FEATURE_FANCY_TAIL("\0" "Ff"),
&str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period)
);
#define FOLLOW (opt & 0x1) #define FOLLOW (opt & 0x1)
#define COUNT_BYTES (opt & 0x2) #define COUNT_BYTES (opt & 0x2)
//if (opt & 0x1) // -f //if (opt & 0x1) // -f

View File

@ -298,8 +298,8 @@ int tr_main(int argc UNUSED_PARAM, char **argv)
* In POSIX locale, these are the same. * In POSIX locale, these are the same.
*/ */
opt_complementary = "-1"; /* '+': stop at first non-option */
opts = getopt32(argv, "+Ccds"); /* '+': stop at first non-option */ opts = getopt32(argv, "^+" "Ccds" "\0" "-1");
argv += optind; argv += optind;
str1_length = expand(*argv++, &str1); str1_length = expand(*argv++, &str1);

View File

@ -50,8 +50,7 @@ int truncate_main(int argc UNUSED_PARAM, char **argv)
OPT_SIZE = (1 << 1), OPT_SIZE = (1 << 1),
}; };
opt_complementary = "s:-1"; opts = getopt32(argv, "^" "cs:" "\0" "s:-1", &size_str);
opts = getopt32(argv, "cs:", &size_str);
if (!(opts & OPT_NOCREATE)) if (!(opts & OPT_NOCREATE))
flags |= O_CREAT; flags |= O_CREAT;

View File

@ -25,8 +25,7 @@
int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unlink_main(int argc UNUSED_PARAM, char **argv) int unlink_main(int argc UNUSED_PARAM, char **argv)
{ {
opt_complementary = "=1"; /* must have exactly 1 param */ getopt32(argv, "^" "" "\0" "=1");
getopt32(argv, "");
argv += optind; argv += optind;
xunlink(argv[0]); xunlink(argv[0]);
return 0; return 0;

View File

@ -120,8 +120,7 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
char *outname = NULL; char *outname = NULL;
char *line; char *line;
opt_complementary = "?1"; /* 1 argument max */ getopt32(argv, "^" "o:" "\0" "?1"/* 1 arg max*/, &outname);
getopt32(argv, "o:", &outname);
argv += optind; argv += optind;
if (!argv[0]) if (!argv[0])
@ -196,8 +195,7 @@ int base64_main(int argc UNUSED_PARAM, char **argv)
FILE *src_stream; FILE *src_stream;
unsigned opts; unsigned opts;
opt_complementary = "?1"; /* 1 argument max */ opts = getopt32(argv, "^" "d" "\0" "?1"/* 1 arg max*/);
opts = getopt32(argv, "d");
argv += optind; argv += optind;
if (!argv[0]) if (!argv[0])

View File

@ -49,8 +49,7 @@ int uuencode_main(int argc UNUSED_PARAM, char **argv)
tbl = bb_uuenc_tbl_std; tbl = bb_uuenc_tbl_std;
mode = 0666 & ~umask(0666); mode = 0666 & ~umask(0666);
opt_complementary = "-1:?2"; /* must have 1 or 2 args */ if (getopt32(argv, "^" "m" "\0" "-1:?2"/*must have 1 or 2 args*/)) {
if (getopt32(argv, "m")) {
tbl = bb_uuenc_tbl_base64; tbl = bb_uuenc_tbl_base64;
} }
argv += optind; argv += optind;

View File

@ -117,8 +117,7 @@ int who_main(int argc UNUSED_PARAM, char **argv)
unsigned opt; unsigned opt;
const char *fmt = "%s"; const char *fmt = "%s";
opt_complementary = "=0"; opt = getopt32(argv, do_who ? "^" "aH" "\0" "=0": "^" "" "\0" "=0");
opt = getopt32(argv, do_who ? "aH" : "");
if ((opt & 2) || do_w) /* -H or we are w */ if ((opt & 2) || do_w) /* -H or we are w */
puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST"); puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST");

View File

@ -181,8 +181,9 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
INIT_G(); INIT_G();
/* We require exactly one argument: the directory name */ /* We require exactly one argument: the directory name */
opt_complementary = "=1"; GETOPT32(argv, "^" "a:*u:" "\0" "=1" LONGOPTS,
GETOPT32(argv, "a:*u:" LONGOPTS, &arg_list, &umask_p); &arg_list, &umask_p
);
umask(xstrtou_range(umask_p, 8, 0, 07777)); umask(xstrtou_range(umask_p, 8, 0, 07777));

View File

@ -451,15 +451,17 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
INIT_G(); INIT_G();
/* -K or -S is required; they are mutually exclusive */ opt = GETOPT32(argv, "^"
/* -p is required if -m is given */ "KSbqtma:n:s:u:c:x:p:"
/* -xpun (at least one) is required if -K is given */ IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:")
/* -xa (at least one) is required if -S is given */ /* -K or -S is required; they are mutually exclusive */
/* -q turns off -v */ /* -p is required if -m is given */
opt_complementary = "K:S:K--S:S--K:m?p:K?xpun:S?xa" /* -xpun (at least one) is required if -K is given */
IF_FEATURE_START_STOP_DAEMON_FANCY("q-v"); /* -xa (at least one) is required if -S is given */
opt = GETOPT32(argv, "KSbqtma:n:s:u:c:x:p:" /* -q turns off -v */
IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"), "\0"
"K:S:K--S:S--K:m?p:K?xpun:S?xa"
IF_FEATURE_START_STOP_DAEMON_FANCY("q-v"),
LONGOPTS LONGOPTS
&startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile &startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile
IF_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N) IF_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N)

View File

@ -37,8 +37,7 @@ int which_main(int argc UNUSED_PARAM, char **argv)
if (!env_path) if (!env_path)
env_path = bb_default_root_path; env_path = bb_default_root_path;
opt_complementary = "-1"; /* at least one argument */ getopt32(argv, "^" "a" "\0" "-1"/*at least one arg*/);
getopt32(argv, "a");
argv += optind; argv += optind;
do { do {

View File

@ -71,8 +71,7 @@ int tune2fs_main(int argc UNUSED_PARAM, char **argv)
struct ext2_super_block *sb; struct ext2_super_block *sb;
int fd; int fd;
opt_complementary = "=1"; opts = getopt32(argv, "^" "L:c:i:C:" "\0" "=1", &label, &str_c, &str_i, &str_C);
opts = getopt32(argv, "L:c:i:C:", &label, &str_c, &str_i, &str_C);
if (!opts) if (!opts)
bb_show_usage(); bb_show_usage();
argv += optind; // argv[0] -- device argv += optind; // argv[0] -- device

View File

@ -36,7 +36,7 @@ static const char fmt_differ[] ALIGN1 = "%s %s differ: char %"OFF_FMT"u, line %u
// This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"u %o %o\n" // This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"u %o %o\n"
static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT"u %3o %3o\n"; static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT"u %3o %3o\n";
static const char opt_chars[] ALIGN1 = "sl"; #define OPT_STR "sl"
#define CMP_OPT_s (1<<0) #define CMP_OPT_s (1<<0)
#define CMP_OPT_l (1<<1) #define CMP_OPT_l (1<<1)
@ -52,11 +52,13 @@ int cmp_main(int argc UNUSED_PARAM, char **argv)
unsigned opt; unsigned opt;
int retval = 0; int retval = 0;
opt_complementary = "-1" opt = getopt32(argv, "^"
OPT_STR
"\0" "-1"
IF_DESKTOP(":?4") IF_DESKTOP(":?4")
IF_NOT_DESKTOP(":?2") IF_NOT_DESKTOP(":?2")
":l--s:s--l"; ":l--s:s--l"
opt = getopt32(argv, opt_chars); );
argv += optind; argv += optind;
filename1 = *argv; filename1 = *argv;

View File

@ -984,8 +984,8 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
INIT_G(); INIT_G();
/* exactly 2 params; collect multiple -L <label>; -U N */ /* exactly 2 params; collect multiple -L <label>; -U N */
opt_complementary = "=2"; GETOPT32(argv, "^" "abdiL:*NqrsS:tTU:+wupBE" "\0" "=2"
GETOPT32(argv, "abdiL:*NqrsS:tTU:+wupBE" LONGOPTS, LONGOPTS,
&L_arg, &s_start, &opt_U_context); &L_arg, &s_start, &opt_U_context);
argv += optind; argv += optind;
while (L_arg) while (L_arg)

View File

@ -1507,13 +1507,15 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
/* do normal option parsing */ /* do normal option parsing */
opt_e = opt_f = NULL; opt_e = opt_f = NULL;
opt_i = NULL; opt_i = NULL;
opt_complementary = "nn"; /* count -n */
/* -i must be first, to match OPT_in_place definition */ /* -i must be first, to match OPT_in_place definition */
/* -E is a synonym of -r: /* -E is a synonym of -r:
* GNU sed 4.2.1 mentions it in neither --help * GNU sed 4.2.1 mentions it in neither --help
* nor manpage, but does recognize it. * nor manpage, but does recognize it.
*/ */
opt = getopt32long(argv, "i::rEne:*f:*", sed_longopts, opt = getopt32long(argv, "^"
"i::rEne:*f:*"
"\0" "nn"/*count -n*/,
sed_longopts,
&opt_i, &opt_e, &opt_f, &opt_i, &opt_e, &opt_f,
&G.be_quiet); /* counter for -n */ &G.be_quiet); /* counter for -n */
//argc -= optind; //argc -= optind;

View File

@ -107,6 +107,7 @@
//usage:#define fgrep_trivial_usage NOUSAGE_STR //usage:#define fgrep_trivial_usage NOUSAGE_STR
//usage:#define fgrep_full_usage "" //usage:#define fgrep_full_usage ""
/* -e,-f are lists; -m,-A,-B,-C have numeric param */
#define OPTSTR_GREP \ #define OPTSTR_GREP \
"lnqvscFiHhe:*f:*Lorm:+wx" \ "lnqvscFiHhe:*f:*Lorm:+wx" \
IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \ IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \
@ -686,11 +687,9 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
/* do normal option parsing */ /* do normal option parsing */
#if ENABLE_FEATURE_GREP_CONTEXT #if ENABLE_FEATURE_GREP_CONTEXT
/* -H unsets -h; -C unsets -A,-B; -e,-f are lists; /* -H unsets -h; -C unsets -A,-B */
* -m,-A,-B,-C have numeric param */
opt_complementary = "H-h:C-AB";
opts = getopt32(argv, opts = getopt32(argv,
OPTSTR_GREP, "^" OPTSTR_GREP "\0" "H-h:C-AB",
&pattern_head, &fopt, &max_matches, &pattern_head, &fopt, &max_matches,
&lines_after, &lines_before, &Copt); &lines_after, &lines_before, &Copt);
@ -716,9 +715,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
} }
#else #else
/* with auto sanity checks */ /* with auto sanity checks */
/* -H unsets -h; -c,-q or -l unset -n; -e,-f are lists; -m N */ getopt32(argv, "^" OPTSTR_GREP "\0" "H-h:c-n:q-n:l-n:", // why trailing ":"?
opt_complementary = "H-h:c-n:q-n:l-n:";
getopt32(argv, OPTSTR_GREP,
&pattern_head, &fopt, &max_matches); &pattern_head, &fopt, &max_matches);
#endif #endif
invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */ invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */

View File

@ -1185,9 +1185,6 @@ void make_all_argv_opts(char **argv) FAST_FUNC;
char* single_argv(char **argv) FAST_FUNC; char* single_argv(char **argv) FAST_FUNC;
extern const char *const bb_argv_dash[]; /* { "-", NULL } */ extern const char *const bb_argv_dash[]; /* { "-", NULL } */
extern uint32_t option_mask32; extern uint32_t option_mask32;
//TODO: get rid of this global variable. How about a trick where optstring can be
// "^optchars""\0""complementary" (the leading "^" is an indicator)?
extern const char *opt_complementary;
uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC; uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC;
# define No_argument "\0" # define No_argument "\0"
# define Required_argument "\001" # define Required_argument "\001"

View File

@ -96,9 +96,11 @@ getopt32(char **argv, const char *applet_opts, ...)
env -i ls -d / env -i ls -d /
Here we want env to process just the '-i', not the '-d'. Here we want env to process just the '-i', not the '-d'.
"!" Report bad option, missing required options, "!" Report bad options, missing required options,
inconsistent options with all-ones return value (instead of abort). inconsistent options with all-ones return value (instead of abort).
"^" options string is "^optchars""\0""opt_complementary".
uint32_t uint32_t
getopt32long(char **argv, const char *applet_opts, const char *logopts...) getopt32long(char **argv, const char *applet_opts, const char *logopts...)
@ -121,7 +123,7 @@ getopt32long(char **argv, const char *applet_opts, const char *logopts...)
config process and not a required feature. The current standard config process and not a required feature. The current standard
is to name the config option CONFIG_FEATURE_<applet>_LONG_OPTIONS. is to name the config option CONFIG_FEATURE_<applet>_LONG_OPTIONS.
const char *opt_complementary opt_complementary - option modifiers.
":" The colon (":") is used to separate groups of two or more chars ":" The colon (":") is used to separate groups of two or more chars
and/or groups of chars and special characters (stating some and/or groups of chars and special characters (stating some
@ -132,8 +134,7 @@ const char *opt_complementary
Their flags will be turned on if the main option is found even Their flags will be turned on if the main option is found even
if they are not specified on the command line. For example: if they are not specified on the command line. For example:
opt_complementary = "abc"; flags = getopt32(argv, "^abcd""\0""abc")
flags = getopt32(argv, "abcd")
If getopt() finds "-a" on the command line, then If getopt() finds "-a" on the command line, then
getopt32's return value will be as if "-a -b -c" were getopt32's return value will be as if "-a -b -c" were
@ -146,8 +147,7 @@ const char *opt_complementary
if w is given more than once, it is "unlimited" if w is given more than once, it is "unlimited"
int w_counter = 0; // must be initialized! int w_counter = 0; // must be initialized!
opt_complementary = "ww"; getopt32(argv, "^w""\0""ww", &w_counter);
getopt32(argv, "w", &w_counter);
if (w_counter) if (w_counter)
width = (w_counter == 1) ? 132 : INT_MAX; width = (w_counter == 1) ? 132 : INT_MAX;
else else
@ -162,8 +162,9 @@ const char *opt_complementary
llist_t *my_b = NULL; llist_t *my_b = NULL;
int verbose_level = 0; int verbose_level = 0;
opt_complementary = "vv:b-c:c-b"; f = getopt32(argv, "^vb:*c"
f = getopt32(argv, "vb:*c", &my_b, &verbose_level); "\0""vv:b-c:c-b"
, &my_b, &verbose_level);
if (f & 2) // -c after -b unsets -b flag if (f & 2) // -c after -b unsets -b flag
while (my_b) dosomething_with(llist_pop(&my_b)); while (my_b) dosomething_with(llist_pop(&my_b));
if (my_b) // but llist is stored if -b is specified if (my_b) // but llist is stored if -b is specified
@ -199,7 +200,7 @@ Special characters:
getopt32 finds -s, then -d is unset or if it finds -d getopt32 finds -s, then -d is unset or if it finds -d
then -s is unset. (Note: busybox implements the GNU then -s is unset. (Note: busybox implements the GNU
"--max-depth" option as "-d".) To obtain this behavior, you "--max-depth" option as "-d".) To obtain this behavior, you
set opt_complementary = "s-d:d-s". Only one flag value is set opt_complementary to "s-d:d-s". Only one flag value is
added to getopt32's return value depending on the added to getopt32's return value depending on the
position of the options on the command line. If one of the position of the options on the command line. If one of the
two options requires an argument pointer (":" in applet_opts two options requires an argument pointer (":" in applet_opts
@ -207,8 +208,7 @@ Special characters:
char *smax_print_depth; char *smax_print_depth;
opt_complementary = "s-d:d-s:x-x"; opt = getopt32(argv, "^sd:x""\0""s-d:d-s:x-x", &smax_print_depth);
opt = getopt32(argv, "sd:x", &smax_print_depth);
if (opt & 2) if (opt & 2)
max_print_depth = atoi(smax_print_depth); max_print_depth = atoi(smax_print_depth);
@ -224,7 +224,7 @@ Special characters:
The cut applet must have only one type of list specified, so The cut applet must have only one type of list specified, so
-b, -c and -f are mutually exclusive and should raise an error -b, -c and -f are mutually exclusive and should raise an error
if specified together. In this case you must set if specified together. In this case you must set
opt_complementary = "b--cf:c--bf:f--bc". If two of the opt_complementary to "b--cf:c--bf:f--bc". If two of the
mutually exclusive options are found, getopt32 will call mutually exclusive options are found, getopt32 will call
bb_show_usage() and die. bb_show_usage() and die.
@ -236,8 +236,7 @@ Special characters:
with xatoi_positive() - allowed range is 0..INT_MAX. with xatoi_positive() - allowed range is 0..INT_MAX.
int param; // "unsigned param;" will also work int param; // "unsigned param;" will also work
opt_complementary = "p+"; getopt32(argv, "^p:""\0""p+", &param);
getopt32(argv, "p:", &param);
"o::" A double colon after a char in opt_complementary means that the "o::" A double colon after a char in opt_complementary means that the
option can occur multiple times. Each occurrence will be saved as option can occur multiple times. Each occurrence will be saved as
@ -252,8 +251,7 @@ Special characters:
(this pointer must be initializated to NULL if the list is empty (this pointer must be initializated to NULL if the list is empty
as required by llist_add_to_end(llist_t **old_head, char *new_item).) as required by llist_add_to_end(llist_t **old_head, char *new_item).)
opt_complementary = "e::"; getopt32(argv, "^e:""\0""e::", &patterns);
getopt32(argv, "e:", &patterns);
$ grep -e user -e root /etc/passwd $ grep -e user -e root /etc/passwd
root:x:0:0:root:/root:/bin/bash root:x:0:0:root:/root:/bin/bash
@ -271,8 +269,7 @@ Special characters:
For example from "id" applet: For example from "id" applet:
// Don't allow -n -r -rn -ug -rug -nug -rnug // Don't allow -n -r -rn -ug -rug -nug -rnug
opt_complementary = "r?ug:n?ug:u--g:g--u"; flags = getopt32(argv, "^rnug""\0""r?ug:n?ug:u--g:g--u");
flags = getopt32(argv, "rnug");
This example allowed only: This example allowed only:
$ id; id -u; id -g; id -ru; id -nu; id -rg; id -ng; id -rnu; id -rng $ id; id -u; id -g; id -ru; id -nu; id -rg; id -ng; id -rnu; id -rng
@ -283,8 +280,7 @@ Special characters:
For example from "start-stop-daemon" applet: For example from "start-stop-daemon" applet:
// Don't allow -KS -SK, but -S or -K is required // Don't allow -KS -SK, but -S or -K is required
opt_complementary = "K:S:K--S:S--K"; flags = getopt32(argv, "^KS...""\0""K:S:K--S:S--K");
flags = getopt32(argv, "KS...);
Don't forget to use ':'. For example, "?322-22-23X-x-a" Don't forget to use ':'. For example, "?322-22-23X-x-a"
@ -299,8 +295,6 @@ Special characters:
const char *const bb_argv_dash[] = { "-", NULL }; const char *const bb_argv_dash[] = { "-", NULL };
const char *opt_complementary;
enum { enum {
PARAM_STRING, PARAM_STRING,
PARAM_LIST, PARAM_LIST,
@ -337,10 +331,12 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
int argc; int argc;
unsigned flags = 0; unsigned flags = 0;
unsigned requires = 0; unsigned requires = 0;
unsigned len;
t_complementary complementary[33]; /* last stays zero-filled */ t_complementary complementary[33]; /* last stays zero-filled */
char first_char; char dont_die_flag;
int c; int c;
const unsigned char *s; const unsigned char *s;
const char *opt_complementary;
t_complementary *on_off; t_complementary *on_off;
#if ENABLE_LONG_OPTS #if ENABLE_LONG_OPTS
const struct option *l_o; const struct option *l_o;
@ -349,23 +345,29 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
unsigned trigger; unsigned trigger;
int min_arg = 0; int min_arg = 0;
int max_arg = -1; int max_arg = -1;
#define SHOW_USAGE_IF_ERROR 1
int spec_flgs = 0; int spec_flgs = 0;
/* skip 0: some applets cheat: they do not actually HAVE argv[0] */ #define SHOW_USAGE_IF_ERROR 1
argc = 1 + string_array_len(argv + 1);
on_off = complementary; on_off = complementary;
memset(on_off, 0, sizeof(complementary)); memset(on_off, 0, sizeof(complementary));
applet_opts = strcpy(alloca(strlen(applet_opts) + 1), applet_opts); len = strlen(applet_opts);
/* skip bbox extension */ /* skip bbox extension */
first_char = applet_opts[0]; opt_complementary = NULL;
if (first_char == '!') if (applet_opts[0] == '^') {
applet_opts++; applet_opts++;
/* point it past terminating NUL */
opt_complementary = applet_opts + len;
}
/* skip another bbox extension */
dont_die_flag = applet_opts[0];
if (dont_die_flag == '!')
applet_opts++;
applet_opts = strcpy(alloca(len + 1), applet_opts);
/* skip GNU extension */ /* skip GNU extension */
s = (const unsigned char *)applet_opts; s = (const unsigned char *)applet_opts;
@ -435,7 +437,8 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
} }
#endif /* ENABLE_LONG_OPTS */ #endif /* ENABLE_LONG_OPTS */
for (s = (const unsigned char *)opt_complementary; s && *s; s++) { s = (const unsigned char *)opt_complementary;
if (s) for (; *s; s++) {
t_complementary *pair; t_complementary *pair;
unsigned *pair_switch; unsigned *pair_switch;
@ -513,8 +516,6 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
s--; s--;
} }
/* Make it unnecessary to clear it by hand after each getopt32 call */
opt_complementary = NULL;
/* In case getopt32 was already called: /* In case getopt32 was already called:
* reset the libc getopt() function, which keeps internal state. * reset the libc getopt() function, which keeps internal state.
* run_nofork_applet() does this, but we might end up here * run_nofork_applet() does this, but we might end up here
@ -522,6 +523,9 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
*/ */
GETOPT_RESET(); GETOPT_RESET();
/* skip 0: some applets cheat: they do not actually HAVE argv[0] */
argc = 1 + string_array_len(argv + 1);
/* Note: just "getopt() <= 0" will not work well for /* Note: just "getopt() <= 0" will not work well for
* "fake" short options, like this one: * "fake" short options, like this one:
* wget $'-\203' "Test: test" http://kernel.org/ * wget $'-\203' "Test: test" http://kernel.org/
@ -583,7 +587,7 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
return flags; return flags;
error: error:
if (first_char != '!') if (dont_die_flag != '!')
bb_show_usage(); bb_show_usage();
return (int32_t)-1; return (int32_t)-1;
} }

View File

@ -42,8 +42,9 @@ int parse_main(int argc UNUSED_PARAM, char **argv)
int mintokens = 0, ntokens = 128; int mintokens = 0, ntokens = 128;
unsigned noout; unsigned noout;
opt_complementary = "-1"; noout = 1 & getopt32(argv, "^" "xn:+m:+d:f:+" "\0" "-1",
noout = 1 & getopt32(argv, "xn:+m:+d:f:+", &ntokens, &mintokens, &delims, &flags); &ntokens, &mintokens, &delims, &flags
);
//argc -= optind; //argc -= optind;
argv += optind; argv += optind;

View File

@ -98,7 +98,6 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
* (getopt32() does it itself, but getopt() doesn't (and can't)) * (getopt32() does it itself, but getopt() doesn't (and can't))
*/ */
GETOPT_RESET(); GETOPT_RESET();
/* opt_complementary = NULL; - cleared by each getopt32() call anyway */
argc = string_array_len(argv); argc = string_array_len(argv);
@ -123,7 +122,6 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
restore_nofork_data(&old); restore_nofork_data(&old);
/* Other globals can be simply reset to defaults */ /* Other globals can be simply reset to defaults */
GETOPT_RESET(); GETOPT_RESET();
/* opt_complementary = NULL; - cleared by each getopt32() call anyway */
return rc & 0xff; /* don't confuse people with "exitcodes" >255 */ return rc & 0xff; /* don't confuse people with "exitcodes" >255 */
} }
@ -138,7 +136,6 @@ void FAST_FUNC run_noexec_applet_and_exit(int a, const char *name, char **argv)
xfunc_error_retval = EXIT_FAILURE; xfunc_error_retval = EXIT_FAILURE;
die_func = NULL; die_func = NULL;
GETOPT_RESET(); GETOPT_RESET();
/* opt_complementary = NULL; - cleared by each getopt32() call anyway */
//TODO: think pidof, pgrep, pkill! //TODO: think pidof, pgrep, pkill!
//set_task_comm() makes our pidof find NOEXECs (e.g. "yes >/dev/null"), //set_task_comm() makes our pidof find NOEXECs (e.g. "yes >/dev/null"),

View File

@ -152,11 +152,12 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv)
} }
/* Syntax: /* Syntax:
* addgroup group * addgroup group
* addgroup -g num group * addgroup --gid num group
* addgroup user group * addgroup user group
* Check for min, max and missing args */ * Check for min, max and missing args */
opt_complementary = "-1:?2"; opts = getopt32long(argv, "^" "g:S" "\0" "-1:?2", addgroup_longopts,
opts = getopt32long(argv, "g:S", addgroup_longopts, &gid); &gid
);
/* move past the commandline options */ /* move past the commandline options */
argv += optind; argv += optind;
//argc -= optind; //argc -= optind;

View File

@ -201,12 +201,15 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
pw.pw_shell = (char *)get_shell_name(); pw.pw_shell = (char *)get_shell_name();
pw.pw_dir = NULL; pw.pw_dir = NULL;
/* at least one and at most two non-option args */ opts = getopt32long(argv, "^"
/* disable interactive passwd for system accounts */ "h:g:s:G:DSHu:k:"
opt_complementary = "-1:?2:SD"; /* at least one and at most two non-option args */
opts = getopt32long(argv, "h:g:s:G:DSHu:k:", adduser_longopts, /* disable interactive passwd for system accounts */
"\0" "-1:?2:SD",
adduser_longopts,
&pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell,
&usegroup, &uid, &skel); &usegroup, &uid, &skel
);
if (opts & OPT_UID) if (opts & OPT_UID)
pw.pw_uid = xatou_range(uid, 0, CONFIG_LAST_ID); pw.pw_uid = xatou_range(uid, 0, CONFIG_LAST_ID);

View File

@ -61,8 +61,10 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv)
if (getuid() != 0) if (getuid() != 0)
bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
opt_complementary = "m--ec:e--mc:c--em"; opt = getopt32long(argv, "^" "emc:" "\0" "m--ec:e--mc:c--em",
opt = getopt32long(argv, "emc:", chpasswd_longopts, &algo); chpasswd_longopts,
&algo
);
while ((name = xmalloc_fgetline(stdin)) != NULL) { while ((name = xmalloc_fgetline(stdin)) != NULL) {
char *free_me; char *free_me;

View File

@ -111,9 +111,10 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv)
opt_m = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO; opt_m = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO;
opt_S = NULL; opt_S = NULL;
/* at most two non-option arguments; -P NUM */ /* at most two non-option arguments; -P NUM */
opt_complementary = "?2"; getopt32long(argv, "^" "sP:+S:m:a:" "\0" "?2",
getopt32long(argv, "sP:+S:m:a:", mkpasswd_longopts, mkpasswd_longopts,
&fd, &opt_S, &opt_m, &opt_m); &fd, &opt_S, &opt_m, &opt_m
);
argv += optind; argv += optind;
/* have no idea how to handle -s... */ /* have no idea how to handle -s... */

View File

@ -131,7 +131,7 @@ struct globals {
//usage: "\n" //usage: "\n"
//usage: "\nBAUD_RATE of 0 leaves it unchanged" //usage: "\nBAUD_RATE of 0 leaves it unchanged"
static const char opt_string[] ALIGN1 = "I:LH:f:hil:mt:+wn"; #define OPT_STR "I:LH:f:hil:mt:+wn"
#define F_INITSTRING (1 << 0) /* -I */ #define F_INITSTRING (1 << 0) /* -I */
#define F_LOCAL (1 << 1) /* -L */ #define F_LOCAL (1 << 1) /* -L */
#define F_FAKEHOST (1 << 2) /* -H */ #define F_FAKEHOST (1 << 2) /* -H */
@ -179,8 +179,7 @@ static void parse_args(char **argv)
char *ts; char *ts;
int flags; int flags;
opt_complementary = "-2"; /* at least 2 args; -t N */ flags = getopt32(argv, "^" OPT_STR "\0" "-2"/* at least 2 args*/,
flags = getopt32(argv, opt_string,
&G.initstring, &G.fakehost, &G.issue, &G.initstring, &G.fakehost, &G.issue,
&G.login, &G.timeout &G.login, &G.timeout
); );

View File

@ -66,8 +66,7 @@ int vlock_main(int argc UNUSED_PARAM, char **argv)
struct passwd *pw; struct passwd *pw;
pw = xgetpwuid(getuid()); pw = xgetpwuid(getuid());
opt_complementary = "=0"; /* no params! */ getopt32(argv, "^" "a" "\0" "=0"/* no args!*/);
getopt32(argv, "a");
/* Ignore some signals so that we don't get killed by them */ /* Ignore some signals so that we don't get killed by them */
bb_signals(0 bb_signals(0

View File

@ -125,9 +125,9 @@ int popmaildir_main(int argc UNUSED_PARAM, char **argv)
INIT_G(); INIT_G();
// parse options // parse options
opt_complementary = "-1:dd"; opts = getopt32(argv, "^"
opts = getopt32(argv, "bdmVcasTkt:+" "R:+Z:L:+H:+" IF_FEATURE_POPMAILDIR_DELIVERY("M:F:")
"bdmVcasTkt:+" "R:+Z:L:+H:+" IF_FEATURE_POPMAILDIR_DELIVERY("M:F:"), "\0" "-1:dd",
&timeout, NULL, NULL, NULL, &opt_nlines &timeout, NULL, NULL, NULL, &opt_nlines
IF_FEATURE_POPMAILDIR_DELIVERY(, &delivery, &delivery) // we treat -M and -F the same IF_FEATURE_POPMAILDIR_DELIVERY(, &delivery, &delivery) // we treat -M and -F the same
); );

View File

@ -280,9 +280,9 @@ int reformime_main(int argc UNUSED_PARAM, char **argv)
// parse options // parse options
// N.B. only -x and -X are supported so far // N.B. only -x and -X are supported so far
opt_complementary = "x--X:X--x"; opts = getopt32(argv, "^"
opts = getopt32(argv, "x:X" IF_FEATURE_REFORMIME_COMPAT("deis:r:c:m:*h:o:O:")
"x:X" IF_FEATURE_REFORMIME_COMPAT("deis:r:c:m:*h:o:O:"), "\0" "x--X:X--x",
&opt_prefix &opt_prefix
IF_FEATURE_REFORMIME_COMPAT(, NULL, NULL, &G.opt_charset, NULL, NULL, NULL, NULL) IF_FEATURE_REFORMIME_COMPAT(, NULL, NULL, &G.opt_charset, NULL, NULL, NULL, NULL)
); );

View File

@ -256,13 +256,17 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
G.fp0 = xfdopen_for_read(3); G.fp0 = xfdopen_for_read(3);
// parse options // parse options
// -v is a counter, -H and -S are mutually exclusive, -a is a list
opt_complementary = "vv:H--S:S--H";
// N.B. since -H and -S are mutually exclusive they do not interfere in opt_connect // N.B. since -H and -S are mutually exclusive they do not interfere in opt_connect
// -a is for ssmtp (http://downloads.openwrt.org/people/nico/man/man8/ssmtp.8.html) compatibility, // -a is for ssmtp (http://downloads.openwrt.org/people/nico/man/man8/ssmtp.8.html) compatibility,
// it is still under development. // it is still under development.
opts = getopt32(argv, "tf:o:iw:+H:S:a:*:v", &opt_from, NULL, opts = getopt32(argv, "^"
&timeout, &opt_connect, &opt_connect, &list, &verbose); "tf:o:iw:+H:S:a:*:v"
"\0"
// -v is a counter, -H and -S are mutually exclusive, -a is a list
"vv:H--S:S--H",
&opt_from, NULL,
&timeout, &opt_connect, &opt_connect, &list, &verbose
);
//argc -= optind; //argc -= optind;
argv += optind; argv += optind;

View File

@ -95,9 +95,10 @@ int adjtimex_main(int argc UNUSED_PARAM, char **argv)
memset(&txc, 0, sizeof(txc)); memset(&txc, 0, sizeof(txc));
opt_complementary = "=0"; /* no valid non-option parameters */ opt = getopt32(argv, "^" "qo:f:p:t:"
opt = getopt32(argv, "qo:f:p:t:", "\0" "=0"/*no valid non-option args*/,
&opt_o, &opt_f, &opt_p, &opt_t); &opt_o, &opt_f, &opt_p, &opt_t
);
//if (opt & 0x1) // -q //if (opt & 0x1) // -q
if (opt & 0x2) { // -o if (opt & 0x2) { // -o
txc.offset = xatol(opt_o); txc.offset = xatol(opt_o);

View File

@ -1021,13 +1021,17 @@ int crond_main(int argc UNUSED_PARAM, char **argv)
INIT_G(); INIT_G();
/* "-b after -f is ignored", and so on for every pair a-b */ opts = getopt32(argv, "^"
opt_complementary = "f-b:b-f:S-L:L-S" IF_FEATURE_CROND_D(":d-l") "l:L:fbSc:" IF_FEATURE_CROND_D("d:")
"\0"
/* "-b after -f is ignored", and so on for every pair a-b */
"f-b:b-f:S-L:L-S" IF_FEATURE_CROND_D(":d-l")
/* -l and -d have numeric param */ /* -l and -d have numeric param */
":l+" IF_FEATURE_CROND_D(":d+"); ":l+" IF_FEATURE_CROND_D(":d+")
opts = getopt32(argv, "l:L:fbSc:" IF_FEATURE_CROND_D("d:"), ,
&G.log_level, &G.log_filename, &G.crontab_dir_name &G.log_level, &G.log_filename, &G.crontab_dir_name
IF_FEATURE_CROND_D(,&G.log_level)); IF_FEATURE_CROND_D(,&G.log_level)
);
/* both -d N and -l N set the same variable: G.log_level */ /* both -d N and -l N set the same variable: G.log_level */
if (!(opts & OPT_f)) { if (!(opts & OPT_f)) {

View File

@ -99,8 +99,9 @@ int crontab_main(int argc UNUSED_PARAM, char **argv)
OPT_ler = OPT_l + OPT_e + OPT_r, OPT_ler = OPT_l + OPT_e + OPT_r,
}; };
opt_complementary = "?1:dr"; /* max one argument; -d implies -r */ opt_ler = getopt32(argv, "^" "u:c:lerd" "\0" "?1:dr"/*max one arg; -d implies -r*/,
opt_ler = getopt32(argv, "u:c:lerd", &user_name, &crontab_dir); &user_name, &crontab_dir
);
argv += optind; argv += optind;
if (sanitize_env_if_suid()) { /* Clears dangerous stuff, sets PATH */ if (sanitize_env_if_suid()) { /* Clears dangerous stuff, sets PATH */

View File

@ -82,8 +82,7 @@ int flash_eraseall_main(int argc UNUSED_PARAM, char **argv)
unsigned int flags; unsigned int flags;
char *mtd_name; char *mtd_name;
opt_complementary = "=1"; flags = getopt32(argv, "^" "jNq" "\0" "=1");
flags = getopt32(argv, "jNq");
mtd_name = argv[optind]; mtd_name = argv[optind];
fd = xopen(mtd_name, O_RDWR); fd = xopen(mtd_name, O_RDWR);

View File

@ -69,8 +69,7 @@ int flashcp_main(int argc UNUSED_PARAM, char **argv)
RESERVE_CONFIG_UBUFFER(buf, BUFSIZE); RESERVE_CONFIG_UBUFFER(buf, BUFSIZE);
RESERVE_CONFIG_UBUFFER(buf2, BUFSIZE); RESERVE_CONFIG_UBUFFER(buf2, BUFSIZE);
opt_complementary = "=2"; /* exactly 2 non-option args: file, dev */ /*opts =*/ getopt32(argv, "^" "v" "\0" "=2"/*exactly 2 non-option args: file,dev*/);
/*opts =*/ getopt32(argv, "v");
argv += optind; argv += optind;
// filename = *argv++; // filename = *argv++;
// devicename = *argv; // devicename = *argv;

View File

@ -455,14 +455,12 @@ int i2cget_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int i2cget_main(int argc UNUSED_PARAM, char **argv) int i2cget_main(int argc UNUSED_PARAM, char **argv)
{ {
const unsigned opt_f = (1 << 0), opt_y = (1 << 1); const unsigned opt_f = (1 << 0), opt_y = (1 << 1);
const char *const optstr = "fy";
int bus_num, bus_addr, data_addr = -1, status; int bus_num, bus_addr, data_addr = -1, status;
int mode = I2C_SMBUS_BYTE, pec = 0, fd; int mode = I2C_SMBUS_BYTE, pec = 0, fd;
unsigned opts; unsigned opts;
opt_complementary = "-2:?4"; /* from 2 to 4 args */ opts = getopt32(argv, "^" "fy" "\0" "-2:?4"/*from 2 to 4 args*/);
opts = getopt32(argv, optstr);
argv += optind; argv += optind;
bus_num = i2c_bus_lookup(argv[0]); bus_num = i2c_bus_lookup(argv[0]);
@ -544,7 +542,6 @@ int i2cset_main(int argc, char **argv)
{ {
const unsigned opt_f = (1 << 0), opt_y = (1 << 1), const unsigned opt_f = (1 << 0), opt_y = (1 << 1),
opt_m = (1 << 2), opt_r = (1 << 3); opt_m = (1 << 2), opt_r = (1 << 3);
const char *const optstr = "fym:r";
int bus_num, bus_addr, data_addr, mode = I2C_SMBUS_BYTE, pec = 0; int bus_num, bus_addr, data_addr, mode = I2C_SMBUS_BYTE, pec = 0;
int val, blen = 0, mask = 0, fd, status; int val, blen = 0, mask = 0, fd, status;
@ -552,8 +549,7 @@ int i2cset_main(int argc, char **argv)
char *opt_m_arg = NULL; char *opt_m_arg = NULL;
unsigned opts; unsigned opts;
opt_complementary = "-3"; /* from 3 to ? args */ opts = getopt32(argv, "^" "fym:r" "\0" "-3"/*from 3 to ? args*/, &opt_m_arg);
opts = getopt32(argv, optstr, &opt_m_arg);
argv += optind; argv += optind;
argc -= optind; argc -= optind;
@ -905,7 +901,6 @@ int i2cdump_main(int argc UNUSED_PARAM, char **argv)
{ {
const unsigned opt_f = (1 << 0), opt_y = (1 << 1), const unsigned opt_f = (1 << 0), opt_y = (1 << 1),
opt_r = (1 << 2); opt_r = (1 << 2);
const char *const optstr = "fyr:";
int bus_num, bus_addr, mode = I2C_SMBUS_BYTE_DATA, even = 0, pec = 0; int bus_num, bus_addr, mode = I2C_SMBUS_BYTE_DATA, even = 0, pec = 0;
unsigned first = 0x00, last = 0xff, opts; unsigned first = 0x00, last = 0xff, opts;
@ -913,8 +908,11 @@ int i2cdump_main(int argc UNUSED_PARAM, char **argv)
char *opt_r_str, *dash; char *opt_r_str, *dash;
int fd, res; int fd, res;
opt_complementary = "-2:?3"; /* from 2 to 3 args */ opts = getopt32(argv, "^"
opts = getopt32(argv, optstr, &opt_r_str); "fyr:"
"\0" "-2:?3" /* from 2 to 3 args */,
&opt_r_str
);
argv += optind; argv += optind;
bus_num = i2c_bus_lookup(argv[0]); bus_num = i2c_bus_lookup(argv[0]);
@ -1208,15 +1206,16 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv)
const unsigned opt_y = (1 << 0), opt_a = (1 << 1), const unsigned opt_y = (1 << 0), opt_a = (1 << 1),
opt_q = (1 << 2), opt_r = (1 << 3), opt_q = (1 << 2), opt_r = (1 << 3),
opt_F = (1 << 4), opt_l = (1 << 5); opt_F = (1 << 4), opt_l = (1 << 5);
const char *const optstr = "yaqrFl";
int fd, bus_num, i, j, mode = I2CDETECT_MODE_AUTO, status, cmd; int fd, bus_num, i, j, mode = I2CDETECT_MODE_AUTO, status, cmd;
unsigned first = 0x03, last = 0x77, opts; unsigned first = 0x03, last = 0x77, opts;
unsigned long funcs; unsigned long funcs;
opt_complementary = "q--r:r--q:" /* mutually exclusive */ opts = getopt32(argv, "^"
"?3"; /* up to 3 args */ "yaqrFl"
opts = getopt32(argv, optstr); "\0"
"q--r:r--q:"/*mutually exclusive*/ "?3"/*up to 3 args*/
);
argv += optind; argv += optind;
if (opts & opt_l) if (opts & opt_l)

View File

@ -183,8 +183,7 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv)
char *line = (char *)"-"; char *line = (char *)"-";
int ret = EXIT_SUCCESS; int ret = EXIT_SUCCESS;
opt_complementary = "=1"; /* exactly one param */ getopt32(argv, "^" "d:" "\0" "=1", &line);
getopt32(argv, "d:", &line);
argv += optind; argv += optind;
xchdir(*argv); /* ensure root dir exists */ xchdir(*argv); /* ensure root dir exists */

View File

@ -253,8 +253,7 @@ int man_main(int argc UNUSED_PARAM, char **argv)
INIT_G(); INIT_G();
opt_complementary = "-1"; /* at least one argument */ opt = getopt32(argv, "^+" "aw" "\0" "-1"/*at least one arg*/);
opt = getopt32(argv, "+aw");
argv += optind; argv += optind;
sec_list = xstrdup("0p:1:1p:2:3:3p:4:5:6:7:8:9"); sec_list = xstrdup("0p:1:1p:2:3:3p:4:5:6:7:8:9");

View File

@ -74,8 +74,9 @@ int microcom_main(int argc UNUSED_PARAM, char **argv)
unsigned opts; unsigned opts;
// fetch options // fetch options
opt_complementary = "=1"; opts = getopt32(argv, "^" "Xs:+d:+t:+" "\0" "=1",
opts = getopt32(argv, "Xs:+d:+t:+", &speed, &delay, &timeout); &speed, &delay, &timeout
);
// argc -= optind; // argc -= optind;
argv += optind; argv += optind;

View File

@ -123,13 +123,12 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
const char *opt_s = "0", *opt_f = "-", *opt_l, *opt_bb; const char *opt_s = "0", *opt_f = "-", *opt_l, *opt_bb;
if (IS_NANDDUMP) { if (IS_NANDDUMP) {
opt_complementary = "=1"; opts = getopt32long(argv, "^" "ons:f:l:" "\0" "=1",
opts = getopt32long(argv, "ons:f:l:",
"bb\0" Required_argument "\xff", /* no short equivalent */ "bb\0" Required_argument "\xff", /* no short equivalent */
&opt_s, &opt_f, &opt_l, &opt_bb); &opt_s, &opt_f, &opt_l, &opt_bb
);
} else { /* nandwrite */ } else { /* nandwrite */
opt_complementary = "-1:?2"; opts = getopt32(argv, "^" "pns:" "\0" "-1:?2", &opt_s);
opts = getopt32(argv, "pns:", &opt_s);
} }
argv += optind; argv += optind;

View File

@ -742,8 +742,7 @@ int setserial_main(int argc UNUSED_PARAM, char **argv)
{ {
int opts; int opts;
opt_complementary = "-1:b-aG:G-ab:a-bG"; opts = getopt32(argv, "^" "bGavzgq" "\0" "-1:b-aG:G-ab:a-bG");
opts = getopt32(argv, "bGavzgq");
argv += optind; argv += optind;
if (!argv[1]) /* one arg only? (nothing to change?) */ if (!argv[1]) /* one arg only? (nothing to change?) */

View File

@ -430,9 +430,10 @@ int time_main(int argc UNUSED_PARAM, char **argv)
OPT_f = (1 << 4), OPT_f = (1 << 4),
}; };
opt_complementary = "-1"; /* at least one arg */
/* "+": stop on first non-option */ /* "+": stop on first non-option */
opt = getopt32(argv, "+vpao:f:", &output_filename, &output_format); opt = getopt32(argv, "^+" "vpao:f:" "\0" "-1"/*at least one arg*/,
&output_filename, &output_format
);
argv += optind; argv += optind;
if (opt & OPT_v) if (opt & OPT_v)
output_format = long_format; output_format = long_format;

View File

@ -145,20 +145,17 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
#define OPTION_a (1 << 5) #define OPTION_a (1 << 5)
#define OPTION_t (1 << 6) #define OPTION_t (1 << 6)
if (do_mkvol) { if (do_mkvol) {
opt_complementary = "-1"; opts = getopt32(argv, "^" "md:+n:+N:s:a:+t:O:+" "\0" "-1",
opts = getopt32(argv, "md:+n:+N:s:a:+t:O:+",
&dev_num, &vol_id, &dev_num, &vol_id,
&vol_name, &size_bytes_str, &alignment, &type, &vol_name, &size_bytes_str, &alignment, &type,
&vid_hdr_offset &vid_hdr_offset
); );
} else } else
if (do_update) { if (do_update) {
opt_complementary = "-1"; opts = getopt32(argv, "^" "s:at" "\0" "-1", &size_bytes_str);
opts = getopt32(argv, "s:at", &size_bytes_str);
opts *= OPTION_s; opts *= OPTION_s;
} else { } else {
opt_complementary = "-1"; opts = getopt32(argv, "^" "m:+d:+n:+N:s:a:+t:" "\0" "-1",
opts = getopt32(argv, "m:+d:+n:+N:s:a:+t:",
&mtd_num, &dev_num, &vol_id, &mtd_num, &dev_num, &vol_id,
&vol_name, &size_bytes_str, &alignment, &type &vol_name, &size_bytes_str, &alignment, &type
); );

View File

@ -101,8 +101,9 @@ int watchdog_main(int argc UNUSED_PARAM, char **argv)
char *st_arg; char *st_arg;
char *ht_arg; char *ht_arg;
opt_complementary = "=1"; /* must have exactly 1 argument */ opts = getopt32(argv, "^" "Ft:T:" "\0" "=1"/*must have exactly 1 arg*/,
opts = getopt32(argv, "Ft:T:", &st_arg, &ht_arg); &st_arg, &ht_arg
);
/* We need to daemonize *before* opening the watchdog as many drivers /* We need to daemonize *before* opening the watchdog as many drivers
* will only allow one process at a time to do so. Since daemonizing * will only allow one process at a time to do so. Since daemonizing

View File

@ -148,8 +148,7 @@ int modinfo_main(int argc UNUSED_PARAM, char **argv)
unsigned i; unsigned i;
field = NULL; field = NULL;
opt_complementary = "-1"; /* minimum one param */ opts = getopt32(argv, "^" "0F:nadlp" "\0" "-1"/*minimum one arg*/, &field);
opts = getopt32(argv, "0F:nadlp", &field);
/* If no field selected, show all */ /* If no field selected, show all */
if (!(opts & (OPT_TAGS|OPT_F))) if (!(opts & (OPT_TAGS|OPT_F)))
option_mask32 |= OPT_TAGS; option_mask32 |= OPT_TAGS;

View File

@ -988,10 +988,9 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_MODPROBE || ENABLE_INSMOD || ENABLE_RMMOD #if ENABLE_MODPROBE || ENABLE_INSMOD || ENABLE_RMMOD
/* modprobe, insmod, rmmod require at least one argument */ /* modprobe, insmod, rmmod require at least one argument */
opt_complementary = "-1";
/* only -q (quiet) and -r (rmmod), /* only -q (quiet) and -r (rmmod),
* the rest are accepted and ignored (compat) */ * the rest are accepted and ignored (compat) */
getopt32(argv, "qrfsvwb"); getopt32(argv, "^" "qrfsvwb" "\0" "-1");
argv += optind; argv += optind;
if (is_modprobe) { if (is_modprobe) {

View File

@ -133,7 +133,7 @@
*/ */
#define MODPROBE_OPTS "alrDb" #define MODPROBE_OPTS "alrDb"
/* -a and -D _are_ in fact compatible */ /* -a and -D _are_ in fact compatible */
#define MODPROBE_COMPLEMENTARY ("q-v:v-q:l--arD:r--alD:a--lr:D--rl") #define MODPROBE_COMPLEMENTARY "q-v:v-q:l--arD:r--alD:a--lr:D--rl"
//#define MODPROBE_OPTS "acd:lnrt:C:b" //#define MODPROBE_OPTS "acd:lnrt:C:b"
//#define MODPROBE_COMPLEMENTARY "q-v:v-q:l--acr:a--lr:r--al" //#define MODPROBE_COMPLEMENTARY "q-v:v-q:l--acr:a--lr:r--al"
enum { enum {
@ -566,8 +566,10 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
INIT_G(); INIT_G();
opt_complementary = MODPROBE_COMPLEMENTARY; opt = getopt32long(argv, "^" INSMOD_OPTS MODPROBE_OPTS "\0" MODPROBE_COMPLEMENTARY,
opt = getopt32long(argv, INSMOD_OPTS MODPROBE_OPTS, modprobe_longopts INSMOD_ARGS); modprobe_longopts
INSMOD_ARGS
);
argv += optind; argv += optind;
/* Goto modules location */ /* Goto modules location */

View File

@ -306,9 +306,9 @@ int arping_main(int argc UNUSED_PARAM, char **argv)
/* Dad also sets quit_on_reply. /* Dad also sets quit_on_reply.
* Advert also sets unsolicited. * Advert also sets unsolicited.
*/ */
opt_complementary = "=1:Df:AU"; opt = getopt32(argv, "^" "DUAqfbc:+w:I:s:" "\0" "=1:Df:AU",
opt = getopt32(argv, "DUAqfbc:+w:I:s:", &count, &str_timeout, &device, &source
&count, &str_timeout, &device, &source); );
if (opt & 0x80) /* -w: timeout */ if (opt & 0x80) /* -w: timeout */
timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000 + 500000; timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000 + 500000;
//if (opt & 0x200) /* -s: source */ //if (opt & 0x200) /* -s: source */

View File

@ -212,8 +212,7 @@ int ether_wake_main(int argc UNUSED_PARAM, char **argv)
struct whereto_t whereto; /* who to wake up */ struct whereto_t whereto; /* who to wake up */
/* handle misc user options */ /* handle misc user options */
opt_complementary = "=1"; flags = getopt32(argv, "^" "bi:p:" "\0" "=1", &ifname, &pass);
flags = getopt32(argv, "bi:p:", &ifname, &pass);
if (flags & 4) /* -p */ if (flags & 4) /* -p */
wol_passwd_sz = get_wol_pw(pass, wol_passwd); wol_passwd_sz = get_wol_pw(pass, wol_passwd);
flags &= 1; /* we further interested only in -b [bcast] flag */ flags &= 1; /* we further interested only in -b [bcast] flag */

View File

@ -1174,17 +1174,20 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
abs_timeout = 1 * 60 * 60; abs_timeout = 1 * 60 * 60;
verbose_S = 0; verbose_S = 0;
G.timeout = 2 * 60; G.timeout = 2 * 60;
opt_complementary = "vv:SS";
#if BB_MMU #if BB_MMU
opts = getopt32(argv, "vS" opts = getopt32(argv, "^" "vS"
IF_FEATURE_FTPD_WRITE("w") "t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:"), IF_FEATURE_FTPD_WRITE("w") "t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:")
"\0" "vv:SS",
&G.timeout, &abs_timeout, IF_FEATURE_FTPD_AUTHENTICATION(&anon_opt,) &G.timeout, &abs_timeout, IF_FEATURE_FTPD_AUTHENTICATION(&anon_opt,)
&G.verbose, &verbose_S); &G.verbose, &verbose_S
);
#else #else
opts = getopt32(argv, "l1AvS" opts = getopt32(argv, "^" "l1AvS"
IF_FEATURE_FTPD_WRITE("w") "t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:"), IF_FEATURE_FTPD_WRITE("w") "t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:")
"\0" "vv:SS",
&G.timeout, &abs_timeout, IF_FEATURE_FTPD_AUTHENTICATION(&anon_opt,) &G.timeout, &abs_timeout, IF_FEATURE_FTPD_AUTHENTICATION(&anon_opt,)
&G.verbose, &verbose_S); &G.verbose, &verbose_S
);
if (opts & (OPT_l|OPT_1)) { if (opts & (OPT_l|OPT_1)) {
/* Our secret backdoor to ls */ /* Our secret backdoor to ls */
if (fchdir(3) != 0) if (fchdir(3) != 0)

View File

@ -361,11 +361,12 @@ int ftpgetput_main(int argc UNUSED_PARAM, char **argv)
/* /*
* Decipher the command line * Decipher the command line
*/ */
opt_complementary = "-2:vv:cc"; /* must have 2 to 3 params; -v and -c count */ /* must have 2 to 3 params; -v and -c count */
#define OPTSTRING "^cvu:p:P:" "\0" "-2:?3:vv:cc"
#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS #if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
getopt32long(argv, "cvu:p:P:", ftpgetput_longopts, getopt32long(argv, OPTSTRING, ftpgetput_longopts,
#else #else
getopt32(argv, "cvu:p:P:", getopt32(argv, OPTSTRING,
#endif #endif
&user, &password, &port, &verbose_flag, &do_continue &user, &password, &port, &verbose_flag, &do_continue
); );

View File

@ -2636,17 +2636,19 @@ int httpd_main(int argc UNUSED_PARAM, char **argv)
#endif #endif
home_httpd = xrealloc_getcwd_or_warn(NULL); home_httpd = xrealloc_getcwd_or_warn(NULL);
/* -v counts, -i implies -f */
opt_complementary = "vv:if";
/* We do not "absolutize" path given by -h (home) opt. /* We do not "absolutize" path given by -h (home) opt.
* If user gives relative path in -h, * If user gives relative path in -h,
* $SCRIPT_FILENAME will not be set. */ * $SCRIPT_FILENAME will not be set. */
opt = getopt32(argv, "c:d:h:" opt = getopt32(argv, "^"
"c:d:h:"
IF_FEATURE_HTTPD_ENCODE_URL_STR("e:") IF_FEATURE_HTTPD_ENCODE_URL_STR("e:")
IF_FEATURE_HTTPD_BASIC_AUTH("r:") IF_FEATURE_HTTPD_BASIC_AUTH("r:")
IF_FEATURE_HTTPD_AUTH_MD5("m:") IF_FEATURE_HTTPD_AUTH_MD5("m:")
IF_FEATURE_HTTPD_SETUID("u:") IF_FEATURE_HTTPD_SETUID("u:")
"p:ifv", "p:ifv"
"\0"
/* -v counts, -i implies -f */
"vv:if",
&opt_c_configFile, &url_for_decode, &home_httpd &opt_c_configFile, &url_for_decode, &home_httpd
IF_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode) IF_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode)
IF_FEATURE_HTTPD_BASIC_AUTH(, &g_realm) IF_FEATURE_HTTPD_BASIC_AUTH(, &g_realm)

View File

@ -130,8 +130,11 @@ int ipcalc_main(int argc UNUSED_PARAM, char **argv)
#define ipaddr (s_ipaddr.s_addr) #define ipaddr (s_ipaddr.s_addr)
char *ipstr; char *ipstr;
opt_complementary = "-1:?2"; /* minimum 1 arg, maximum 2 args */ opt = GETOPT32(argv, "^"
opt = GETOPT32(argv, "mbn" IF_FEATURE_IPCALC_FANCY("phs") LONGOPTS); "mbn" IF_FEATURE_IPCALC_FANCY("phs")
"\0" "-1:?2"/*min 1, max 2 args*/
LONGOPTS
);
argv += optind; argv += optind;
if (opt & SILENT) if (opt & SILENT)
logmode = LOGMODE_NONE; /* suppress error_msg() output */ logmode = LOGMODE_NONE; /* suppress error_msg() output */

View File

@ -787,11 +787,15 @@ int nc_main(int argc UNUSED_PARAM, char **argv)
e_found: e_found:
// -g -G -t -r deleted, unimplemented -a deleted too // -g -G -t -r deleted, unimplemented -a deleted too
opt_complementary = "?2:vv:ll"; /* max 2 params; -v and -l are counters; -w N */ getopt32(argv, "^"
getopt32(argv, "np:s:uvw:+" IF_NC_SERVER("lk") "np:s:uvw:+"/* -w N */ IF_NC_SERVER("lk")
IF_NC_EXTRA("i:o:z"), IF_NC_EXTRA("i:o:z")
&str_p, &str_s, &o_wait "\0"
IF_NC_EXTRA(, &str_i, &str_o), &o_verbose IF_NC_SERVER(, &cnt_l)); "?2:vv:ll", /* max 2 params; -v and -l are counters */
&str_p, &str_s, &o_wait
IF_NC_EXTRA(, &str_i, &str_o)
, &o_verbose IF_NC_SERVER(, &cnt_l)
);
argv += optind; argv += optind;
#if ENABLE_NC_EXTRA #if ENABLE_NC_EXTRA
if (option_mask32 & OPT_i) /* line-interval time */ if (option_mask32 & OPT_i) /* line-interval time */

View File

@ -2230,15 +2230,16 @@ static NOINLINE void ntp_init(char **argv)
/* Parse options */ /* Parse options */
peers = NULL; peers = NULL;
opt_complementary = "dd:wn" /* -d: counter; -p: list; -w implies -n */ opts = getopt32(argv, "^"
IF_FEATURE_NTPD_SERVER(":Il"); /* -I implies -l */
opts = getopt32(argv,
"nqNx" /* compat */ "nqNx" /* compat */
"wp:*S:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */ "wp:*S:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */
IF_FEATURE_NTPD_SERVER("I:") /* compat */ IF_FEATURE_NTPD_SERVER("I:") /* compat */
"d" /* compat */ "d" /* compat */
"46aAbgL", /* compat, ignored */ "46aAbgL", /* compat, ignored */
&peers, &G.script_name, "\0"
"dd:wn" /* -d: counter; -p: list; -w implies -n */
IF_FEATURE_NTPD_SERVER(":Il") /* -I implies -l */
, &peers, &G.script_name,
#if ENABLE_FEATURE_NTPD_SERVER #if ENABLE_FEATURE_NTPD_SERVER
&G.if_name, &G.if_name,
#endif #endif

View File

@ -340,7 +340,8 @@ static int common_ping_main(sa_family_t af, char **argv)
/* Full(er) version */ /* Full(er) version */
#define OPT_STRING ("qvc:+s:t:+w:+W:+I:np:4" IF_PING6("6")) /* -c NUM, -t NUM, -w NUM, -W NUM */
#define OPT_STRING "qvc:+s:t:+w:+W:+I:np:4"IF_PING6("6")
enum { enum {
OPT_QUIET = 1 << 0, OPT_QUIET = 1 << 0,
OPT_VERBOSE = 1 << 1, OPT_VERBOSE = 1 << 1,
@ -863,9 +864,12 @@ static int common_ping_main(int opt, char **argv)
INIT_G(); INIT_G();
/* exactly one argument needed; -v and -q don't mix; -c NUM, -t NUM, -w NUM, -W NUM */ opt |= getopt32(argv, "^"
opt_complementary = "=1:q--v:v--q"; OPT_STRING
opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &opt_ttl, &deadline, &timeout, &str_I, &str_p); /* exactly one arg; -v and -q don't mix */
"\0" "=1:q--v:v--q",
&pingcount, &str_s, &opt_ttl, &deadline, &timeout, &str_I, &str_p
);
if (opt & OPT_s) if (opt & OPT_s)
datalen = xatou16(str_s); // -s datalen = xatou16(str_s); // -s
if (opt & OPT_I) { // -I if (opt & OPT_I) { // -I

View File

@ -75,8 +75,11 @@ int pscan_main(int argc UNUSED_PARAM, char **argv)
unsigned rtt_4; unsigned rtt_4;
unsigned start, diff; unsigned start, diff;
opt_complementary = "=1"; /* exactly one non-option */ opt = getopt32(argv, "^"
opt = getopt32(argv, "cbp:P:t:T:", &opt_min_port, &opt_max_port, &opt_timeout, &opt_min_rtt); "cbp:P:t:T:"
"\0" "=1", /* exactly one non-option */
&opt_min_port, &opt_max_port, &opt_timeout, &opt_min_rtt
);
argv += optind; argv += optind;
max_port = xatou_range(opt_max_port, 1, 65535); max_port = xatou_range(opt_max_port, 1, 65535);
port = xatou_range(opt_min_port, 1, max_port); port = xatou_range(opt_min_port, 1, max_port);

View File

@ -128,8 +128,9 @@ int slattach_main(int argc UNUSED_PARAM, char **argv)
INIT_G(); INIT_G();
/* Parse command line options */ /* Parse command line options */
opt_complementary = "=1"; opt = getopt32(argv, "^" "p:s:c:ehmLF" "\0" "=1",
opt = getopt32(argv, "p:s:c:ehmLF", &proto, &baud_str, &extcmd); &proto, &baud_str, &extcmd
);
/*argc -= optind;*/ /*argc -= optind;*/
argv += optind; argv += optind;

View File

@ -269,10 +269,11 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
tcp = (applet_name[0] == 't'); tcp = (applet_name[0] == 't');
/* 3+ args, -i at most once, -p implies -h, -v is counter, -b N, -c N */
opt_complementary = "-3:i--i:ph:vv";
#ifdef SSLSVD #ifdef SSLSVD
opts = getopt32(argv, "+c:+C:i:x:u:l:Eb:+hpt:vU:/:Z:K:", opts = getopt32(argv, "^+"
"c:+C:i:x:u:l:Eb:+hpt:vU:/:Z:K:" /* -c NUM, -b NUM */
/* 3+ args, -i at most once, -p implies -h, -v is a counter */
"\0" "-3:i--i:ph:vv",
&cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname, &cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
&backlog, &str_t, &ssluser, &root, &cert, &key, &verbose &backlog, &str_t, &ssluser, &root, &cert, &key, &verbose
); );

View File

@ -659,13 +659,15 @@ int telnetd_main(int argc UNUSED_PARAM, char **argv)
#endif #endif
INIT_G(); INIT_G();
/* -w NUM, and implies -F. -w and -i don't mix */
IF_FEATURE_TELNETD_INETD_WAIT(opt_complementary = "wF:i--w:w--i";)
/* Even if !STANDALONE, we accept (and ignore) -i, thus people /* Even if !STANDALONE, we accept (and ignore) -i, thus people
* don't need to guess whether it's ok to pass -i to us */ * don't need to guess whether it's ok to pass -i to us */
opt = getopt32(argv, "f:l:Ki" opt = getopt32(argv, "^"
"f:l:Ki"
IF_FEATURE_TELNETD_STANDALONE("p:b:F") IF_FEATURE_TELNETD_STANDALONE("p:b:F")
IF_FEATURE_TELNETD_INETD_WAIT("Sw:+"), IF_FEATURE_TELNETD_INETD_WAIT("Sw:+") /* -w NUM */
"\0"
/* -w implies -F. -w and -i don't mix */
IF_FEATURE_TELNETD_INETD_WAIT("wF:i--w:w--i"),
&G.issuefile, &G.loginpath &G.issuefile, &G.loginpath
IF_FEATURE_TELNETD_STANDALONE(, &opt_portnbr, &opt_bindaddr) IF_FEATURE_TELNETD_STANDALONE(, &opt_portnbr, &opt_bindaddr)
IF_FEATURE_TELNETD_INETD_WAIT(, &sec_linger) IF_FEATURE_TELNETD_INETD_WAIT(, &sec_linger)

View File

@ -761,15 +761,16 @@ int tftp_main(int argc UNUSED_PARAM, char **argv)
INIT_G(); INIT_G();
/* -p or -g is mandatory, and they are mutually exclusive */ IF_GETPUT(opt =) getopt32(argv, "^"
opt_complementary = "" IF_FEATURE_TFTP_GET("g:") IF_FEATURE_TFTP_PUT("p:")
IF_GETPUT("g--p:p--g:");
IF_GETPUT(opt =) getopt32(argv,
IF_FEATURE_TFTP_GET("g") IF_FEATURE_TFTP_PUT("p") IF_FEATURE_TFTP_GET("g") IF_FEATURE_TFTP_PUT("p")
"l:r:" IF_FEATURE_TFTP_BLOCKSIZE("b:"), "l:r:" IF_FEATURE_TFTP_BLOCKSIZE("b:")
"\0"
/* -p or -g is mandatory, and they are mutually exclusive */
IF_FEATURE_TFTP_GET("g:") IF_FEATURE_TFTP_PUT("p:")
IF_GETPUT("g--p:p--g:"),
&local_file, &remote_file &local_file, &remote_file
IF_FEATURE_TFTP_BLOCKSIZE(, &blksize_str)); IF_FEATURE_TFTP_BLOCKSIZE(, &blksize_str)
);
argv += optind; argv += optind;
# if ENABLE_FEATURE_TFTP_BLOCKSIZE # if ENABLE_FEATURE_TFTP_BLOCKSIZE

View File

@ -833,9 +833,9 @@ common_traceroute_main(int op, char **argv)
INIT_G(); INIT_G();
/* minimum 1 arg */ op |= getopt32(argv, "^"
opt_complementary = "-1:x-x"; OPT_STRING
op |= getopt32(argv, OPT_STRING "\0" "-1:x-x" /* minimum 1 arg */
, &tos_str, &device, &max_ttl_str, &port_str, &nprobes_str , &tos_str, &device, &max_ttl_str, &port_str, &nprobes_str
, &source, &waittime_str, &pausemsecs_str, &first_ttl_str , &source, &waittime_str, &pausemsecs_str, &first_ttl_str
); );

View File

@ -83,10 +83,13 @@ int tunctl_main(int argc UNUSED_PARAM, char **argv)
#endif #endif
}; };
opt_complementary = "=0:t--d:d--t"; // no arguments; t ^ d opts = getopt32(argv, "^"
opts = getopt32(argv, "f:t:d:" IF_FEATURE_TUNCTL_UG("u:g:b"), "f:t:d:" IF_FEATURE_TUNCTL_UG("u:g:b")
"\0"
"=0:t--d:d--t", // no arguments; t ^ d
&opt_device, &opt_name, &opt_name &opt_device, &opt_name, &opt_name
IF_FEATURE_TUNCTL_UG(, &opt_user, &opt_group)); IF_FEATURE_TUNCTL_UG(, &opt_user, &opt_group)
);
// select device // select device
memset(&ifr, 0, sizeof(ifr)); memset(&ifr, 0, sizeof(ifr));
@ -153,9 +156,12 @@ int tunctl_main(int argc UNUSED_PARAM, char **argv)
OPT_d = 1 << 2, // delete named interface OPT_d = 1 << 2, // delete named interface
}; };
opt_complementary = "=0:t--d:d--t"; // no arguments; t ^ d opts = getopt32(argv, "^"
opts = getopt32(argv, "f:t:d:u:g:b", // u, g, b accepted and ignored "f:t:d:u:g:b" // u, g, b accepted and ignored
&opt_device, &opt_name, &opt_name, NULL, NULL); "\0"
"=0:t--d:d--t", // no arguments; t ^ d
&opt_device, &opt_name, &opt_name, NULL, NULL
);
// set interface name // set interface name
memset(&ifr, 0, sizeof(ifr)); memset(&ifr, 0, sizeof(ifr));

View File

@ -1101,13 +1101,14 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
client_config.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; client_config.script = CONFIG_UDHCPC_DEFAULT_SCRIPT;
/* Parse command line */ /* Parse command line */
/* O,x: list; -T,-t,-A take numeric param */ opt = getopt32long(argv, "^"
IF_UDHCP_VERBOSE(opt_complementary = "vv";) /* O,x: list; -T,-t,-A take numeric param */
opt = getopt32long(argv, "i:np:qRr:s:T:+t:+SA:+O:*ox:*f" "i:np:qRr:s:T:+t:+SA:+O:*ox:*f"
USE_FOR_MMU("b") USE_FOR_MMU("b")
///IF_FEATURE_UDHCPC_ARPING("a") ///IF_FEATURE_UDHCPC_ARPING("a")
IF_FEATURE_UDHCP_PORT("P:") IF_FEATURE_UDHCP_PORT("P:")
"v" "v"
"\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */
, udhcpc6_longopts , udhcpc6_longopts
, &client_config.interface, &client_config.pidfile, &str_r /* i,p */ , &client_config.interface, &client_config.pidfile, &str_r /* i,p */
, &client_config.script /* s */ , &client_config.script /* s */

View File

@ -1295,16 +1295,18 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
str_V = "udhcp "BB_VER; str_V = "udhcp "BB_VER;
/* Parse command line */ /* Parse command line */
/* O,x: list; -T,-t,-A take numeric param */ opt = getopt32long(argv, "^"
IF_UDHCP_VERBOSE(opt_complementary = "vv";) /* O,x: list; -T,-t,-A take numeric param */
opt = getopt32long(argv, "CV:H:h:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fB" "CV:H:h:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fB"
USE_FOR_MMU("b") USE_FOR_MMU("b")
IF_FEATURE_UDHCPC_ARPING("a::") IF_FEATURE_UDHCPC_ARPING("a::")
IF_FEATURE_UDHCP_PORT("P:") IF_FEATURE_UDHCP_PORT("P:")
"v" "v"
"\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */
, udhcpc_longopts , udhcpc_longopts
, &str_V, &str_h, &str_h, &str_F , &str_V, &str_h, &str_h, &str_F
, &client_config.interface, &client_config.pidfile, &str_r /* i,p */ , &client_config.interface, &client_config.pidfile /* i,p */
, &str_r /* r */
, &client_config.script /* s */ , &client_config.script /* s */
, &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */
, &list_O , &list_O

View File

@ -814,11 +814,12 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;)
IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;)
opt = getopt32(argv, "^"
"fSI:va:"IF_FEATURE_UDHCP_PORT("P:")
"\0"
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
opt_complementary = "vv"; "vv"
#endif #endif
opt = getopt32(argv, "fSI:va:"
IF_FEATURE_UDHCP_PORT("P:")
, &str_I , &str_I
, &str_a , &str_a
IF_FEATURE_UDHCP_PORT(, &str_P) IF_FEATURE_UDHCP_PORT(, &str_P)

View File

@ -54,8 +54,12 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv)
#endif #endif
init_unicode(); init_unicode();
opt_complementary = "=0:a--r:r--a"; opt = getopt32long(argv, "^"
opt = getopt32long(argv, "arf:d", dumpleases_longopts, &file); "arf:d"
"\0" "=0:a--r:r--a",
dumpleases_longopts,
&file
);
fd = xopen(file, O_RDONLY); fd = xopen(file, O_RDONLY);

View File

@ -1387,9 +1387,8 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
#if ENABLE_FEATURE_WGET_LONG_OPTIONS #if ENABLE_FEATURE_WGET_LONG_OPTIONS
#endif #endif
opt_complementary = "-1" /* at least one URL */ GETOPT32(argv, "^"
IF_FEATURE_WGET_LONG_OPTIONS(":\xff::"); /* --header is a list */ "cqSO:P:Y:U:T:+"
GETOPT32(argv, "cqSO:P:Y:U:T:+"
/*ignored:*/ "t:" /*ignored:*/ "t:"
/*ignored:*/ "n::" /*ignored:*/ "n::"
/* wget has exactly four -n<letter> opts, all of which we can ignore: /* wget has exactly four -n<letter> opts, all of which we can ignore:
@ -1400,6 +1399,9 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
* "n::" above says that we accept -n[ARG]. * "n::" above says that we accept -n[ARG].
* Specifying "n:" would be a bug: "-n ARG" would eat ARG! * Specifying "n:" would be a bug: "-n ARG" would eat ARG!
*/ */
"\0"
"-1" /* at least one URL */
IF_FEATURE_WGET_LONG_OPTIONS(":\xff::") /* --header is a list */
LONGOPTS LONGOPTS
, &G.fname_out, &G.dir_prefix, , &G.fname_out, &G.dir_prefix,
&G.proxy_flag, &G.user_agent, &G.proxy_flag, &G.user_agent,

View File

@ -167,8 +167,7 @@ int whois_main(int argc UNUSED_PARAM, char **argv)
int port = 43; int port = 43;
const char *host = "whois.iana.org"; const char *host = "whois.iana.org";
opt_complementary = "-1"; getopt32(argv, "^" "ih:p:+" "\0" "-1", &host, &port);
getopt32(argv, "ih:p:+", &host, &port);
argv += optind; argv += optind;
do { do {

Some files were not shown because too many files have changed in this diff Show More