summaryrefslogtreecommitdiffhomepage
path: root/coreutils
diff options
context:
space:
mode:
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)
{
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, &ltok);
+ opt = getopt32(argv, "^"
+ OPT_STR
+ "\0" "b--bcf:c--bcf:f--bcf",
+ &sopt, &sopt, &sopt, &ltok
+ );
// 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");