aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-08 21:55:02 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-08 21:55:02 +0200
commit22542eca18e5807b72ddc78999f5101e33f17a53 (patch)
tree1271842a37c6215c998674a44bf7f561a0deff52 /coreutils
parent036585a911a5fe6c2cd77b808dd9150500f37272 (diff)
downloadbusybox-w32-22542eca18e5807b72ddc78999f5101e33f17a53.tar.gz
busybox-w32-22542eca18e5807b72ddc78999f5101e33f17a53.tar.bz2
busybox-w32-22542eca18e5807b72ddc78999f5101e33f17a53.zip
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.c8
-rw-r--r--coreutils/chmod.c3
-rw-r--r--coreutils/chown.c7
-rw-r--r--coreutils/comm.c3
-rw-r--r--coreutils/cp.c18
-rw-r--r--coreutils/cut.c9
-rw-r--r--coreutils/date.c14
-rw-r--r--coreutils/df.c15
-rw-r--r--coreutils/dos2unix.c3
-rw-r--r--coreutils/du.c14
-rw-r--r--coreutils/expand.c7
-rw-r--r--coreutils/id.c9
-rw-r--r--coreutils/install.c13
-rw-r--r--coreutils/link.c3
-rw-r--r--coreutils/ln.c3
-rw-r--r--coreutils/ls.c60
-rw-r--r--coreutils/md5_sha1_sum.c7
-rw-r--r--coreutils/mktemp.c3
-rw-r--r--coreutils/mv.c6
-rw-r--r--coreutils/readlink.c3
-rw-r--r--coreutils/rm.c3
-rw-r--r--coreutils/shuf.c7
-rw-r--r--coreutils/sort.c10
-rw-r--r--coreutils/split.c7
-rw-r--r--coreutils/stat.c8
-rw-r--r--coreutils/sync.c3
-rw-r--r--coreutils/tail.c8
-rw-r--r--coreutils/tr.c4
-rw-r--r--coreutils/truncate.c3
-rw-r--r--coreutils/unlink.c3
-rw-r--r--coreutils/uudecode.c6
-rw-r--r--coreutils/uuencode.c3
-rw-r--r--coreutils/who.c3
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)
170{ 170{
171 unsigned opts; 171 unsigned opts;
172 172
173 IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */) 173 opts = getopt32(argv, IF_FEATURE_CATV("^")
174 /* -u is ignored ("unbuffered") */ 174 /* -u is ignored ("unbuffered") */
175 opts = getopt32(argv, IF_FEATURE_CATV("etvA") IF_FEATURE_CATN("nb") "u"); 175 IF_FEATURE_CATV("etvA")IF_FEATURE_CATN("nb")"u"
176 IF_FEATURE_CATV("\0" "Aetv" /* -A == -vet */)
177 );
176 argv += optind; 178 argv += optind;
177 179
178 /* Read from stdin if there's nothing else to do. */ 180 /* 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)
123 } 123 }
124 124
125 /* Parse options */ 125 /* Parse options */
126 opt_complementary = "-2"; 126 getopt32(argv, "^" OPT_STR "\0" "-2");
127 getopt32(argv, ("-"OPT_STR) + 1); /* Reuse string */
128 argv += optind; 127 argv += optind;
129 128
130 /* Restore option-like mode if needed */ 129 /* 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 @@
55/* This is a NOEXEC applet. Be very careful! */ 55/* This is a NOEXEC applet. Be very careful! */
56 56
57 57
58#define OPT_STR ("Rh" IF_DESKTOP("vcfLHP")) 58#define OPT_STR "Rh" IF_DESKTOP("vcfLHP")
59#define BIT_RECURSE 1 59#define BIT_RECURSE 1
60#define OPT_RECURSE (opt & 1) 60#define OPT_RECURSE (opt & 1)
61#define OPT_NODEREF (opt & 2) 61#define OPT_NODEREF (opt & 2)
@@ -127,11 +127,10 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
127 int opt, flags; 127 int opt, flags;
128 struct param_t param; 128 struct param_t param;
129 129
130 opt_complementary = "-2";
131#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS 130#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
132 opt = getopt32long(argv, OPT_STR, chown_longopts); 131 opt = getopt32long(argv, "^" OPT_STR "\0" "=2", chown_longopts);
133#else 132#else
134 opt = getopt32(argv, OPT_STR); 133 opt = getopt32(argv, "^" OPT_STR "\0" "=2");
135#endif 134#endif
136 argv += optind; 135 argv += optind;
137 136
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)
62 int i; 62 int i;
63 int order; 63 int order;
64 64
65 opt_complementary = "=2"; 65 getopt32(argv, "^" "123" "\0" "=2");
66 getopt32(argv, "123");
67 argv += optind; 66 argv += optind;
68 67
69 for (i = 0; i < 2; ++i) { 68 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)
73#endif 73#endif
74 }; 74 };
75 75
76 // Need at least two arguments
77 // Soft- and hardlinking doesn't mix
78 // -P and -d are the same (-P is POSIX, -d is GNU)
79 // -r and -R are the same
80 // -R (and therefore -r) turns on -d (coreutils does this)
81 // -a = -pdR
82 opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR";
83#if ENABLE_FEATURE_CP_LONG_OPTIONS 76#if ENABLE_FEATURE_CP_LONG_OPTIONS
84 flags = getopt32long(argv, FILEUTILS_CP_OPTSTR, 77 flags = getopt32long(argv, "^"
78 FILEUTILS_CP_OPTSTR
79 "\0"
80 // Need at least two arguments
81 // Soft- and hardlinking doesn't mix
82 // -P and -d are the same (-P is POSIX, -d is GNU)
83 // -r and -R are the same
84 // -R (and therefore -r) turns on -d (coreutils does this)
85 // -a = -pdR
86 "-2:l--s:s--l:Pd:rRd:Rd:apdR",
85 "archive\0" No_argument "a" 87 "archive\0" No_argument "a"
86 "force\0" No_argument "f" 88 "force\0" No_argument "f"
87 "interactive\0" No_argument "i" 89 "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 @@
42 42
43 43
44/* option vars */ 44/* option vars */
45static const char optstring[] ALIGN1 = "b:c:f:d:sn"; 45#define OPT_STR "b:c:f:d:sn"
46#define CUT_OPT_BYTE_FLGS (1 << 0) 46#define CUT_OPT_BYTE_FLGS (1 << 0)
47#define CUT_OPT_CHAR_FLGS (1 << 1) 47#define CUT_OPT_CHAR_FLGS (1 << 1)
48#define CUT_OPT_FIELDS_FLGS (1 << 2) 48#define CUT_OPT_FIELDS_FLGS (1 << 2)
@@ -201,8 +201,11 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
201 char *sopt, *ltok; 201 char *sopt, *ltok;
202 unsigned opt; 202 unsigned opt;
203 203
204 opt_complementary = "b--bcf:c--bcf:f--bcf"; 204 opt = getopt32(argv, "^"
205 opt = getopt32(argv, optstring, &sopt, &sopt, &sopt, &ltok); 205 OPT_STR
206 "\0" "b--bcf:c--bcf:f--bcf",
207 &sopt, &sopt, &sopt, &ltok
208 );
206// argc -= optind; 209// argc -= optind;
207 argv += optind; 210 argv += optind;
208 if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) 211 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)
192 char *filename; 192 char *filename;
193 char *isofmt_arg = NULL; 193 char *isofmt_arg = NULL;
194 194
195 opt_complementary = "d--s:s--d" 195 opt = getopt32long(argv, "^"
196 IF_FEATURE_DATE_ISOFMT(":R--I:I--R"); 196 "Rs:ud:r:"
197 opt = getopt32long(argv, "Rs:ud:r:" 197 IF_FEATURE_DATE_ISOFMT("I::D:")
198 IF_FEATURE_DATE_ISOFMT("I::D:"), date_longopts, 198 "\0"
199 "d--s:s--d"
200 IF_FEATURE_DATE_ISOFMT(":R--I:I--R"),
201 date_longopts,
199 &date_str, &date_str, &filename 202 &date_str, &date_str, &filename
200 IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt)); 203 IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt)
204 );
201 argv += optind; 205 argv += optind;
202 maybe_set_utc(opt); 206 maybe_set_utc(opt);
203 207
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)
115 115
116 init_unicode(); 116 init_unicode();
117 117
118 opt = getopt32(argv, "^"
119 "kPT"
120 IF_FEATURE_DF_FANCY("aiB:")
121 IF_FEATURE_HUMAN_READABLE("hm")
122 "\0"
118#if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY 123#if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY
119 opt_complementary = "k-mB:m-Bk:B-km"; 124 "k-mB:m-Bk:B-km"
120#elif ENABLE_FEATURE_HUMAN_READABLE 125#elif ENABLE_FEATURE_HUMAN_READABLE
121 opt_complementary = "k-m:m-k"; 126 "k-m:m-k"
122#endif 127#endif
123 opt = getopt32(argv, "kPT" 128 IF_FEATURE_DF_FANCY(, &chp)
124 IF_FEATURE_DF_FANCY("aiB:") 129 );
125 IF_FEATURE_HUMAN_READABLE("hm")
126 IF_FEATURE_DF_FANCY(, &chp));
127 if (opt & OPT_MEGA) 130 if (opt & OPT_MEGA)
128 df_disp_hr = 1024*1024; 131 df_disp_hr = 1024*1024;
129 132
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)
120 } 120 }
121 121
122 /* -u convert to unix, -d convert to dos */ 122 /* -u convert to unix, -d convert to dos */
123 opt_complementary = "u--d:d--u"; /* mutually exclusive */ 123 o = getopt32(argv, "^" "du" "\0" "u--d:d--u"); /* mutually exclusive */
124 o = getopt32(argv, "du");
125 124
126 /* Do the conversion requested by an argument else do the default 125 /* Do the conversion requested by an argument else do the default
127 * conversion depending on our name. */ 126 * 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)
242 * ignore -a. This is consistent with -s being equivalent to -d 0. 242 * ignore -a. This is consistent with -s being equivalent to -d 0.
243 */ 243 */
244#if ENABLE_FEATURE_HUMAN_READABLE 244#if ENABLE_FEATURE_HUMAN_READABLE
245 opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; 245 opt = getopt32(argv, "^"
246 opt = getopt32(argv, "aHkLsx" "d:+" "lc" "hm", &G.max_print_depth); 246 "aHkLsxd:+lchm"
247 "\0" "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s",
248 &G.max_print_depth
249 );
247 argv += optind; 250 argv += optind;
248 if (opt & OPT_h_for_humans) { 251 if (opt & OPT_h_for_humans) {
249 G.disp_unit = 0; 252 G.disp_unit = 0;
@@ -255,8 +258,11 @@ int du_main(int argc UNUSED_PARAM, char **argv)
255 G.disp_unit = 1024; 258 G.disp_unit = 1024;
256 } 259 }
257#else 260#else
258 opt_complementary = "H-L:L-H:s-d:d-s"; 261 opt = getopt32(argv, "^"
259 opt = getopt32(argv, "aHkLsx" "d:+" "lc", &G.max_print_depth); 262 "aHkLsxd:+lc"
263 "\0" "H-L:L-H:s-d:d-s",
264 &G.max_print_depth
265 );
260 argv += optind; 266 argv += optind;
261#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K 267#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
262 if (opt & OPT_k_kbytes) { 268 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)
174 , &opt_t 174 , &opt_t
175 ); 175 );
176 } else { 176 } else {
177 /* -t NUM sets also -a */ 177 opt = getopt32long(argv, "^"
178 opt_complementary = "ta"; 178 "ft:a"
179 opt = getopt32long(argv, "ft:a", 179 "\0"
180 "ta" /* -t NUM sets -a */,
180 "first-only\0" No_argument "i" 181 "first-only\0" No_argument "i"
181 "tabs\0" Required_argument "t" 182 "tabs\0" Required_argument "t"
182 "all\0" No_argument "a" 183 "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)
170 } else { 170 } else {
171 /* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/ 171 /* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/
172 /* Don't allow more than one username */ 172 /* Don't allow more than one username */
173 opt_complementary = "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG" 173 opt = getopt32(argv, "^"
174 IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G"); 174 "rnugG" IF_SELINUX("Z")
175 opt = getopt32(argv, "rnugG" IF_SELINUX("Z")); 175 "\0"
176 "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG"
177 IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G")
178 );
176 } 179 }
177 180
178 username = argv[optind]; 181 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)
140#endif 140#endif
141 }; 141 };
142 142
143 opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
144 /* -c exists for backwards compatibility, it's needed */ 143 /* -c exists for backwards compatibility, it's needed */
145 /* -b is ignored ("make a backup of each existing destination file") */ 144 /* -b is ignored ("make a backup of each existing destination file") */
146 opts = GETOPT32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"), 145 opts = GETOPT32(argv, "^"
147 LONGOPTS 146 "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:")
148 &gid_str, &mode_str, &uid_str, &last 147 "\0"
149 IF_SELINUX(, &scontext) 148 "t--d:d--t:s--d:d--s"
149 IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")),
150 LONGOPTS
151 &gid_str, &mode_str, &uid_str, &last
152 IF_SELINUX(, &scontext)
150 ); 153 );
151 argc -= optind; 154 argc -= optind;
152 argv += optind; 155 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 @@
27int link_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 27int link_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
28int link_main(int argc UNUSED_PARAM, char **argv) 28int link_main(int argc UNUSED_PARAM, char **argv)
29{ 29{
30 opt_complementary = "=2"; /* exactly 2 params */ 30 getopt32(argv, "^" "" "\0" "=2");
31 getopt32(argv, "");
32 argv += optind; 31 argv += optind;
33 if (link(argv[0], argv[1]) != 0) { 32 if (link(argv[0], argv[1]) != 0) {
34 /* shared message */ 33 /* 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)
62 struct stat statbuf; 62 struct stat statbuf;
63 int (*link_func)(const char *, const char *); 63 int (*link_func)(const char *, const char *);
64 64
65 opt_complementary = "-1"; /* min one arg */ 65 opts = getopt32(argv, "^" "sfnbS:vT" "\0" "-1", &suffix);
66 opts = getopt32(argv, "sfnbS:vT", &suffix);
67 66
68 last = argv[argc - 1]; 67 last = argv[argc - 1];
69 argv += optind; 68 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,
206/* -SXvhTw GNU options, busybox optionally supports */ 206/* -SXvhTw GNU options, busybox optionally supports */
207/* -T WIDTH Ignored (we don't use tabs on output) */ 207/* -T WIDTH Ignored (we don't use tabs on output) */
208/* -Z SELinux mandated option, busybox optionally supports */ 208/* -Z SELinux mandated option, busybox optionally supports */
209static const char ls_options[] ALIGN1 = 209#define ls_options \
210 "Cadi1lgnsxAk" /* 12 opts, total 12 */ 210 "Cadi1lgnsxAk" /* 12 opts, total 12 */ \
211 IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */ 211 IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */ \
212 IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */ 212 IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */ \
213 IF_SELINUX("Z") /* 1, 16 */ 213 IF_SELINUX("Z") /* 1, 16 */ \
214 "Q" /* 1, 17 */ 214 "Q" /* 1, 17 */ \
215 IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */ 215 IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */ \
216 IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */ 216 IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */ \
217 IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */ 217 IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */ \
218 IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */ 218 IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */ \
219 IF_FEATURE_LS_WIDTH("T:w:") /* 2, 29 */ 219 IF_FEATURE_LS_WIDTH("T:w:") /* 2, 29 */
220; 220
221enum { 221enum {
222 OPT_C = (1 << 0), 222 OPT_C = (1 << 0),
223 OPT_a = (1 << 1), 223 OPT_a = (1 << 1),
@@ -1093,24 +1093,26 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1093#endif 1093#endif
1094 1094
1095 /* process options */ 1095 /* process options */
1096 opt_complementary = 1096 opt = getopt32long(argv, "^"
1097 /* -n and -g imply -l */ 1097 ls_options
1098 "nl:gl" 1098 "\0"
1099 /* --full-time implies -l */ 1099 /* -n and -g imply -l */
1100 IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l")) 1100 "nl:gl"
1101 /* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html: 1101 /* --full-time implies -l */
1102 * in some pairs of opts, only last one takes effect: 1102 IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l"))
1103 */ 1103 /* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html:
1104 IF_FEATURE_LS_TIMESTAMPS(IF_FEATURE_LS_SORTFILES(":t-S:S-t")) /* time/size */ 1104 * in some pairs of opts, only last one takes effect:
1105 // ":m-l:l-m" - we don't have -m 1105 */
1106 IF_FEATURE_LS_FOLLOWLINKS(":H-L:L-H") 1106 IF_FEATURE_LS_TIMESTAMPS(IF_FEATURE_LS_SORTFILES(":t-S:S-t")) /* time/size */
1107 ":C-xl:x-Cl:l-xC" /* bycols/bylines/long */ 1107 // ":m-l:l-m" - we don't have -m
1108 ":C-1:1-C" /* bycols/oneline */ 1108 IF_FEATURE_LS_FOLLOWLINKS(":H-L:L-H")
1109 ":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */ 1109 ":C-xl:x-Cl:l-xC" /* bycols/bylines/long */
1110 IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */ 1110 ":C-1:1-C" /* bycols/oneline */
1111 /* -w NUM: */ 1111 ":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */
1112 IF_FEATURE_LS_WIDTH(":w+"); 1112 IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */
1113 opt = getopt32long(argv, ls_options, ls_longopts 1113 /* -w NUM: */
1114 IF_FEATURE_LS_WIDTH(":w+")
1115 , ls_longopts
1114 IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width) 1116 IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width)
1115 IF_FEATURE_LS_COLOR(, &color_opt) 1117 IF_FEATURE_LS_COLOR(, &color_opt)
1116 ); 1118 );
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)
258#endif 258#endif
259 259
260 if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) { 260 if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) {
261 /* -s and -w require -c */
262 opt_complementary = "s?c:w?c";
263 /* -b "binary", -t "text" are ignored (shaNNNsum compat) */ 261 /* -b "binary", -t "text" are ignored (shaNNNsum compat) */
262 /* -s and -w require -c */
264#if ENABLE_SHA3SUM 263#if ENABLE_SHA3SUM
265 if (applet_name[3] == HASH_SHA3) 264 if (applet_name[3] == HASH_SHA3)
266 flags = getopt32(argv, "scwbta:+", &sha3_width); 265 flags = getopt32(argv, "^" "scwbta:+" "\0" "s?c:w?c", &sha3_width);
267 else 266 else
268#endif 267#endif
269 flags = getopt32(argv, "scwbt"); 268 flags = getopt32(argv, "^" "scwbt" "\0" "s?c:w?c");
270 } else { 269 } else {
271#if ENABLE_SHA3SUM 270#if ENABLE_SHA3SUM
272 if (applet_name[3] == HASH_SHA3) 271 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)
80 if (!path || path[0] == '\0') 80 if (!path || path[0] == '\0')
81 path = "/tmp"; 81 path = "/tmp";
82 82
83 opt_complementary = "?1"; /* 1 argument max */ 83 opts = getopt32(argv, "^" "dqtp:u" "\0" "?1"/*1 arg max*/, &path);
84 opts = getopt32(argv, "dqtp:u", &path);
85 84
86 chp = argv[optind]; 85 chp = argv[optind];
87 if (!chp) { 86 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)
55 * If more than one of -f, -i, -n is specified , only the final one 55 * If more than one of -f, -i, -n is specified , only the final one
56 * takes effect (it unsets previous options). 56 * takes effect (it unsets previous options).
57 */ 57 */
58 opt_complementary = "-2:f-in:i-fn:n-fi"; 58 flags = getopt32long(argv, "^"
59 flags = getopt32long(argv, "finv", 59 "finv"
60 "\0"
61 "-2:f-in:i-fn:n-fi",
60 "interactive\0" No_argument "i" 62 "interactive\0" No_argument "i"
61 "force\0" No_argument "f" 63 "force\0" No_argument "f"
62 "no-clobber\0" No_argument "n" 64 "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)
71 IF_FEATURE_READLINK_FOLLOW( 71 IF_FEATURE_READLINK_FOLLOW(
72 unsigned opt; 72 unsigned opt;
73 /* We need exactly one non-option argument. */ 73 /* We need exactly one non-option argument. */
74 opt_complementary = "=1"; 74 opt = getopt32(argv, "^" "fnvsq" "\0" "=1");
75 opt = getopt32(argv, "fnvsq");
76 fname = argv[optind]; 75 fname = argv[optind];
77 ) 76 )
78 IF_NOT_FEATURE_READLINK_FOLLOW( 77 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)
46 int flags = 0; 46 int flags = 0;
47 unsigned opt; 47 unsigned opt;
48 48
49 opt_complementary = "f-i:i-f"; 49 opt = getopt32(argv, "^" "fiRrv" "\0" "f-i:i-f");
50 opt = getopt32(argv, "fiRrv");
51 argv += optind; 50 argv += optind;
52 if (opt & 1) 51 if (opt & 1)
53 flags |= FILEUTILS_FORCE; 52 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)
70 unsigned numlines; 70 unsigned numlines;
71 char eol; 71 char eol;
72 72
73 opt_complementary = "e--i:i--e"; /* mutually exclusive */ 73 opts = getopt32(argv, "^"
74 opts = getopt32(argv, OPT_STR, &opt_i_str, &opt_n_str, &opt_o_str); 74 OPT_STR
75 "\0" "e--i:i--e"/* mutually exclusive */,
76 &opt_i_str, &opt_n_str, &opt_o_str
77 );
75 78
76 argc -= optind; 79 argc -= optind;
77 argv += optind; 80 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 @@
94*/ 94*/
95 95
96/* These are sort types */ 96/* These are sort types */
97static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:*t:"; 97#define OPT_STR "ngMucszbrdfimS:T:o:k:*t:"
98enum { 98enum {
99 FLAG_n = 1, /* Numeric sort */ 99 FLAG_n = 1, /* Numeric sort */
100 FLAG_g = 2, /* Sort using strtod() */ 100 FLAG_g = 2, /* Sort using strtod() */
@@ -378,9 +378,11 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
378 xfunc_error_retval = 2; 378 xfunc_error_retval = 2;
379 379
380 /* Parse command line options */ 380 /* Parse command line options */
381 /* -o and -t can be given at most once */ 381 opts = getopt32(argv, "^"
382 opt_complementary = "o--o:t--t"; /* -t, -o: at most one of each */ 382 OPT_STR
383 opts = getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t); 383 "\0" "o--o:t--t"/*-t, -o: at most one of each*/,
384 &str_ignored, &str_ignored, &str_o, &lst_k, &str_t
385 );
384 /* global b strips leading and trailing spaces */ 386 /* global b strips leading and trailing spaces */
385 if (opts & FLAG_b) 387 if (opts & FLAG_b)
386 option_mask32 |= FLAG_bb; 388 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)
100 100
101 setup_common_bufsiz(); 101 setup_common_bufsiz();
102 102
103 opt_complementary = "?2"; /* max 2 args; -a N */ 103 opt = getopt32(argv, "^"
104 opt = getopt32(argv, "l:b:a:+", &count_p, &count_p, &suffix_len); 104 "l:b:a:+" /* -a N */
105 "\0" "?2"/*max 2 args*/,
106 &count_p, &count_p, &suffix_len
107 );
105 108
106 if (opt & SPLIT_OPT_l) 109 if (opt & SPLIT_OPT_l)
107 cnt = XATOOFF(count_p); 110 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)
762 unsigned opts; 762 unsigned opts;
763 statfunc_ptr statfunc = do_stat; 763 statfunc_ptr statfunc = do_stat;
764 764
765 opt_complementary = "-1"; /* min one arg */ 765 opts = getopt32(argv, "^"
766 opts = getopt32(argv, "tL" 766 "tL"
767 IF_FEATURE_STAT_FILESYSTEM("f") 767 IF_FEATURE_STAT_FILESYSTEM("f")
768 IF_SELINUX("Z") 768 IF_SELINUX("Z")
769 IF_FEATURE_STAT_FORMAT("c:", &format) 769 IF_FEATURE_STAT_FORMAT("c:")
770 "\0" "-1" /* min one arg */
771 IF_FEATURE_STAT_FORMAT(,&format)
770 ); 772 );
771#if ENABLE_FEATURE_STAT_FILESYSTEM 773#if ENABLE_FEATURE_STAT_FILESYSTEM
772 if (opts & OPT_FILESYS) /* -f */ 774 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))
59 OPT_SYNCFS = (1 << 1), 59 OPT_SYNCFS = (1 << 1),
60 }; 60 };
61 61
62 opt_complementary = "d--f:f--d"; 62 opts = getopt32(argv, "^" "df" "\0" "d--f:f--d");
63 opts = getopt32(argv, "df");
64 argv += optind; 63 argv += optind;
65 64
66 /* Handle the no-argument case. */ 65 /* 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)
140#endif 140#endif
141 141
142 /* -s NUM, -F imlies -f */ 142 /* -s NUM, -F imlies -f */
143 IF_FEATURE_FANCY_TAIL(opt_complementary = "Ff";) 143 opt = getopt32(argv, IF_FEATURE_FANCY_TAIL("^")
144 opt = getopt32(argv, "fc:n:" IF_FEATURE_FANCY_TAIL("qs:+vF"), 144 "fc:n:"IF_FEATURE_FANCY_TAIL("qs:+vF")
145 &str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period)); 145 IF_FEATURE_FANCY_TAIL("\0" "Ff"),
146 &str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period)
147 );
146#define FOLLOW (opt & 0x1) 148#define FOLLOW (opt & 0x1)
147#define COUNT_BYTES (opt & 0x2) 149#define COUNT_BYTES (opt & 0x2)
148 //if (opt & 0x1) // -f 150 //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)
298 * In POSIX locale, these are the same. 298 * In POSIX locale, these are the same.
299 */ 299 */
300 300
301 opt_complementary = "-1"; 301 /* '+': stop at first non-option */
302 opts = getopt32(argv, "+Ccds"); /* '+': stop at first non-option */ 302 opts = getopt32(argv, "^+" "Ccds" "\0" "-1");
303 argv += optind; 303 argv += optind;
304 304
305 str1_length = expand(*argv++, &str1); 305 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)
50 OPT_SIZE = (1 << 1), 50 OPT_SIZE = (1 << 1),
51 }; 51 };
52 52
53 opt_complementary = "s:-1"; 53 opts = getopt32(argv, "^" "cs:" "\0" "s:-1", &size_str);
54 opts = getopt32(argv, "cs:", &size_str);
55 54
56 if (!(opts & OPT_NOCREATE)) 55 if (!(opts & OPT_NOCREATE))
57 flags |= O_CREAT; 56 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 @@
25int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 25int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
26int unlink_main(int argc UNUSED_PARAM, char **argv) 26int unlink_main(int argc UNUSED_PARAM, char **argv)
27{ 27{
28 opt_complementary = "=1"; /* must have exactly 1 param */ 28 getopt32(argv, "^" "" "\0" "=1");
29 getopt32(argv, "");
30 argv += optind; 29 argv += optind;
31 xunlink(argv[0]); 30 xunlink(argv[0]);
32 return 0; 31 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)
120 char *outname = NULL; 120 char *outname = NULL;
121 char *line; 121 char *line;
122 122
123 opt_complementary = "?1"; /* 1 argument max */ 123 getopt32(argv, "^" "o:" "\0" "?1"/* 1 arg max*/, &outname);
124 getopt32(argv, "o:", &outname);
125 argv += optind; 124 argv += optind;
126 125
127 if (!argv[0]) 126 if (!argv[0])
@@ -196,8 +195,7 @@ int base64_main(int argc UNUSED_PARAM, char **argv)
196 FILE *src_stream; 195 FILE *src_stream;
197 unsigned opts; 196 unsigned opts;
198 197
199 opt_complementary = "?1"; /* 1 argument max */ 198 opts = getopt32(argv, "^" "d" "\0" "?1"/* 1 arg max*/);
200 opts = getopt32(argv, "d");
201 argv += optind; 199 argv += optind;
202 200
203 if (!argv[0]) 201 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)
49 49
50 tbl = bb_uuenc_tbl_std; 50 tbl = bb_uuenc_tbl_std;
51 mode = 0666 & ~umask(0666); 51 mode = 0666 & ~umask(0666);
52 opt_complementary = "-1:?2"; /* must have 1 or 2 args */ 52 if (getopt32(argv, "^" "m" "\0" "-1:?2"/*must have 1 or 2 args*/)) {
53 if (getopt32(argv, "m")) {
54 tbl = bb_uuenc_tbl_base64; 53 tbl = bb_uuenc_tbl_base64;
55 } 54 }
56 argv += optind; 55 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)
117 unsigned opt; 117 unsigned opt;
118 const char *fmt = "%s"; 118 const char *fmt = "%s";
119 119
120 opt_complementary = "=0"; 120 opt = getopt32(argv, do_who ? "^" "aH" "\0" "=0": "^" "" "\0" "=0");
121 opt = getopt32(argv, do_who ? "aH" : "");
122 if ((opt & 2) || do_w) /* -H or we are w */ 121 if ((opt & 2) || do_w) /* -H or we are w */
123 puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST"); 122 puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST");
124 123