diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-08 21:55:02 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-08 21:55:02 +0200 |
commit | 22542eca18e5807b72ddc78999f5101e33f17a53 (patch) | |
tree | 1271842a37c6215c998674a44bf7f561a0deff52 /coreutils | |
parent | 036585a911a5fe6c2cd77b808dd9150500f37272 (diff) |
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>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/cat.c | 8 | ||||
-rw-r--r-- | coreutils/chmod.c | 3 | ||||
-rw-r--r-- | coreutils/chown.c | 7 | ||||
-rw-r--r-- | coreutils/comm.c | 3 | ||||
-rw-r--r-- | coreutils/cp.c | 18 | ||||
-rw-r--r-- | coreutils/cut.c | 9 | ||||
-rw-r--r-- | coreutils/date.c | 14 | ||||
-rw-r--r-- | coreutils/df.c | 15 | ||||
-rw-r--r-- | coreutils/dos2unix.c | 3 | ||||
-rw-r--r-- | coreutils/du.c | 14 | ||||
-rw-r--r-- | coreutils/expand.c | 7 | ||||
-rw-r--r-- | coreutils/id.c | 9 | ||||
-rw-r--r-- | coreutils/install.c | 13 | ||||
-rw-r--r-- | coreutils/link.c | 3 | ||||
-rw-r--r-- | coreutils/ln.c | 3 | ||||
-rw-r--r-- | coreutils/ls.c | 60 | ||||
-rw-r--r-- | coreutils/md5_sha1_sum.c | 7 | ||||
-rw-r--r-- | coreutils/mktemp.c | 3 | ||||
-rw-r--r-- | coreutils/mv.c | 6 | ||||
-rw-r--r-- | coreutils/readlink.c | 3 | ||||
-rw-r--r-- | coreutils/rm.c | 3 | ||||
-rw-r--r-- | coreutils/shuf.c | 7 | ||||
-rw-r--r-- | coreutils/sort.c | 10 | ||||
-rw-r--r-- | coreutils/split.c | 7 | ||||
-rw-r--r-- | coreutils/stat.c | 8 | ||||
-rw-r--r-- | coreutils/sync.c | 3 | ||||
-rw-r--r-- | coreutils/tail.c | 8 | ||||
-rw-r--r-- | coreutils/tr.c | 4 | ||||
-rw-r--r-- | coreutils/truncate.c | 3 | ||||
-rw-r--r-- | coreutils/unlink.c | 3 | ||||
-rw-r--r-- | coreutils/uudecode.c | 6 | ||||
-rw-r--r-- | coreutils/uuencode.c | 3 | ||||
-rw-r--r-- | coreutils/who.c | 3 |
33 files changed, 151 insertions, 125 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c index 390254512..7e35fa5ee 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c @@ -170,9 +170,11 @@ int cat_main(int argc UNUSED_PARAM, char **argv) { unsigned opts; - IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */) - /* -u is ignored ("unbuffered") */ - opts = getopt32(argv, IF_FEATURE_CATV("etvA") IF_FEATURE_CATN("nb") "u"); + opts = getopt32(argv, IF_FEATURE_CATV("^") + /* -u is ignored ("unbuffered") */ + 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. */ diff --git a/coreutils/chmod.c b/coreutils/chmod.c index 2174334d1..88989bf67 100644 --- a/coreutils/chmod.c +++ b/coreutils/chmod.c @@ -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 */ diff --git a/coreutils/chown.c b/coreutils/chown.c index 0c77529ec..985d18d6f 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c @@ -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; diff --git a/coreutils/comm.c b/coreutils/comm.c index 5be11468c..4bee77677 100644 --- a/coreutils/comm.c +++ b/coreutils/comm.c @@ -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) { diff --git a/coreutils/cp.c b/coreutils/cp.c index fe408950a..5b34c27e7 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c @@ -73,15 +73,17 @@ int cp_main(int argc, char **argv) #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 - 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" "force\0" No_argument "f" "interactive\0" No_argument "i" diff --git a/coreutils/cut.c b/coreutils/cut.c index 6578ce8ce..cdd90ab44 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c @@ -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))) diff --git a/coreutils/date.c b/coreutils/date.c index 33f210434..5b15ce778 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -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); diff --git a/coreutils/df.c b/coreutils/df.c index 4d6534bc2..121da970b 100644 --- a/coreutils/df.c +++ b/coreutils/df.c @@ -115,15 +115,18 @@ int df_main(int argc UNUSED_PARAM, char **argv) init_unicode(); + opt = getopt32(argv, "^" + "kPT" + IF_FEATURE_DF_FANCY("aiB:") + IF_FEATURE_HUMAN_READABLE("hm") + "\0" #if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY - opt_complementary = "k-mB:m-Bk:B-km"; + "k-mB:m-Bk:B-km" #elif ENABLE_FEATURE_HUMAN_READABLE - opt_complementary = "k-m:m-k"; + "k-m:m-k" #endif - opt = getopt32(argv, "kPT" - IF_FEATURE_DF_FANCY("aiB:") - IF_FEATURE_HUMAN_READABLE("hm") - IF_FEATURE_DF_FANCY(, &chp)); + IF_FEATURE_DF_FANCY(, &chp) + ); if (opt & OPT_MEGA) df_disp_hr = 1024*1024; diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c index a3d008051..9f098e41e 100644 --- a/coreutils/dos2unix.c +++ b/coreutils/dos2unix.c @@ -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. */ diff --git a/coreutils/du.c b/coreutils/du.c index 947c46e74..d5ce46cf2 100644 --- a/coreutils/du.c +++ b/coreutils/du.c @@ -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) { diff --git a/coreutils/expand.c b/coreutils/expand.c index fa3ff18f4..91084b80b 100644 --- a/coreutils/expand.c +++ b/coreutils/expand.c @@ -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" diff --git a/coreutils/id.c b/coreutils/id.c index 6043bca61..5a7fb9aaf 100644 --- a/coreutils/id.c +++ b/coreutils/id.c @@ -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]; diff --git a/coreutils/install.c b/coreutils/install.c index c01750f81..2e4dc257f 100644 --- a/coreutils/install.c +++ b/coreutils/install.c @@ -140,13 +140,16 @@ 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:"), - LONGOPTS - &gid_str, &mode_str, &uid_str, &last - IF_SELINUX(, &scontext) + 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) ); argc -= optind; argv += optind; diff --git a/coreutils/link.c b/coreutils/link.c index 6e20dafe3..81808b778 100644 --- a/coreutils/link.c +++ b/coreutils/link.c @@ -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 */ diff --git a/coreutils/ln.c b/coreutils/ln.c index fed96af42..2dda5dae9 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c @@ -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; diff --git a/coreutils/ls.c b/coreutils/ls.c index 0834cdc63..af5e6cb51 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -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,24 +1093,26 @@ int ls_main(int argc UNUSED_PARAM, char **argv) #endif /* process options */ - opt_complementary = - /* -n and -g imply -l */ - "nl:gl" - /* --full-time implies -l */ - IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l")) - /* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html: - * in some pairs of opts, only last one takes effect: - */ - IF_FEATURE_LS_TIMESTAMPS(IF_FEATURE_LS_SORTFILES(":t-S:S-t")) /* time/size */ - // ":m-l:l-m" - we don't have -m - IF_FEATURE_LS_FOLLOWLINKS(":H-L:L-H") - ":C-xl:x-Cl:l-xC" /* bycols/bylines/long */ - ":C-1:1-C" /* bycols/oneline */ - ":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 + opt = getopt32long(argv, "^" + ls_options + "\0" + /* -n and -g imply -l */ + "nl:gl" + /* --full-time implies -l */ + IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l")) + /* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html: + * in some pairs of opts, only last one takes effect: + */ + IF_FEATURE_LS_TIMESTAMPS(IF_FEATURE_LS_SORTFILES(":t-S:S-t")) /* time/size */ + // ":m-l:l-m" - we don't have -m + IF_FEATURE_LS_FOLLOWLINKS(":H-L:L-H") + ":C-xl:x-Cl:l-xC" /* bycols/bylines/long */ + ":C-1:1-C" /* bycols/oneline */ + ":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+") + , ls_longopts IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width) IF_FEATURE_LS_COLOR(, &color_opt) ); diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index bcccdd64f..89d6cec0b 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c @@ -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) diff --git a/coreutils/mktemp.c b/coreutils/mktemp.c index 944eb0e06..d4ff883fa 100644 --- a/coreutils/mktemp.c +++ b/coreutils/mktemp.c @@ -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) { diff --git a/coreutils/mv.c b/coreutils/mv.c index 7f6e9fef5..10cbc506f 100644 --- a/coreutils/mv.c +++ b/coreutils/mv.c @@ -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" diff --git a/coreutils/readlink.c b/coreutils/readlink.c index 7f8d6b239..b8e327d11 100644 --- a/coreutils/readlink.c +++ b/coreutils/readlink.c @@ -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( diff --git a/coreutils/rm.c b/coreutils/rm.c index 5e4acab8c..b68a82dc4 100644 --- a/coreutils/rm.c +++ b/coreutils/rm.c @@ -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; diff --git a/coreutils/shuf.c b/coreutils/shuf.c index 403041534..d0caaa2ce 100644 --- a/coreutils/shuf.c +++ b/coreutils/shuf.c @@ -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; diff --git a/coreutils/sort.c b/coreutils/sort.c index 9860dca64..ceea24491 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -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; diff --git a/coreutils/split.c b/coreutils/split.c index d0c63573a..4e1db190c 100644 --- a/coreutils/split.c +++ b/coreutils/split.c @@ -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); diff --git a/coreutils/stat.c b/coreutils/stat.c index 4e926a908..dafbd4e9f 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c @@ -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 */ diff --git a/coreutils/sync.c b/coreutils/sync.c index 66445281a..9be47ab64 100644 --- a/coreutils/sync.c +++ b/coreutils/sync.c @@ -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. */ diff --git a/coreutils/tail.c b/coreutils/tail.c index fd310f422..7335ba11e 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c @@ -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 diff --git a/coreutils/tr.c b/coreutils/tr.c index 64e4efc91..c5872434a 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c @@ -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); diff --git a/coreutils/truncate.c b/coreutils/truncate.c index f67abaf40..f693570aa 100644 --- a/coreutils/truncate.c +++ b/coreutils/truncate.c @@ -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; diff --git a/coreutils/unlink.c b/coreutils/unlink.c index e32a9743c..56309b1c7 100644 --- a/coreutils/unlink.c +++ b/coreutils/unlink.c @@ -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; diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c index 4e72e86ee..5ef05ee4d 100644 --- a/coreutils/uudecode.c +++ b/coreutils/uudecode.c @@ -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]) diff --git a/coreutils/uuencode.c b/coreutils/uuencode.c index 7164f838a..d6e077430 100644 --- a/coreutils/uuencode.c +++ b/coreutils/uuencode.c @@ -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; diff --git a/coreutils/who.c b/coreutils/who.c index 6be3d692e..cfe0c921e 100644 --- a/coreutils/who.c +++ b/coreutils/who.c @@ -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"); |