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:
parent
036585a911
commit
22542eca18
@ -243,10 +243,13 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* prepend '-' to the first argument if required */
|
||||
if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0')
|
||||
argv[1] = xasprintf("-%s", argv[1]);
|
||||
/* -1: at least one param is reqd */
|
||||
opt = getopt32(argv, "^"
|
||||
"voc""ptx"IF_FEATURE_AR_CREATE("r")
|
||||
"\0"
|
||||
/* -1: at least one arg is reqd */
|
||||
/* one of p,t,x[,r] is required */
|
||||
opt_complementary = "-1:p:t:x"IF_FEATURE_AR_CREATE(":r");
|
||||
opt = getopt32(argv, "voc""ptx"IF_FEATURE_AR_CREATE("r"));
|
||||
"-1:p:t:x"IF_FEATURE_AR_CREATE(":r")
|
||||
);
|
||||
argv += optind;
|
||||
|
||||
t = opt / FIRST_CMD;
|
||||
|
@ -195,9 +195,11 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
* --best alias for -9
|
||||
*/
|
||||
|
||||
opt_complementary = "s2"; /* -s means -2 (compatibility) */
|
||||
opt = getopt32(argv, "^"
|
||||
/* 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 (opt & 0x30) // -d and/or -t
|
||||
return bunzip2_main(argc, argv);
|
||||
|
@ -80,8 +80,9 @@ int dpkg_deb_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
|
||||
/* 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;
|
||||
//argc -= optind;
|
||||
|
||||
|
@ -1138,7 +1138,7 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* -U is "anti -k", invert bit for bbunpack(): */
|
||||
option_mask32 ^= OPT_KEEP;
|
||||
/* -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)
|
||||
option_mask32 |= OPT_KEEP;
|
||||
|
||||
|
@ -973,18 +973,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Prepend '-' to the first argument if required */
|
||||
if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0')
|
||||
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
|
||||
/* Lie to buildroot when it starts asking stupid questions. */
|
||||
if (argv[1] && strcmp(argv[1], "--version") == 0) {
|
||||
@ -1021,7 +1009,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
opt = GETOPT32(argv,
|
||||
opt = GETOPT32(argv, "^"
|
||||
"txC:f:Oopvk"
|
||||
IF_FEATURE_TAR_CREATE( "ch" )
|
||||
IF_FEATURE_SEAMLESS_BZ2( "j" )
|
||||
@ -1032,6 +1020,17 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
IF_FEATURE_SEAMLESS_Z( "Z" )
|
||||
IF_FEATURE_TAR_NOPRESERVE_TIME("m")
|
||||
IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
|
||||
"\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
|
||||
, &base_dir // -C dir
|
||||
, &tar_filename // -f filename
|
||||
|
@ -348,8 +348,7 @@ int loadfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned char *buffer;
|
||||
|
||||
// no arguments allowed!
|
||||
opt_complementary = "=0";
|
||||
getopt32(argv, "");
|
||||
getopt32(argv, "^" "" "\0" "=0");
|
||||
|
||||
/*
|
||||
* 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;
|
||||
const char *tty_name = CURRENT_TTY;
|
||||
|
||||
opt_complementary = "=1";
|
||||
opts = getopt32(argv, "m:C:", &mapfilename, &tty_name);
|
||||
opts = getopt32(argv, "^" "m:C:" "\0" "=1", &mapfilename, &tty_name);
|
||||
argv += optind;
|
||||
|
||||
fd = xopen_nonblocking(tty_name);
|
||||
|
@ -47,8 +47,7 @@ int setconsole_main(int argc UNUSED_PARAM, char **argv)
|
||||
int reset;
|
||||
|
||||
/* at most one non-option argument */
|
||||
opt_complementary = "?1";
|
||||
reset = getopt32(argv, "r");
|
||||
reset = getopt32(argv, "^" "r" "\0" "?1");
|
||||
|
||||
argv += 1 + reset;
|
||||
if (*argv) {
|
||||
|
@ -170,9 +170,11 @@ int cat_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
unsigned opts;
|
||||
|
||||
IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */)
|
||||
opts = getopt32(argv, IF_FEATURE_CATV("^")
|
||||
/* -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;
|
||||
|
||||
/* Read from stdin if there's nothing else to do. */
|
||||
|
@ -123,8 +123,7 @@ int chmod_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
/* Parse options */
|
||||
opt_complementary = "-2";
|
||||
getopt32(argv, ("-"OPT_STR) + 1); /* Reuse string */
|
||||
getopt32(argv, "^" OPT_STR "\0" "-2");
|
||||
argv += optind;
|
||||
|
||||
/* Restore option-like mode if needed */
|
||||
|
@ -55,7 +55,7 @@
|
||||
/* 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 OPT_RECURSE (opt & 1)
|
||||
#define OPT_NODEREF (opt & 2)
|
||||
@ -127,11 +127,10 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
|
||||
int opt, flags;
|
||||
struct param_t param;
|
||||
|
||||
opt_complementary = "-2";
|
||||
#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
|
||||
opt = getopt32long(argv, OPT_STR, chown_longopts);
|
||||
opt = getopt32long(argv, "^" OPT_STR "\0" "=2", chown_longopts);
|
||||
#else
|
||||
opt = getopt32(argv, OPT_STR);
|
||||
opt = getopt32(argv, "^" OPT_STR "\0" "=2");
|
||||
#endif
|
||||
argv += optind;
|
||||
|
||||
|
@ -62,8 +62,7 @@ int comm_main(int argc UNUSED_PARAM, char **argv)
|
||||
int i;
|
||||
int order;
|
||||
|
||||
opt_complementary = "=2";
|
||||
getopt32(argv, "123");
|
||||
getopt32(argv, "^" "123" "\0" "=2");
|
||||
argv += optind;
|
||||
|
||||
for (i = 0; i < 2; ++i) {
|
||||
|
@ -73,15 +73,17 @@ int cp_main(int argc, char **argv)
|
||||
#endif
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
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
|
||||
opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR";
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
flags = getopt32long(argv, FILEUTILS_CP_OPTSTR,
|
||||
"-2:l--s:s--l:Pd:rRd:Rd:apdR",
|
||||
"archive\0" No_argument "a"
|
||||
"force\0" No_argument "f"
|
||||
"interactive\0" No_argument "i"
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
|
||||
/* 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_CHAR_FLGS (1 << 1)
|
||||
#define CUT_OPT_FIELDS_FLGS (1 << 2)
|
||||
@ -201,8 +201,11 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
|
||||
char *sopt, *ltok;
|
||||
unsigned opt;
|
||||
|
||||
opt_complementary = "b--bcf:c--bcf:f--bcf";
|
||||
opt = getopt32(argv, optstring, &sopt, &sopt, &sopt, <ok);
|
||||
opt = getopt32(argv, "^"
|
||||
OPT_STR
|
||||
"\0" "b--bcf:c--bcf:f--bcf",
|
||||
&sopt, &sopt, &sopt, <ok
|
||||
);
|
||||
// argc -= optind;
|
||||
argv += optind;
|
||||
if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
|
||||
|
@ -192,12 +192,16 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
char *filename;
|
||||
char *isofmt_arg = NULL;
|
||||
|
||||
opt_complementary = "d--s:s--d"
|
||||
IF_FEATURE_DATE_ISOFMT(":R--I:I--R");
|
||||
opt = getopt32long(argv, "Rs:ud:r:"
|
||||
IF_FEATURE_DATE_ISOFMT("I::D:"), date_longopts,
|
||||
opt = getopt32long(argv, "^"
|
||||
"Rs:ud:r:"
|
||||
IF_FEATURE_DATE_ISOFMT("I::D:")
|
||||
"\0"
|
||||
"d--s:s--d"
|
||||
IF_FEATURE_DATE_ISOFMT(":R--I:I--R"),
|
||||
date_longopts,
|
||||
&date_str, &date_str, &filename
|
||||
IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt));
|
||||
IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt)
|
||||
);
|
||||
argv += optind;
|
||||
maybe_set_utc(opt);
|
||||
|
||||
|
@ -115,15 +115,18 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
init_unicode();
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY
|
||||
opt_complementary = "k-mB:m-Bk:B-km";
|
||||
#elif ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "k-m:m-k";
|
||||
#endif
|
||||
opt = getopt32(argv, "kPT"
|
||||
opt = getopt32(argv, "^"
|
||||
"kPT"
|
||||
IF_FEATURE_DF_FANCY("aiB:")
|
||||
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)
|
||||
df_disp_hr = 1024*1024;
|
||||
|
||||
|
@ -120,8 +120,7 @@ int dos2unix_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
/* -u convert to unix, -d convert to dos */
|
||||
opt_complementary = "u--d:d--u"; /* mutually exclusive */
|
||||
o = getopt32(argv, "du");
|
||||
o = getopt32(argv, "^" "du" "\0" "u--d:d--u"); /* mutually exclusive */
|
||||
|
||||
/* Do the conversion requested by an argument else do the default
|
||||
* conversion depending on our name. */
|
||||
|
@ -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.
|
||||
*/
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
|
||||
opt = getopt32(argv, "aHkLsx" "d:+" "lc" "hm", &G.max_print_depth);
|
||||
opt = getopt32(argv, "^"
|
||||
"aHkLsxd:+lchm"
|
||||
"\0" "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s",
|
||||
&G.max_print_depth
|
||||
);
|
||||
argv += optind;
|
||||
if (opt & OPT_h_for_humans) {
|
||||
G.disp_unit = 0;
|
||||
@ -255,8 +258,11 @@ int du_main(int argc UNUSED_PARAM, char **argv)
|
||||
G.disp_unit = 1024;
|
||||
}
|
||||
#else
|
||||
opt_complementary = "H-L:L-H:s-d:d-s";
|
||||
opt = getopt32(argv, "aHkLsx" "d:+" "lc", &G.max_print_depth);
|
||||
opt = getopt32(argv, "^"
|
||||
"aHkLsxd:+lc"
|
||||
"\0" "H-L:L-H:s-d:d-s",
|
||||
&G.max_print_depth
|
||||
);
|
||||
argv += optind;
|
||||
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
if (opt & OPT_k_kbytes) {
|
||||
|
@ -174,9 +174,10 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
|
||||
, &opt_t
|
||||
);
|
||||
} else {
|
||||
/* -t NUM sets also -a */
|
||||
opt_complementary = "ta";
|
||||
opt = getopt32long(argv, "ft:a",
|
||||
opt = getopt32long(argv, "^"
|
||||
"ft:a"
|
||||
"\0"
|
||||
"ta" /* -t NUM sets -a */,
|
||||
"first-only\0" No_argument "i"
|
||||
"tabs\0" Required_argument "t"
|
||||
"all\0" No_argument "a"
|
||||
|
@ -170,9 +170,12 @@ int id_main(int argc UNUSED_PARAM, char **argv)
|
||||
} else {
|
||||
/* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/
|
||||
/* 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"
|
||||
IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G");
|
||||
opt = getopt32(argv, "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];
|
||||
|
@ -140,10 +140,13 @@ int install_main(int argc, char **argv)
|
||||
#endif
|
||||
};
|
||||
|
||||
opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
|
||||
/* -c exists for backwards compatibility, it's needed */
|
||||
/* -b is ignored ("make a backup of each existing destination file") */
|
||||
opts = GETOPT32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"),
|
||||
opts = GETOPT32(argv, "^"
|
||||
"cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:")
|
||||
"\0"
|
||||
"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)
|
||||
|
@ -27,8 +27,7 @@
|
||||
int link_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int link_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
opt_complementary = "=2"; /* exactly 2 params */
|
||||
getopt32(argv, "");
|
||||
getopt32(argv, "^" "" "\0" "=2");
|
||||
argv += optind;
|
||||
if (link(argv[0], argv[1]) != 0) {
|
||||
/* shared message */
|
||||
|
@ -62,8 +62,7 @@ int ln_main(int argc, char **argv)
|
||||
struct stat statbuf;
|
||||
int (*link_func)(const char *, const char *);
|
||||
|
||||
opt_complementary = "-1"; /* min one arg */
|
||||
opts = getopt32(argv, "sfnbS:vT", &suffix);
|
||||
opts = getopt32(argv, "^" "sfnbS:vT" "\0" "-1", &suffix);
|
||||
|
||||
last = argv[argc - 1];
|
||||
argv += optind;
|
||||
|
@ -206,18 +206,18 @@ SPLIT_SUBDIR = 2,
|
||||
/* -SXvhTw GNU options, busybox optionally supports */
|
||||
/* -T WIDTH Ignored (we don't use tabs on output) */
|
||||
/* -Z SELinux mandated option, busybox optionally supports */
|
||||
static const char ls_options[] ALIGN1 =
|
||||
"Cadi1lgnsxAk" /* 12 opts, total 12 */
|
||||
IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */
|
||||
IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */
|
||||
IF_SELINUX("Z") /* 1, 16 */
|
||||
"Q" /* 1, 17 */
|
||||
IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */
|
||||
IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */
|
||||
IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */
|
||||
IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */
|
||||
#define ls_options \
|
||||
"Cadi1lgnsxAk" /* 12 opts, total 12 */ \
|
||||
IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */ \
|
||||
IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */ \
|
||||
IF_SELINUX("Z") /* 1, 16 */ \
|
||||
"Q" /* 1, 17 */ \
|
||||
IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */ \
|
||||
IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */ \
|
||||
IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */ \
|
||||
IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */ \
|
||||
IF_FEATURE_LS_WIDTH("T:w:") /* 2, 29 */
|
||||
;
|
||||
|
||||
enum {
|
||||
OPT_C = (1 << 0),
|
||||
OPT_a = (1 << 1),
|
||||
@ -1093,7 +1093,9 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
|
||||
/* process options */
|
||||
opt_complementary =
|
||||
opt = getopt32long(argv, "^"
|
||||
ls_options
|
||||
"\0"
|
||||
/* -n and -g imply -l */
|
||||
"nl:gl"
|
||||
/* --full-time implies -l */
|
||||
@ -1109,8 +1111,8 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */
|
||||
IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */
|
||||
/* -w NUM: */
|
||||
IF_FEATURE_LS_WIDTH(":w+");
|
||||
opt = getopt32long(argv, ls_options, ls_longopts
|
||||
IF_FEATURE_LS_WIDTH(":w+")
|
||||
, ls_longopts
|
||||
IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width)
|
||||
IF_FEATURE_LS_COLOR(, &color_opt)
|
||||
);
|
||||
|
@ -258,15 +258,14 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
|
||||
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) */
|
||||
/* -s and -w require -c */
|
||||
#if ENABLE_SHA3SUM
|
||||
if (applet_name[3] == HASH_SHA3)
|
||||
flags = getopt32(argv, "scwbta:+", &sha3_width);
|
||||
flags = getopt32(argv, "^" "scwbta:+" "\0" "s?c:w?c", &sha3_width);
|
||||
else
|
||||
#endif
|
||||
flags = getopt32(argv, "scwbt");
|
||||
flags = getopt32(argv, "^" "scwbt" "\0" "s?c:w?c");
|
||||
} else {
|
||||
#if ENABLE_SHA3SUM
|
||||
if (applet_name[3] == HASH_SHA3)
|
||||
|
@ -80,8 +80,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (!path || path[0] == '\0')
|
||||
path = "/tmp";
|
||||
|
||||
opt_complementary = "?1"; /* 1 argument max */
|
||||
opts = getopt32(argv, "dqtp:u", &path);
|
||||
opts = getopt32(argv, "^" "dqtp:u" "\0" "?1"/*1 arg max*/, &path);
|
||||
|
||||
chp = argv[optind];
|
||||
if (!chp) {
|
||||
|
@ -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
|
||||
* takes effect (it unsets previous options).
|
||||
*/
|
||||
opt_complementary = "-2:f-in:i-fn:n-fi";
|
||||
flags = getopt32long(argv, "finv",
|
||||
flags = getopt32long(argv, "^"
|
||||
"finv"
|
||||
"\0"
|
||||
"-2:f-in:i-fn:n-fi",
|
||||
"interactive\0" No_argument "i"
|
||||
"force\0" No_argument "f"
|
||||
"no-clobber\0" No_argument "n"
|
||||
|
@ -71,8 +71,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv)
|
||||
IF_FEATURE_READLINK_FOLLOW(
|
||||
unsigned opt;
|
||||
/* We need exactly one non-option argument. */
|
||||
opt_complementary = "=1";
|
||||
opt = getopt32(argv, "fnvsq");
|
||||
opt = getopt32(argv, "^" "fnvsq" "\0" "=1");
|
||||
fname = argv[optind];
|
||||
)
|
||||
IF_NOT_FEATURE_READLINK_FOLLOW(
|
||||
|
@ -46,8 +46,7 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
|
||||
int flags = 0;
|
||||
unsigned opt;
|
||||
|
||||
opt_complementary = "f-i:i-f";
|
||||
opt = getopt32(argv, "fiRrv");
|
||||
opt = getopt32(argv, "^" "fiRrv" "\0" "f-i:i-f");
|
||||
argv += optind;
|
||||
if (opt & 1)
|
||||
flags |= FILEUTILS_FORCE;
|
||||
|
@ -70,8 +70,11 @@ int shuf_main(int argc, char **argv)
|
||||
unsigned numlines;
|
||||
char eol;
|
||||
|
||||
opt_complementary = "e--i:i--e"; /* mutually exclusive */
|
||||
opts = getopt32(argv, OPT_STR, &opt_i_str, &opt_n_str, &opt_o_str);
|
||||
opts = getopt32(argv, "^"
|
||||
OPT_STR
|
||||
"\0" "e--i:i--e"/* mutually exclusive */,
|
||||
&opt_i_str, &opt_n_str, &opt_o_str
|
||||
);
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
@ -94,7 +94,7 @@
|
||||
*/
|
||||
|
||||
/* These are sort types */
|
||||
static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:*t:";
|
||||
#define OPT_STR "ngMucszbrdfimS:T:o:k:*t:"
|
||||
enum {
|
||||
FLAG_n = 1, /* Numeric sort */
|
||||
FLAG_g = 2, /* Sort using strtod() */
|
||||
@ -378,9 +378,11 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
xfunc_error_retval = 2;
|
||||
|
||||
/* Parse command line options */
|
||||
/* -o and -t can be given at most once */
|
||||
opt_complementary = "o--o:t--t"; /* -t, -o: at most one of each */
|
||||
opts = getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t);
|
||||
opts = getopt32(argv, "^"
|
||||
OPT_STR
|
||||
"\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 */
|
||||
if (opts & FLAG_b)
|
||||
option_mask32 |= FLAG_bb;
|
||||
|
@ -100,8 +100,11 @@ int split_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
setup_common_bufsiz();
|
||||
|
||||
opt_complementary = "?2"; /* max 2 args; -a N */
|
||||
opt = getopt32(argv, "l:b:a:+", &count_p, &count_p, &suffix_len);
|
||||
opt = getopt32(argv, "^"
|
||||
"l:b:a:+" /* -a N */
|
||||
"\0" "?2"/*max 2 args*/,
|
||||
&count_p, &count_p, &suffix_len
|
||||
);
|
||||
|
||||
if (opt & SPLIT_OPT_l)
|
||||
cnt = XATOOFF(count_p);
|
||||
|
@ -762,11 +762,13 @@ int stat_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned opts;
|
||||
statfunc_ptr statfunc = do_stat;
|
||||
|
||||
opt_complementary = "-1"; /* min one arg */
|
||||
opts = getopt32(argv, "tL"
|
||||
opts = getopt32(argv, "^"
|
||||
"tL"
|
||||
IF_FEATURE_STAT_FILESYSTEM("f")
|
||||
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 (opts & OPT_FILESYS) /* -f */
|
||||
|
@ -59,8 +59,7 @@ int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
|
||||
OPT_SYNCFS = (1 << 1),
|
||||
};
|
||||
|
||||
opt_complementary = "d--f:f--d";
|
||||
opts = getopt32(argv, "df");
|
||||
opts = getopt32(argv, "^" "df" "\0" "d--f:f--d");
|
||||
argv += optind;
|
||||
|
||||
/* Handle the no-argument case. */
|
||||
|
@ -140,9 +140,11 @@ int tail_main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
/* -s NUM, -F imlies -f */
|
||||
IF_FEATURE_FANCY_TAIL(opt_complementary = "Ff";)
|
||||
opt = getopt32(argv, "fc:n:" IF_FEATURE_FANCY_TAIL("qs:+vF"),
|
||||
&str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period));
|
||||
opt = getopt32(argv, IF_FEATURE_FANCY_TAIL("^")
|
||||
"fc:n:"IF_FEATURE_FANCY_TAIL("qs:+vF")
|
||||
IF_FEATURE_FANCY_TAIL("\0" "Ff"),
|
||||
&str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period)
|
||||
);
|
||||
#define FOLLOW (opt & 0x1)
|
||||
#define COUNT_BYTES (opt & 0x2)
|
||||
//if (opt & 0x1) // -f
|
||||
|
@ -298,8 +298,8 @@ int tr_main(int argc UNUSED_PARAM, char **argv)
|
||||
* In POSIX locale, these are the same.
|
||||
*/
|
||||
|
||||
opt_complementary = "-1";
|
||||
opts = getopt32(argv, "+Ccds"); /* '+': stop at first non-option */
|
||||
/* '+': stop at first non-option */
|
||||
opts = getopt32(argv, "^+" "Ccds" "\0" "-1");
|
||||
argv += optind;
|
||||
|
||||
str1_length = expand(*argv++, &str1);
|
||||
|
@ -50,8 +50,7 @@ int truncate_main(int argc UNUSED_PARAM, char **argv)
|
||||
OPT_SIZE = (1 << 1),
|
||||
};
|
||||
|
||||
opt_complementary = "s:-1";
|
||||
opts = getopt32(argv, "cs:", &size_str);
|
||||
opts = getopt32(argv, "^" "cs:" "\0" "s:-1", &size_str);
|
||||
|
||||
if (!(opts & OPT_NOCREATE))
|
||||
flags |= O_CREAT;
|
||||
|
@ -25,8 +25,7 @@
|
||||
int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlink_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
opt_complementary = "=1"; /* must have exactly 1 param */
|
||||
getopt32(argv, "");
|
||||
getopt32(argv, "^" "" "\0" "=1");
|
||||
argv += optind;
|
||||
xunlink(argv[0]);
|
||||
return 0;
|
||||
|
@ -120,8 +120,7 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
|
||||
char *outname = NULL;
|
||||
char *line;
|
||||
|
||||
opt_complementary = "?1"; /* 1 argument max */
|
||||
getopt32(argv, "o:", &outname);
|
||||
getopt32(argv, "^" "o:" "\0" "?1"/* 1 arg max*/, &outname);
|
||||
argv += optind;
|
||||
|
||||
if (!argv[0])
|
||||
@ -196,8 +195,7 @@ int base64_main(int argc UNUSED_PARAM, char **argv)
|
||||
FILE *src_stream;
|
||||
unsigned opts;
|
||||
|
||||
opt_complementary = "?1"; /* 1 argument max */
|
||||
opts = getopt32(argv, "d");
|
||||
opts = getopt32(argv, "^" "d" "\0" "?1"/* 1 arg max*/);
|
||||
argv += optind;
|
||||
|
||||
if (!argv[0])
|
||||
|
@ -49,8 +49,7 @@ int uuencode_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
tbl = bb_uuenc_tbl_std;
|
||||
mode = 0666 & ~umask(0666);
|
||||
opt_complementary = "-1:?2"; /* must have 1 or 2 args */
|
||||
if (getopt32(argv, "m")) {
|
||||
if (getopt32(argv, "^" "m" "\0" "-1:?2"/*must have 1 or 2 args*/)) {
|
||||
tbl = bb_uuenc_tbl_base64;
|
||||
}
|
||||
argv += optind;
|
||||
|
@ -117,8 +117,7 @@ int who_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned opt;
|
||||
const char *fmt = "%s";
|
||||
|
||||
opt_complementary = "=0";
|
||||
opt = getopt32(argv, do_who ? "aH" : "");
|
||||
opt = getopt32(argv, do_who ? "^" "aH" "\0" "=0": "^" "" "\0" "=0");
|
||||
if ((opt & 2) || do_w) /* -H or we are w */
|
||||
puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST");
|
||||
|
||||
|
@ -181,8 +181,9 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
|
||||
INIT_G();
|
||||
|
||||
/* We require exactly one argument: the directory name */
|
||||
opt_complementary = "=1";
|
||||
GETOPT32(argv, "a:*u:" LONGOPTS, &arg_list, &umask_p);
|
||||
GETOPT32(argv, "^" "a:*u:" "\0" "=1" LONGOPTS,
|
||||
&arg_list, &umask_p
|
||||
);
|
||||
|
||||
umask(xstrtou_range(umask_p, 8, 0, 07777));
|
||||
|
||||
|
@ -451,15 +451,17 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
INIT_G();
|
||||
|
||||
opt = GETOPT32(argv, "^"
|
||||
"KSbqtma:n:s:u:c:x:p:"
|
||||
IF_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:")
|
||||
/* -K or -S is required; they are mutually exclusive */
|
||||
/* -p is required if -m is given */
|
||||
/* -xpun (at least one) is required if -K is given */
|
||||
/* -xa (at least one) is required if -S is given */
|
||||
/* -q turns off -v */
|
||||
opt_complementary = "K:S:K--S:S--K:m?p:K?xpun:S?xa"
|
||||
IF_FEATURE_START_STOP_DAEMON_FANCY("q-v");
|
||||
opt = GETOPT32(argv, "KSbqtma:n:s:u:c:x:p:"
|
||||
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
|
||||
&startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile
|
||||
IF_FEATURE_START_STOP_DAEMON_FANCY(,&opt_N)
|
||||
|
@ -37,8 +37,7 @@ int which_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (!env_path)
|
||||
env_path = bb_default_root_path;
|
||||
|
||||
opt_complementary = "-1"; /* at least one argument */
|
||||
getopt32(argv, "a");
|
||||
getopt32(argv, "^" "a" "\0" "-1"/*at least one arg*/);
|
||||
argv += optind;
|
||||
|
||||
do {
|
||||
|
@ -71,8 +71,7 @@ int tune2fs_main(int argc UNUSED_PARAM, char **argv)
|
||||
struct ext2_super_block *sb;
|
||||
int fd;
|
||||
|
||||
opt_complementary = "=1";
|
||||
opts = getopt32(argv, "L:c:i:C:", &label, &str_c, &str_i, &str_C);
|
||||
opts = getopt32(argv, "^" "L:c:i:C:" "\0" "=1", &label, &str_c, &str_i, &str_C);
|
||||
if (!opts)
|
||||
bb_show_usage();
|
||||
argv += optind; // argv[0] -- device
|
||||
|
@ -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"
|
||||
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_l (1<<1)
|
||||
|
||||
@ -52,11 +52,13 @@ int cmp_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned opt;
|
||||
int retval = 0;
|
||||
|
||||
opt_complementary = "-1"
|
||||
opt = getopt32(argv, "^"
|
||||
OPT_STR
|
||||
"\0" "-1"
|
||||
IF_DESKTOP(":?4")
|
||||
IF_NOT_DESKTOP(":?2")
|
||||
":l--s:s--l";
|
||||
opt = getopt32(argv, opt_chars);
|
||||
":l--s:s--l"
|
||||
);
|
||||
argv += optind;
|
||||
|
||||
filename1 = *argv;
|
||||
|
@ -984,8 +984,8 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
|
||||
INIT_G();
|
||||
|
||||
/* exactly 2 params; collect multiple -L <label>; -U N */
|
||||
opt_complementary = "=2";
|
||||
GETOPT32(argv, "abdiL:*NqrsS:tTU:+wupBE" LONGOPTS,
|
||||
GETOPT32(argv, "^" "abdiL:*NqrsS:tTU:+wupBE" "\0" "=2"
|
||||
LONGOPTS,
|
||||
&L_arg, &s_start, &opt_U_context);
|
||||
argv += optind;
|
||||
while (L_arg)
|
||||
|
@ -1507,13 +1507,15 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* do normal option parsing */
|
||||
opt_e = opt_f = NULL;
|
||||
opt_i = NULL;
|
||||
opt_complementary = "nn"; /* count -n */
|
||||
/* -i must be first, to match OPT_in_place definition */
|
||||
/* -E is a synonym of -r:
|
||||
* GNU sed 4.2.1 mentions it in neither --help
|
||||
* 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,
|
||||
&G.be_quiet); /* counter for -n */
|
||||
//argc -= optind;
|
||||
|
@ -107,6 +107,7 @@
|
||||
//usage:#define fgrep_trivial_usage NOUSAGE_STR
|
||||
//usage:#define fgrep_full_usage ""
|
||||
|
||||
/* -e,-f are lists; -m,-A,-B,-C have numeric param */
|
||||
#define OPTSTR_GREP \
|
||||
"lnqvscFiHhe:*f:*Lorm:+wx" \
|
||||
IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \
|
||||
@ -686,11 +687,9 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
/* do normal option parsing */
|
||||
#if ENABLE_FEATURE_GREP_CONTEXT
|
||||
/* -H unsets -h; -C unsets -A,-B; -e,-f are lists;
|
||||
* -m,-A,-B,-C have numeric param */
|
||||
opt_complementary = "H-h:C-AB";
|
||||
/* -H unsets -h; -C unsets -A,-B */
|
||||
opts = getopt32(argv,
|
||||
OPTSTR_GREP,
|
||||
"^" OPTSTR_GREP "\0" "H-h:C-AB",
|
||||
&pattern_head, &fopt, &max_matches,
|
||||
&lines_after, &lines_before, &Copt);
|
||||
|
||||
@ -716,9 +715,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
#else
|
||||
/* with auto sanity checks */
|
||||
/* -H unsets -h; -c,-q or -l unset -n; -e,-f are lists; -m N */
|
||||
opt_complementary = "H-h:c-n:q-n:l-n:";
|
||||
getopt32(argv, OPTSTR_GREP,
|
||||
getopt32(argv, "^" OPTSTR_GREP "\0" "H-h:c-n:q-n:l-n:", // why trailing ":"?
|
||||
&pattern_head, &fopt, &max_matches);
|
||||
#endif
|
||||
invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */
|
||||
|
@ -1185,9 +1185,6 @@ void make_all_argv_opts(char **argv) FAST_FUNC;
|
||||
char* single_argv(char **argv) FAST_FUNC;
|
||||
extern const char *const bb_argv_dash[]; /* { "-", NULL } */
|
||||
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;
|
||||
# define No_argument "\0"
|
||||
# define Required_argument "\001"
|
||||
|
@ -96,9 +96,11 @@ getopt32(char **argv, const char *applet_opts, ...)
|
||||
env -i ls -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).
|
||||
|
||||
"^" options string is "^optchars""\0""opt_complementary".
|
||||
|
||||
uint32_t
|
||||
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
|
||||
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
|
||||
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
|
||||
if they are not specified on the command line. For example:
|
||||
|
||||
opt_complementary = "abc";
|
||||
flags = getopt32(argv, "abcd")
|
||||
flags = getopt32(argv, "^abcd""\0""abc")
|
||||
|
||||
If getopt() finds "-a" on the command line, then
|
||||
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"
|
||||
|
||||
int w_counter = 0; // must be initialized!
|
||||
opt_complementary = "ww";
|
||||
getopt32(argv, "w", &w_counter);
|
||||
getopt32(argv, "^w""\0""ww", &w_counter);
|
||||
if (w_counter)
|
||||
width = (w_counter == 1) ? 132 : INT_MAX;
|
||||
else
|
||||
@ -162,8 +162,9 @@ const char *opt_complementary
|
||||
|
||||
llist_t *my_b = NULL;
|
||||
int verbose_level = 0;
|
||||
opt_complementary = "vv:b-c:c-b";
|
||||
f = getopt32(argv, "vb:*c", &my_b, &verbose_level);
|
||||
f = getopt32(argv, "^vb:*c"
|
||||
"\0""vv:b-c:c-b"
|
||||
, &my_b, &verbose_level);
|
||||
if (f & 2) // -c after -b unsets -b flag
|
||||
while (my_b) dosomething_with(llist_pop(&my_b));
|
||||
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
|
||||
then -s is unset. (Note: busybox implements the GNU
|
||||
"--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
|
||||
position of the options on the command line. If one of the
|
||||
two options requires an argument pointer (":" in applet_opts
|
||||
@ -207,8 +208,7 @@ Special characters:
|
||||
|
||||
char *smax_print_depth;
|
||||
|
||||
opt_complementary = "s-d:d-s:x-x";
|
||||
opt = getopt32(argv, "sd:x", &smax_print_depth);
|
||||
opt = getopt32(argv, "^sd:x""\0""s-d:d-s:x-x", &smax_print_depth);
|
||||
|
||||
if (opt & 2)
|
||||
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
|
||||
-b, -c and -f are mutually exclusive and should raise an error
|
||||
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
|
||||
bb_show_usage() and die.
|
||||
|
||||
@ -236,8 +236,7 @@ Special characters:
|
||||
with xatoi_positive() - allowed range is 0..INT_MAX.
|
||||
|
||||
int param; // "unsigned param;" will also work
|
||||
opt_complementary = "p+";
|
||||
getopt32(argv, "p:", ¶m);
|
||||
getopt32(argv, "^p:""\0""p+", ¶m);
|
||||
|
||||
"o::" A double colon after a char in opt_complementary means that the
|
||||
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
|
||||
as required by llist_add_to_end(llist_t **old_head, char *new_item).)
|
||||
|
||||
opt_complementary = "e::";
|
||||
getopt32(argv, "e:", &patterns);
|
||||
getopt32(argv, "^e:""\0""e::", &patterns);
|
||||
|
||||
$ grep -e user -e root /etc/passwd
|
||||
root:x:0:0:root:/root:/bin/bash
|
||||
@ -271,8 +269,7 @@ Special characters:
|
||||
For example from "id" applet:
|
||||
|
||||
// Don't allow -n -r -rn -ug -rug -nug -rnug
|
||||
opt_complementary = "r?ug:n?ug:u--g:g--u";
|
||||
flags = getopt32(argv, "rnug");
|
||||
flags = getopt32(argv, "^rnug""\0""r?ug:n?ug:u--g:g--u");
|
||||
|
||||
This example allowed only:
|
||||
$ 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:
|
||||
|
||||
// Don't allow -KS -SK, but -S or -K is required
|
||||
opt_complementary = "K:S:K--S:S--K";
|
||||
flags = getopt32(argv, "KS...);
|
||||
flags = getopt32(argv, "^KS...""\0""K:S:K--S:S--K");
|
||||
|
||||
|
||||
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 *opt_complementary;
|
||||
|
||||
enum {
|
||||
PARAM_STRING,
|
||||
PARAM_LIST,
|
||||
@ -337,10 +331,12 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
|
||||
int argc;
|
||||
unsigned flags = 0;
|
||||
unsigned requires = 0;
|
||||
unsigned len;
|
||||
t_complementary complementary[33]; /* last stays zero-filled */
|
||||
char first_char;
|
||||
char dont_die_flag;
|
||||
int c;
|
||||
const unsigned char *s;
|
||||
const char *opt_complementary;
|
||||
t_complementary *on_off;
|
||||
#if ENABLE_LONG_OPTS
|
||||
const struct option *l_o;
|
||||
@ -349,23 +345,29 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
|
||||
unsigned trigger;
|
||||
int min_arg = 0;
|
||||
int max_arg = -1;
|
||||
|
||||
#define SHOW_USAGE_IF_ERROR 1
|
||||
|
||||
int spec_flgs = 0;
|
||||
|
||||
/* skip 0: some applets cheat: they do not actually HAVE argv[0] */
|
||||
argc = 1 + string_array_len(argv + 1);
|
||||
#define SHOW_USAGE_IF_ERROR 1
|
||||
|
||||
on_off = complementary;
|
||||
memset(on_off, 0, sizeof(complementary));
|
||||
|
||||
applet_opts = strcpy(alloca(strlen(applet_opts) + 1), applet_opts);
|
||||
len = strlen(applet_opts);
|
||||
|
||||
/* skip bbox extension */
|
||||
first_char = applet_opts[0];
|
||||
if (first_char == '!')
|
||||
opt_complementary = NULL;
|
||||
if (applet_opts[0] == '^') {
|
||||
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 */
|
||||
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 */
|
||||
|
||||
for (s = (const unsigned char *)opt_complementary; s && *s; s++) {
|
||||
s = (const unsigned char *)opt_complementary;
|
||||
if (s) for (; *s; s++) {
|
||||
t_complementary *pair;
|
||||
unsigned *pair_switch;
|
||||
|
||||
@ -513,8 +516,6 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options,
|
||||
s--;
|
||||
}
|
||||
|
||||
/* Make it unnecessary to clear it by hand after each getopt32 call */
|
||||
opt_complementary = NULL;
|
||||
/* In case getopt32 was already called:
|
||||
* reset the libc getopt() function, which keeps internal state.
|
||||
* 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();
|
||||
|
||||
/* 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
|
||||
* "fake" short options, like this one:
|
||||
* 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;
|
||||
|
||||
error:
|
||||
if (first_char != '!')
|
||||
if (dont_die_flag != '!')
|
||||
bb_show_usage();
|
||||
return (int32_t)-1;
|
||||
}
|
||||
|
@ -42,8 +42,9 @@ int parse_main(int argc UNUSED_PARAM, char **argv)
|
||||
int mintokens = 0, ntokens = 128;
|
||||
unsigned noout;
|
||||
|
||||
opt_complementary = "-1";
|
||||
noout = 1 & getopt32(argv, "xn:+m:+d:f:+", &ntokens, &mintokens, &delims, &flags);
|
||||
noout = 1 & getopt32(argv, "^" "xn:+m:+d:f:+" "\0" "-1",
|
||||
&ntokens, &mintokens, &delims, &flags
|
||||
);
|
||||
//argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
|
@ -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))
|
||||
*/
|
||||
GETOPT_RESET();
|
||||
/* opt_complementary = NULL; - cleared by each getopt32() call anyway */
|
||||
|
||||
argc = string_array_len(argv);
|
||||
|
||||
@ -123,7 +122,6 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
|
||||
restore_nofork_data(&old);
|
||||
/* Other globals can be simply reset to defaults */
|
||||
GETOPT_RESET();
|
||||
/* opt_complementary = NULL; - cleared by each getopt32() call anyway */
|
||||
|
||||
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;
|
||||
die_func = NULL;
|
||||
GETOPT_RESET();
|
||||
/* opt_complementary = NULL; - cleared by each getopt32() call anyway */
|
||||
|
||||
//TODO: think pidof, pgrep, pkill!
|
||||
//set_task_comm() makes our pidof find NOEXECs (e.g. "yes >/dev/null"),
|
||||
|
@ -152,11 +152,12 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
/* Syntax:
|
||||
* addgroup group
|
||||
* addgroup -g num group
|
||||
* addgroup --gid num group
|
||||
* addgroup user group
|
||||
* Check for min, max and missing args */
|
||||
opt_complementary = "-1:?2";
|
||||
opts = getopt32long(argv, "g:S", addgroup_longopts, &gid);
|
||||
opts = getopt32long(argv, "^" "g:S" "\0" "-1:?2", addgroup_longopts,
|
||||
&gid
|
||||
);
|
||||
/* move past the commandline options */
|
||||
argv += optind;
|
||||
//argc -= optind;
|
||||
|
@ -201,12 +201,15 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
|
||||
pw.pw_shell = (char *)get_shell_name();
|
||||
pw.pw_dir = NULL;
|
||||
|
||||
opts = getopt32long(argv, "^"
|
||||
"h:g:s:G:DSHu:k:"
|
||||
/* at least one and at most two non-option args */
|
||||
/* disable interactive passwd for system accounts */
|
||||
opt_complementary = "-1:?2:SD";
|
||||
opts = getopt32long(argv, "h:g:s:G:DSHu:k:", adduser_longopts,
|
||||
"\0" "-1:?2:SD",
|
||||
adduser_longopts,
|
||||
&pw.pw_dir, &pw.pw_gecos, &pw.pw_shell,
|
||||
&usegroup, &uid, &skel);
|
||||
&usegroup, &uid, &skel
|
||||
);
|
||||
if (opts & OPT_UID)
|
||||
pw.pw_uid = xatou_range(uid, 0, CONFIG_LAST_ID);
|
||||
|
||||
|
@ -61,8 +61,10 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (getuid() != 0)
|
||||
bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
|
||||
|
||||
opt_complementary = "m--ec:e--mc:c--em";
|
||||
opt = getopt32long(argv, "emc:", chpasswd_longopts, &algo);
|
||||
opt = getopt32long(argv, "^" "emc:" "\0" "m--ec:e--mc:c--em",
|
||||
chpasswd_longopts,
|
||||
&algo
|
||||
);
|
||||
|
||||
while ((name = xmalloc_fgetline(stdin)) != NULL) {
|
||||
char *free_me;
|
||||
|
@ -111,9 +111,10 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv)
|
||||
opt_m = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO;
|
||||
opt_S = NULL;
|
||||
/* at most two non-option arguments; -P NUM */
|
||||
opt_complementary = "?2";
|
||||
getopt32long(argv, "sP:+S:m:a:", mkpasswd_longopts,
|
||||
&fd, &opt_S, &opt_m, &opt_m);
|
||||
getopt32long(argv, "^" "sP:+S:m:a:" "\0" "?2",
|
||||
mkpasswd_longopts,
|
||||
&fd, &opt_S, &opt_m, &opt_m
|
||||
);
|
||||
argv += optind;
|
||||
|
||||
/* have no idea how to handle -s... */
|
||||
|
@ -131,7 +131,7 @@ struct globals {
|
||||
//usage: "\n"
|
||||
//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_LOCAL (1 << 1) /* -L */
|
||||
#define F_FAKEHOST (1 << 2) /* -H */
|
||||
@ -179,8 +179,7 @@ static void parse_args(char **argv)
|
||||
char *ts;
|
||||
int flags;
|
||||
|
||||
opt_complementary = "-2"; /* at least 2 args; -t N */
|
||||
flags = getopt32(argv, opt_string,
|
||||
flags = getopt32(argv, "^" OPT_STR "\0" "-2"/* at least 2 args*/,
|
||||
&G.initstring, &G.fakehost, &G.issue,
|
||||
&G.login, &G.timeout
|
||||
);
|
||||
|
@ -66,8 +66,7 @@ int vlock_main(int argc UNUSED_PARAM, char **argv)
|
||||
struct passwd *pw;
|
||||
|
||||
pw = xgetpwuid(getuid());
|
||||
opt_complementary = "=0"; /* no params! */
|
||||
getopt32(argv, "a");
|
||||
getopt32(argv, "^" "a" "\0" "=0"/* no args!*/);
|
||||
|
||||
/* Ignore some signals so that we don't get killed by them */
|
||||
bb_signals(0
|
||||
|
@ -125,9 +125,9 @@ int popmaildir_main(int argc UNUSED_PARAM, char **argv)
|
||||
INIT_G();
|
||||
|
||||
// parse options
|
||||
opt_complementary = "-1:dd";
|
||||
opts = getopt32(argv,
|
||||
"bdmVcasTkt:+" "R:+Z:L:+H:+" IF_FEATURE_POPMAILDIR_DELIVERY("M:F:"),
|
||||
opts = getopt32(argv, "^"
|
||||
"bdmVcasTkt:+" "R:+Z:L:+H:+" IF_FEATURE_POPMAILDIR_DELIVERY("M:F:")
|
||||
"\0" "-1:dd",
|
||||
&timeout, NULL, NULL, NULL, &opt_nlines
|
||||
IF_FEATURE_POPMAILDIR_DELIVERY(, &delivery, &delivery) // we treat -M and -F the same
|
||||
);
|
||||
|
@ -280,9 +280,9 @@ int reformime_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
// parse options
|
||||
// N.B. only -x and -X are supported so far
|
||||
opt_complementary = "x--X:X--x";
|
||||
opts = getopt32(argv,
|
||||
"x:X" IF_FEATURE_REFORMIME_COMPAT("deis:r:c:m:*h:o:O:"),
|
||||
opts = getopt32(argv, "^"
|
||||
"x:X" IF_FEATURE_REFORMIME_COMPAT("deis:r:c:m:*h:o:O:")
|
||||
"\0" "x--X:X--x",
|
||||
&opt_prefix
|
||||
IF_FEATURE_REFORMIME_COMPAT(, NULL, NULL, &G.opt_charset, NULL, NULL, NULL, NULL)
|
||||
);
|
||||
|
@ -256,13 +256,17 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
|
||||
G.fp0 = xfdopen_for_read(3);
|
||||
|
||||
// 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
|
||||
// -a is for ssmtp (http://downloads.openwrt.org/people/nico/man/man8/ssmtp.8.html) compatibility,
|
||||
// it is still under development.
|
||||
opts = getopt32(argv, "tf:o:iw:+H:S:a:*:v", &opt_from, NULL,
|
||||
&timeout, &opt_connect, &opt_connect, &list, &verbose);
|
||||
opts = getopt32(argv, "^"
|
||||
"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;
|
||||
argv += optind;
|
||||
|
||||
|
@ -95,9 +95,10 @@ int adjtimex_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
memset(&txc, 0, sizeof(txc));
|
||||
|
||||
opt_complementary = "=0"; /* no valid non-option parameters */
|
||||
opt = getopt32(argv, "qo:f:p:t:",
|
||||
&opt_o, &opt_f, &opt_p, &opt_t);
|
||||
opt = getopt32(argv, "^" "qo:f:p:t:"
|
||||
"\0" "=0"/*no valid non-option args*/,
|
||||
&opt_o, &opt_f, &opt_p, &opt_t
|
||||
);
|
||||
//if (opt & 0x1) // -q
|
||||
if (opt & 0x2) { // -o
|
||||
txc.offset = xatol(opt_o);
|
||||
|
@ -1021,13 +1021,17 @@ int crond_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
INIT_G();
|
||||
|
||||
opts = getopt32(argv, "^"
|
||||
"l:L:fbSc:" IF_FEATURE_CROND_D("d:")
|
||||
"\0"
|
||||
/* "-b after -f is ignored", and so on for every pair a-b */
|
||||
opt_complementary = "f-b:b-f:S-L:L-S" IF_FEATURE_CROND_D(":d-l")
|
||||
"f-b:b-f:S-L:L-S" IF_FEATURE_CROND_D(":d-l")
|
||||
/* -l and -d have numeric param */
|
||||
":l+" IF_FEATURE_CROND_D(":d+");
|
||||
opts = getopt32(argv, "l:L:fbSc:" IF_FEATURE_CROND_D("d:"),
|
||||
":l+" IF_FEATURE_CROND_D(":d+")
|
||||
,
|
||||
&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 */
|
||||
|
||||
if (!(opts & OPT_f)) {
|
||||
|
@ -99,8 +99,9 @@ int crontab_main(int argc UNUSED_PARAM, char **argv)
|
||||
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", &user_name, &crontab_dir);
|
||||
opt_ler = getopt32(argv, "^" "u:c:lerd" "\0" "?1:dr"/*max one arg; -d implies -r*/,
|
||||
&user_name, &crontab_dir
|
||||
);
|
||||
argv += optind;
|
||||
|
||||
if (sanitize_env_if_suid()) { /* Clears dangerous stuff, sets PATH */
|
||||
|
@ -82,8 +82,7 @@ int flash_eraseall_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned int flags;
|
||||
char *mtd_name;
|
||||
|
||||
opt_complementary = "=1";
|
||||
flags = getopt32(argv, "jNq");
|
||||
flags = getopt32(argv, "^" "jNq" "\0" "=1");
|
||||
|
||||
mtd_name = argv[optind];
|
||||
fd = xopen(mtd_name, O_RDWR);
|
||||
|
@ -69,8 +69,7 @@ int flashcp_main(int argc UNUSED_PARAM, char **argv)
|
||||
RESERVE_CONFIG_UBUFFER(buf, BUFSIZE);
|
||||
RESERVE_CONFIG_UBUFFER(buf2, BUFSIZE);
|
||||
|
||||
opt_complementary = "=2"; /* exactly 2 non-option args: file, dev */
|
||||
/*opts =*/ getopt32(argv, "v");
|
||||
/*opts =*/ getopt32(argv, "^" "v" "\0" "=2"/*exactly 2 non-option args: file,dev*/);
|
||||
argv += optind;
|
||||
// filename = *argv++;
|
||||
// devicename = *argv;
|
||||
|
@ -455,14 +455,12 @@ int i2cget_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int i2cget_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
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 mode = I2C_SMBUS_BYTE, pec = 0, fd;
|
||||
unsigned opts;
|
||||
|
||||
opt_complementary = "-2:?4"; /* from 2 to 4 args */
|
||||
opts = getopt32(argv, optstr);
|
||||
opts = getopt32(argv, "^" "fy" "\0" "-2:?4"/*from 2 to 4 args*/);
|
||||
argv += optind;
|
||||
|
||||
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),
|
||||
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 val, blen = 0, mask = 0, fd, status;
|
||||
@ -552,8 +549,7 @@ int i2cset_main(int argc, char **argv)
|
||||
char *opt_m_arg = NULL;
|
||||
unsigned opts;
|
||||
|
||||
opt_complementary = "-3"; /* from 3 to ? args */
|
||||
opts = getopt32(argv, optstr, &opt_m_arg);
|
||||
opts = getopt32(argv, "^" "fym:r" "\0" "-3"/*from 3 to ? args*/, &opt_m_arg);
|
||||
argv += 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),
|
||||
opt_r = (1 << 2);
|
||||
const char *const optstr = "fyr:";
|
||||
|
||||
int bus_num, bus_addr, mode = I2C_SMBUS_BYTE_DATA, even = 0, pec = 0;
|
||||
unsigned first = 0x00, last = 0xff, opts;
|
||||
@ -913,8 +908,11 @@ int i2cdump_main(int argc UNUSED_PARAM, char **argv)
|
||||
char *opt_r_str, *dash;
|
||||
int fd, res;
|
||||
|
||||
opt_complementary = "-2:?3"; /* from 2 to 3 args */
|
||||
opts = getopt32(argv, optstr, &opt_r_str);
|
||||
opts = getopt32(argv, "^"
|
||||
"fyr:"
|
||||
"\0" "-2:?3" /* from 2 to 3 args */,
|
||||
&opt_r_str
|
||||
);
|
||||
argv += optind;
|
||||
|
||||
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),
|
||||
opt_q = (1 << 2), opt_r = (1 << 3),
|
||||
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;
|
||||
unsigned first = 0x03, last = 0x77, opts;
|
||||
unsigned long funcs;
|
||||
|
||||
opt_complementary = "q--r:r--q:" /* mutually exclusive */
|
||||
"?3"; /* up to 3 args */
|
||||
opts = getopt32(argv, optstr);
|
||||
opts = getopt32(argv, "^"
|
||||
"yaqrFl"
|
||||
"\0"
|
||||
"q--r:r--q:"/*mutually exclusive*/ "?3"/*up to 3 args*/
|
||||
);
|
||||
argv += optind;
|
||||
|
||||
if (opts & opt_l)
|
||||
|
@ -183,8 +183,7 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv)
|
||||
char *line = (char *)"-";
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
opt_complementary = "=1"; /* exactly one param */
|
||||
getopt32(argv, "d:", &line);
|
||||
getopt32(argv, "^" "d:" "\0" "=1", &line);
|
||||
argv += optind;
|
||||
|
||||
xchdir(*argv); /* ensure root dir exists */
|
||||
|
@ -253,8 +253,7 @@ int man_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
INIT_G();
|
||||
|
||||
opt_complementary = "-1"; /* at least one argument */
|
||||
opt = getopt32(argv, "+aw");
|
||||
opt = getopt32(argv, "^+" "aw" "\0" "-1"/*at least one arg*/);
|
||||
argv += optind;
|
||||
|
||||
sec_list = xstrdup("0p:1:1p:2:3:3p:4:5:6:7:8:9");
|
||||
|
@ -74,8 +74,9 @@ int microcom_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned opts;
|
||||
|
||||
// fetch options
|
||||
opt_complementary = "=1";
|
||||
opts = getopt32(argv, "Xs:+d:+t:+", &speed, &delay, &timeout);
|
||||
opts = getopt32(argv, "^" "Xs:+d:+t:+" "\0" "=1",
|
||||
&speed, &delay, &timeout
|
||||
);
|
||||
// argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
|
@ -123,13 +123,12 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
|
||||
const char *opt_s = "0", *opt_f = "-", *opt_l, *opt_bb;
|
||||
|
||||
if (IS_NANDDUMP) {
|
||||
opt_complementary = "=1";
|
||||
opts = getopt32long(argv, "ons:f:l:",
|
||||
opts = getopt32long(argv, "^" "ons:f:l:" "\0" "=1",
|
||||
"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 */
|
||||
opt_complementary = "-1:?2";
|
||||
opts = getopt32(argv, "pns:", &opt_s);
|
||||
opts = getopt32(argv, "^" "pns:" "\0" "-1:?2", &opt_s);
|
||||
}
|
||||
argv += optind;
|
||||
|
||||
|
@ -742,8 +742,7 @@ int setserial_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int opts;
|
||||
|
||||
opt_complementary = "-1:b-aG:G-ab:a-bG";
|
||||
opts = getopt32(argv, "bGavzgq");
|
||||
opts = getopt32(argv, "^" "bGavzgq" "\0" "-1:b-aG:G-ab:a-bG");
|
||||
argv += optind;
|
||||
|
||||
if (!argv[1]) /* one arg only? (nothing to change?) */
|
||||
|
@ -430,9 +430,10 @@ int time_main(int argc UNUSED_PARAM, char **argv)
|
||||
OPT_f = (1 << 4),
|
||||
};
|
||||
|
||||
opt_complementary = "-1"; /* at least one arg */
|
||||
/* "+": 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;
|
||||
if (opt & OPT_v)
|
||||
output_format = long_format;
|
||||
|
@ -145,20 +145,17 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
|
||||
#define OPTION_a (1 << 5)
|
||||
#define OPTION_t (1 << 6)
|
||||
if (do_mkvol) {
|
||||
opt_complementary = "-1";
|
||||
opts = getopt32(argv, "md:+n:+N:s:a:+t:O:+",
|
||||
opts = getopt32(argv, "^" "md:+n:+N:s:a:+t:O:+" "\0" "-1",
|
||||
&dev_num, &vol_id,
|
||||
&vol_name, &size_bytes_str, &alignment, &type,
|
||||
&vid_hdr_offset
|
||||
);
|
||||
} else
|
||||
if (do_update) {
|
||||
opt_complementary = "-1";
|
||||
opts = getopt32(argv, "s:at", &size_bytes_str);
|
||||
opts = getopt32(argv, "^" "s:at" "\0" "-1", &size_bytes_str);
|
||||
opts *= OPTION_s;
|
||||
} else {
|
||||
opt_complementary = "-1";
|
||||
opts = getopt32(argv, "m:+d:+n:+N:s:a:+t:",
|
||||
opts = getopt32(argv, "^" "m:+d:+n:+N:s:a:+t:" "\0" "-1",
|
||||
&mtd_num, &dev_num, &vol_id,
|
||||
&vol_name, &size_bytes_str, &alignment, &type
|
||||
);
|
||||
|
@ -101,8 +101,9 @@ int watchdog_main(int argc UNUSED_PARAM, char **argv)
|
||||
char *st_arg;
|
||||
char *ht_arg;
|
||||
|
||||
opt_complementary = "=1"; /* must have exactly 1 argument */
|
||||
opts = getopt32(argv, "Ft:T:", &st_arg, &ht_arg);
|
||||
opts = getopt32(argv, "^" "Ft:T:" "\0" "=1"/*must have exactly 1 arg*/,
|
||||
&st_arg, &ht_arg
|
||||
);
|
||||
|
||||
/* We need to daemonize *before* opening the watchdog as many drivers
|
||||
* will only allow one process at a time to do so. Since daemonizing
|
||||
|
@ -148,8 +148,7 @@ int modinfo_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned i;
|
||||
|
||||
field = NULL;
|
||||
opt_complementary = "-1"; /* minimum one param */
|
||||
opts = getopt32(argv, "0F:nadlp", &field);
|
||||
opts = getopt32(argv, "^" "0F:nadlp" "\0" "-1"/*minimum one arg*/, &field);
|
||||
/* If no field selected, show all */
|
||||
if (!(opts & (OPT_TAGS|OPT_F)))
|
||||
option_mask32 |= OPT_TAGS;
|
||||
|
@ -988,10 +988,9 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
#if ENABLE_MODPROBE || ENABLE_INSMOD || ENABLE_RMMOD
|
||||
/* modprobe, insmod, rmmod require at least one argument */
|
||||
opt_complementary = "-1";
|
||||
/* only -q (quiet) and -r (rmmod),
|
||||
* the rest are accepted and ignored (compat) */
|
||||
getopt32(argv, "qrfsvwb");
|
||||
getopt32(argv, "^" "qrfsvwb" "\0" "-1");
|
||||
argv += optind;
|
||||
|
||||
if (is_modprobe) {
|
||||
|
@ -133,7 +133,7 @@
|
||||
*/
|
||||
#define MODPROBE_OPTS "alrDb"
|
||||
/* -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_COMPLEMENTARY "q-v:v-q:l--acr:a--lr:r--al"
|
||||
enum {
|
||||
@ -566,8 +566,10 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
INIT_G();
|
||||
|
||||
opt_complementary = MODPROBE_COMPLEMENTARY;
|
||||
opt = getopt32long(argv, INSMOD_OPTS MODPROBE_OPTS, modprobe_longopts INSMOD_ARGS);
|
||||
opt = getopt32long(argv, "^" INSMOD_OPTS MODPROBE_OPTS "\0" MODPROBE_COMPLEMENTARY,
|
||||
modprobe_longopts
|
||||
INSMOD_ARGS
|
||||
);
|
||||
argv += optind;
|
||||
|
||||
/* Goto modules location */
|
||||
|
@ -306,9 +306,9 @@ int arping_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Dad also sets quit_on_reply.
|
||||
* Advert also sets unsolicited.
|
||||
*/
|
||||
opt_complementary = "=1:Df:AU";
|
||||
opt = getopt32(argv, "DUAqfbc:+w:I:s:",
|
||||
&count, &str_timeout, &device, &source);
|
||||
opt = getopt32(argv, "^" "DUAqfbc:+w:I:s:" "\0" "=1:Df:AU",
|
||||
&count, &str_timeout, &device, &source
|
||||
);
|
||||
if (opt & 0x80) /* -w: timeout */
|
||||
timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000 + 500000;
|
||||
//if (opt & 0x200) /* -s: source */
|
||||
|
@ -212,8 +212,7 @@ int ether_wake_main(int argc UNUSED_PARAM, char **argv)
|
||||
struct whereto_t whereto; /* who to wake up */
|
||||
|
||||
/* handle misc user options */
|
||||
opt_complementary = "=1";
|
||||
flags = getopt32(argv, "bi:p:", &ifname, &pass);
|
||||
flags = getopt32(argv, "^" "bi:p:" "\0" "=1", &ifname, &pass);
|
||||
if (flags & 4) /* -p */
|
||||
wol_passwd_sz = get_wol_pw(pass, wol_passwd);
|
||||
flags &= 1; /* we further interested only in -b [bcast] flag */
|
||||
|
@ -1174,17 +1174,20 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
|
||||
abs_timeout = 1 * 60 * 60;
|
||||
verbose_S = 0;
|
||||
G.timeout = 2 * 60;
|
||||
opt_complementary = "vv:SS";
|
||||
#if BB_MMU
|
||||
opts = getopt32(argv, "vS"
|
||||
IF_FEATURE_FTPD_WRITE("w") "t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:"),
|
||||
opts = getopt32(argv, "^" "vS"
|
||||
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.verbose, &verbose_S);
|
||||
&G.verbose, &verbose_S
|
||||
);
|
||||
#else
|
||||
opts = getopt32(argv, "l1AvS"
|
||||
IF_FEATURE_FTPD_WRITE("w") "t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:"),
|
||||
opts = getopt32(argv, "^" "l1AvS"
|
||||
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.verbose, &verbose_S);
|
||||
&G.verbose, &verbose_S
|
||||
);
|
||||
if (opts & (OPT_l|OPT_1)) {
|
||||
/* Our secret backdoor to ls */
|
||||
if (fchdir(3) != 0)
|
||||
|
@ -361,11 +361,12 @@ int ftpgetput_main(int argc UNUSED_PARAM, char **argv)
|
||||
/*
|
||||
* 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
|
||||
getopt32long(argv, "cvu:p:P:", ftpgetput_longopts,
|
||||
getopt32long(argv, OPTSTRING, ftpgetput_longopts,
|
||||
#else
|
||||
getopt32(argv, "cvu:p:P:",
|
||||
getopt32(argv, OPTSTRING,
|
||||
#endif
|
||||
&user, &password, &port, &verbose_flag, &do_continue
|
||||
);
|
||||
|
@ -2636,17 +2636,19 @@ int httpd_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
|
||||
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.
|
||||
* If user gives relative path in -h,
|
||||
* $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_BASIC_AUTH("r:")
|
||||
IF_FEATURE_HTTPD_AUTH_MD5("m:")
|
||||
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
|
||||
IF_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode)
|
||||
IF_FEATURE_HTTPD_BASIC_AUTH(, &g_realm)
|
||||
|
@ -130,8 +130,11 @@ int ipcalc_main(int argc UNUSED_PARAM, char **argv)
|
||||
#define ipaddr (s_ipaddr.s_addr)
|
||||
char *ipstr;
|
||||
|
||||
opt_complementary = "-1:?2"; /* minimum 1 arg, maximum 2 args */
|
||||
opt = GETOPT32(argv, "mbn" IF_FEATURE_IPCALC_FANCY("phs") LONGOPTS);
|
||||
opt = GETOPT32(argv, "^"
|
||||
"mbn" IF_FEATURE_IPCALC_FANCY("phs")
|
||||
"\0" "-1:?2"/*min 1, max 2 args*/
|
||||
LONGOPTS
|
||||
);
|
||||
argv += optind;
|
||||
if (opt & SILENT)
|
||||
logmode = LOGMODE_NONE; /* suppress error_msg() output */
|
||||
|
@ -787,11 +787,15 @@ int nc_main(int argc UNUSED_PARAM, char **argv)
|
||||
e_found:
|
||||
|
||||
// -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, "np:s:uvw:+" IF_NC_SERVER("lk")
|
||||
IF_NC_EXTRA("i:o:z"),
|
||||
getopt32(argv, "^"
|
||||
"np:s:uvw:+"/* -w N */ IF_NC_SERVER("lk")
|
||||
IF_NC_EXTRA("i:o:z")
|
||||
"\0"
|
||||
"?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));
|
||||
IF_NC_EXTRA(, &str_i, &str_o)
|
||||
, &o_verbose IF_NC_SERVER(, &cnt_l)
|
||||
);
|
||||
argv += optind;
|
||||
#if ENABLE_NC_EXTRA
|
||||
if (option_mask32 & OPT_i) /* line-interval time */
|
||||
|
@ -2230,15 +2230,16 @@ static NOINLINE void ntp_init(char **argv)
|
||||
|
||||
/* Parse options */
|
||||
peers = NULL;
|
||||
opt_complementary = "dd:wn" /* -d: counter; -p: list; -w implies -n */
|
||||
IF_FEATURE_NTPD_SERVER(":Il"); /* -I implies -l */
|
||||
opts = getopt32(argv,
|
||||
opts = getopt32(argv, "^"
|
||||
"nqNx" /* compat */
|
||||
"wp:*S:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */
|
||||
IF_FEATURE_NTPD_SERVER("I:") /* compat */
|
||||
"d" /* compat */
|
||||
"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
|
||||
&G.if_name,
|
||||
#endif
|
||||
|
@ -340,7 +340,8 @@ static int common_ping_main(sa_family_t af, char **argv)
|
||||
|
||||
/* 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 {
|
||||
OPT_QUIET = 1 << 0,
|
||||
OPT_VERBOSE = 1 << 1,
|
||||
@ -863,9 +864,12 @@ static int common_ping_main(int opt, char **argv)
|
||||
|
||||
INIT_G();
|
||||
|
||||
/* exactly one argument needed; -v and -q don't mix; -c NUM, -t NUM, -w NUM, -W NUM */
|
||||
opt_complementary = "=1:q--v:v--q";
|
||||
opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &opt_ttl, &deadline, &timeout, &str_I, &str_p);
|
||||
opt |= getopt32(argv, "^"
|
||||
OPT_STRING
|
||||
/* 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)
|
||||
datalen = xatou16(str_s); // -s
|
||||
if (opt & OPT_I) { // -I
|
||||
|
@ -75,8 +75,11 @@ int pscan_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned rtt_4;
|
||||
unsigned start, diff;
|
||||
|
||||
opt_complementary = "=1"; /* exactly one non-option */
|
||||
opt = getopt32(argv, "cbp:P:t:T:", &opt_min_port, &opt_max_port, &opt_timeout, &opt_min_rtt);
|
||||
opt = getopt32(argv, "^"
|
||||
"cbp:P:t:T:"
|
||||
"\0" "=1", /* exactly one non-option */
|
||||
&opt_min_port, &opt_max_port, &opt_timeout, &opt_min_rtt
|
||||
);
|
||||
argv += optind;
|
||||
max_port = xatou_range(opt_max_port, 1, 65535);
|
||||
port = xatou_range(opt_min_port, 1, max_port);
|
||||
|
@ -128,8 +128,9 @@ int slattach_main(int argc UNUSED_PARAM, char **argv)
|
||||
INIT_G();
|
||||
|
||||
/* Parse command line options */
|
||||
opt_complementary = "=1";
|
||||
opt = getopt32(argv, "p:s:c:ehmLF", &proto, &baud_str, &extcmd);
|
||||
opt = getopt32(argv, "^" "p:s:c:ehmLF" "\0" "=1",
|
||||
&proto, &baud_str, &extcmd
|
||||
);
|
||||
/*argc -= optind;*/
|
||||
argv += optind;
|
||||
|
||||
|
@ -269,10 +269,11 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
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
|
||||
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,
|
||||
&backlog, &str_t, &ssluser, &root, &cert, &key, &verbose
|
||||
);
|
||||
|
@ -659,13 +659,15 @@ int telnetd_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
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
|
||||
* 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_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
|
||||
IF_FEATURE_TELNETD_STANDALONE(, &opt_portnbr, &opt_bindaddr)
|
||||
IF_FEATURE_TELNETD_INETD_WAIT(, &sec_linger)
|
||||
|
@ -761,15 +761,16 @@ int tftp_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
INIT_G();
|
||||
|
||||
/* -p or -g is mandatory, and they are mutually exclusive */
|
||||
opt_complementary = "" IF_FEATURE_TFTP_GET("g:") IF_FEATURE_TFTP_PUT("p:")
|
||||
IF_GETPUT("g--p:p--g:");
|
||||
|
||||
IF_GETPUT(opt =) getopt32(argv,
|
||||
IF_GETPUT(opt =) getopt32(argv, "^"
|
||||
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
|
||||
IF_FEATURE_TFTP_BLOCKSIZE(, &blksize_str));
|
||||
IF_FEATURE_TFTP_BLOCKSIZE(, &blksize_str)
|
||||
);
|
||||
argv += optind;
|
||||
|
||||
# if ENABLE_FEATURE_TFTP_BLOCKSIZE
|
||||
|
@ -833,9 +833,9 @@ common_traceroute_main(int op, char **argv)
|
||||
|
||||
INIT_G();
|
||||
|
||||
/* minimum 1 arg */
|
||||
opt_complementary = "-1:x-x";
|
||||
op |= getopt32(argv, OPT_STRING
|
||||
op |= getopt32(argv, "^"
|
||||
OPT_STRING
|
||||
"\0" "-1:x-x" /* minimum 1 arg */
|
||||
, &tos_str, &device, &max_ttl_str, &port_str, &nprobes_str
|
||||
, &source, &waittime_str, &pausemsecs_str, &first_ttl_str
|
||||
);
|
||||
|
@ -83,10 +83,13 @@ int tunctl_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
};
|
||||
|
||||
opt_complementary = "=0:t--d:d--t"; // no arguments; t ^ d
|
||||
opts = getopt32(argv, "f:t:d:" IF_FEATURE_TUNCTL_UG("u:g:b"),
|
||||
opts = getopt32(argv, "^"
|
||||
"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
|
||||
IF_FEATURE_TUNCTL_UG(, &opt_user, &opt_group));
|
||||
IF_FEATURE_TUNCTL_UG(, &opt_user, &opt_group)
|
||||
);
|
||||
|
||||
// select device
|
||||
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_complementary = "=0:t--d:d--t"; // no arguments; t ^ d
|
||||
opts = getopt32(argv, "f:t:d:u:g:b", // u, g, b accepted and ignored
|
||||
&opt_device, &opt_name, &opt_name, NULL, NULL);
|
||||
opts = getopt32(argv, "^"
|
||||
"f:t:d:u:g:b" // u, g, b accepted and ignored
|
||||
"\0"
|
||||
"=0:t--d:d--t", // no arguments; t ^ d
|
||||
&opt_device, &opt_name, &opt_name, NULL, NULL
|
||||
);
|
||||
|
||||
// set interface name
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
|
@ -1101,13 +1101,14 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||
client_config.script = CONFIG_UDHCPC_DEFAULT_SCRIPT;
|
||||
|
||||
/* Parse command line */
|
||||
opt = getopt32long(argv, "^"
|
||||
/* O,x: list; -T,-t,-A take numeric param */
|
||||
IF_UDHCP_VERBOSE(opt_complementary = "vv";)
|
||||
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")
|
||||
///IF_FEATURE_UDHCPC_ARPING("a")
|
||||
IF_FEATURE_UDHCP_PORT("P:")
|
||||
"v"
|
||||
"\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */
|
||||
, udhcpc6_longopts
|
||||
, &client_config.interface, &client_config.pidfile, &str_r /* i,p */
|
||||
, &client_config.script /* s */
|
||||
|
@ -1295,16 +1295,18 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||
str_V = "udhcp "BB_VER;
|
||||
|
||||
/* Parse command line */
|
||||
opt = getopt32long(argv, "^"
|
||||
/* O,x: list; -T,-t,-A take numeric param */
|
||||
IF_UDHCP_VERBOSE(opt_complementary = "vv";)
|
||||
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")
|
||||
IF_FEATURE_UDHCPC_ARPING("a::")
|
||||
IF_FEATURE_UDHCP_PORT("P:")
|
||||
"v"
|
||||
"\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */
|
||||
, udhcpc_longopts
|
||||
, &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 */
|
||||
, &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */
|
||||
, &list_O
|
||||
|
@ -814,11 +814,12 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
||||
IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;)
|
||||
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
|
||||
opt_complementary = "vv";
|
||||
"vv"
|
||||
#endif
|
||||
opt = getopt32(argv, "fSI:va:"
|
||||
IF_FEATURE_UDHCP_PORT("P:")
|
||||
, &str_I
|
||||
, &str_a
|
||||
IF_FEATURE_UDHCP_PORT(, &str_P)
|
||||
|
@ -54,8 +54,12 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
init_unicode();
|
||||
|
||||
opt_complementary = "=0:a--r:r--a";
|
||||
opt = getopt32long(argv, "arf:d", dumpleases_longopts, &file);
|
||||
opt = getopt32long(argv, "^"
|
||||
"arf:d"
|
||||
"\0" "=0:a--r:r--a",
|
||||
dumpleases_longopts,
|
||||
&file
|
||||
);
|
||||
|
||||
fd = xopen(file, O_RDONLY);
|
||||
|
||||
|
@ -1387,9 +1387,8 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
|
||||
|
||||
#if ENABLE_FEATURE_WGET_LONG_OPTIONS
|
||||
#endif
|
||||
opt_complementary = "-1" /* at least one URL */
|
||||
IF_FEATURE_WGET_LONG_OPTIONS(":\xff::"); /* --header is a list */
|
||||
GETOPT32(argv, "cqSO:P:Y:U:T:+"
|
||||
GETOPT32(argv, "^"
|
||||
"cqSO:P:Y:U:T:+"
|
||||
/*ignored:*/ "t:"
|
||||
/*ignored:*/ "n::"
|
||||
/* 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].
|
||||
* 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
|
||||
, &G.fname_out, &G.dir_prefix,
|
||||
&G.proxy_flag, &G.user_agent,
|
||||
|
@ -167,8 +167,7 @@ int whois_main(int argc UNUSED_PARAM, char **argv)
|
||||
int port = 43;
|
||||
const char *host = "whois.iana.org";
|
||||
|
||||
opt_complementary = "-1";
|
||||
getopt32(argv, "ih:p:+", &host, &port);
|
||||
getopt32(argv, "^" "ih:p:+" "\0" "-1", &host, &port);
|
||||
argv += optind;
|
||||
|
||||
do {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user