diff options
58 files changed, 168 insertions, 159 deletions
diff --git a/archival/tar.c b/archival/tar.c index 7434e22e4..8e315c610 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -980,7 +980,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv) | |||
980 | /* Prepend '-' to the first argument if required */ | 980 | /* Prepend '-' to the first argument if required */ |
981 | opt_complementary = "--:" // first arg is options | 981 | opt_complementary = "--:" // first arg is options |
982 | "tt:vv:" // count -t,-v | 982 | "tt:vv:" // count -t,-v |
983 | IF_FEATURE_TAR_FROM("X::T::") // cumulative lists | ||
984 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM | 983 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM |
985 | "\xff::" // --exclude=PATTERN is a list | 984 | "\xff::" // --exclude=PATTERN is a list |
986 | #endif | 985 | #endif |
@@ -1032,13 +1031,13 @@ int tar_main(int argc UNUSED_PARAM, char **argv) | |||
1032 | #endif | 1031 | #endif |
1033 | opt = getopt32(argv, | 1032 | opt = getopt32(argv, |
1034 | "txC:f:Oopvk" | 1033 | "txC:f:Oopvk" |
1035 | IF_FEATURE_TAR_CREATE( "ch" ) | 1034 | IF_FEATURE_TAR_CREATE( "ch" ) |
1036 | IF_FEATURE_SEAMLESS_BZ2( "j" ) | 1035 | IF_FEATURE_SEAMLESS_BZ2( "j" ) |
1037 | IF_FEATURE_SEAMLESS_LZMA("a" ) | 1036 | IF_FEATURE_SEAMLESS_LZMA("a" ) |
1038 | IF_FEATURE_TAR_FROM( "T:X:") | 1037 | IF_FEATURE_TAR_FROM( "T:*X:*") |
1039 | IF_FEATURE_SEAMLESS_GZ( "z" ) | 1038 | IF_FEATURE_SEAMLESS_GZ( "z" ) |
1040 | IF_FEATURE_SEAMLESS_XZ( "J" ) | 1039 | IF_FEATURE_SEAMLESS_XZ( "J" ) |
1041 | IF_FEATURE_SEAMLESS_Z( "Z" ) | 1040 | IF_FEATURE_SEAMLESS_Z( "Z" ) |
1042 | IF_FEATURE_TAR_NOPRESERVE_TIME("m") | 1041 | IF_FEATURE_TAR_NOPRESERVE_TIME("m") |
1043 | IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components | 1042 | IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components |
1044 | , &base_dir // -C dir | 1043 | , &base_dir // -C dir |
diff --git a/coreutils/du.c b/coreutils/du.c index 1240bcbbc..5f104736b 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -226,8 +226,8 @@ int du_main(int argc UNUSED_PARAM, char **argv) | |||
226 | * ignore -a. This is consistent with -s being equivalent to -d 0. | 226 | * ignore -a. This is consistent with -s being equivalent to -d 0. |
227 | */ | 227 | */ |
228 | #if ENABLE_FEATURE_HUMAN_READABLE | 228 | #if ENABLE_FEATURE_HUMAN_READABLE |
229 | opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s:d+"; | 229 | opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; |
230 | opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth); | 230 | opt = getopt32(argv, "aHkLsx" "d:+" "lc" "hm", &G.max_print_depth); |
231 | argv += optind; | 231 | argv += optind; |
232 | if (opt & OPT_h_for_humans) { | 232 | if (opt & OPT_h_for_humans) { |
233 | G.disp_unit = 0; | 233 | G.disp_unit = 0; |
@@ -239,8 +239,8 @@ int du_main(int argc UNUSED_PARAM, char **argv) | |||
239 | G.disp_unit = 1024; | 239 | G.disp_unit = 1024; |
240 | } | 240 | } |
241 | #else | 241 | #else |
242 | opt_complementary = "H-L:L-H:s-d:d-s:d+"; | 242 | opt_complementary = "H-L:L-H:s-d:d-s"; |
243 | opt = getopt32(argv, "aHkLsx" "d:" "lc", &G.max_print_depth); | 243 | opt = getopt32(argv, "aHkLsx" "d:+" "lc", &G.max_print_depth); |
244 | argv += optind; | 244 | argv += optind; |
245 | #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K | 245 | #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K |
246 | if (opt & OPT_k_kbytes) { | 246 | if (opt & OPT_k_kbytes) { |
diff --git a/coreutils/env.c b/coreutils/env.c index 807ef13e9..cdfc30e14 100644 --- a/coreutils/env.c +++ b/coreutils/env.c | |||
@@ -54,11 +54,10 @@ int env_main(int argc UNUSED_PARAM, char **argv) | |||
54 | unsigned opts; | 54 | unsigned opts; |
55 | llist_t *unset_env = NULL; | 55 | llist_t *unset_env = NULL; |
56 | 56 | ||
57 | opt_complementary = "u::"; | ||
58 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS | 57 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS |
59 | applet_long_options = env_longopts; | 58 | applet_long_options = env_longopts; |
60 | #endif | 59 | #endif |
61 | opts = getopt32(argv, "+iu:", &unset_env); | 60 | opts = getopt32(argv, "+iu:+", &unset_env); |
62 | argv += optind; | 61 | argv += optind; |
63 | if (argv[0] && LONE_DASH(argv[0])) { | 62 | if (argv[0] && LONE_DASH(argv[0])) { |
64 | opts |= 1; | 63 | opts |= 1; |
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index c8a654165..f13bdfc11 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c | |||
@@ -62,7 +62,7 @@ enum { | |||
62 | }; | 62 | }; |
63 | 63 | ||
64 | #define OD_GETOPT32() getopt32(argv, \ | 64 | #define OD_GETOPT32() getopt32(argv, \ |
65 | "A:N:abcdfhij:lot:vxsS:w::", \ | 65 | "A:N:abcdfhij:lot:*vxsS:w:+:", \ |
66 | /* -w with optional param */ \ | 66 | /* -w with optional param */ \ |
67 | /* -S was -s and also had optional parameter */ \ | 67 | /* -S was -s and also had optional parameter */ \ |
68 | /* but in coreutils 6.3 it was renamed and now has */ \ | 68 | /* but in coreutils 6.3 it was renamed and now has */ \ |
@@ -1212,7 +1212,6 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
1212 | address_pad_len_char = '7'; | 1212 | address_pad_len_char = '7'; |
1213 | 1213 | ||
1214 | /* Parse command line */ | 1214 | /* Parse command line */ |
1215 | opt_complementary = "w+:t::"; /* -w N, -t is a list */ | ||
1216 | #if ENABLE_LONG_OPTS | 1215 | #if ENABLE_LONG_OPTS |
1217 | applet_long_options = od_longopts; | 1216 | applet_long_options = od_longopts; |
1218 | #endif | 1217 | #endif |
diff --git a/coreutils/sort.c b/coreutils/sort.c index 9139d9f47..34a41999b 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -73,7 +73,7 @@ | |||
73 | */ | 73 | */ |
74 | 74 | ||
75 | /* These are sort types */ | 75 | /* These are sort types */ |
76 | static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:t:"; | 76 | static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:*t:"; |
77 | enum { | 77 | enum { |
78 | FLAG_n = 1, /* Numeric sort */ | 78 | FLAG_n = 1, /* Numeric sort */ |
79 | FLAG_g = 2, /* Sort using strtod() */ | 79 | FLAG_g = 2, /* Sort using strtod() */ |
@@ -358,8 +358,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv) | |||
358 | 358 | ||
359 | /* Parse command line options */ | 359 | /* Parse command line options */ |
360 | /* -o and -t can be given at most once */ | 360 | /* -o and -t can be given at most once */ |
361 | opt_complementary = "o--o:t--t:" /* -t, -o: at most one of each */ | 361 | opt_complementary = "o--o:t--t"; /* -t, -o: at most one of each */ |
362 | "k::"; /* -k takes list */ | ||
363 | opts = getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t); | 362 | opts = getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t); |
364 | /* global b strips leading and trailing spaces */ | 363 | /* global b strips leading and trailing spaces */ |
365 | if (opts & FLAG_b) | 364 | if (opts & FLAG_b) |
diff --git a/coreutils/split.c b/coreutils/split.c index e67c3de66..19d58a21b 100644 --- a/coreutils/split.c +++ b/coreutils/split.c | |||
@@ -81,8 +81,8 @@ int split_main(int argc UNUSED_PARAM, char **argv) | |||
81 | 81 | ||
82 | setup_common_bufsiz(); | 82 | setup_common_bufsiz(); |
83 | 83 | ||
84 | opt_complementary = "?2:a+"; /* max 2 args; -a N */ | 84 | opt_complementary = "?2"; /* max 2 args; -a N */ |
85 | opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len); | 85 | opt = getopt32(argv, "l:b:a:+", &count_p, &count_p, &suffix_len); |
86 | 86 | ||
87 | if (opt & SPLIT_OPT_l) | 87 | if (opt & SPLIT_OPT_l) |
88 | cnt = XATOOFF(count_p); | 88 | cnt = XATOOFF(count_p); |
diff --git a/coreutils/tail.c b/coreutils/tail.c index 39f87679e..57ad0f3b7 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -121,8 +121,8 @@ int tail_main(int argc, char **argv) | |||
121 | #endif | 121 | #endif |
122 | 122 | ||
123 | /* -s NUM, -F imlies -f */ | 123 | /* -s NUM, -F imlies -f */ |
124 | IF_FEATURE_FANCY_TAIL(opt_complementary = "s+:Ff";) | 124 | IF_FEATURE_FANCY_TAIL(opt_complementary = "Ff";) |
125 | opt = getopt32(argv, "fc:n:" IF_FEATURE_FANCY_TAIL("qs:vF"), | 125 | opt = getopt32(argv, "fc:n:" IF_FEATURE_FANCY_TAIL("qs:+vF"), |
126 | &str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period)); | 126 | &str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period)); |
127 | #define FOLLOW (opt & 0x1) | 127 | #define FOLLOW (opt & 0x1) |
128 | #define COUNT_BYTES (opt & 0x2) | 128 | #define COUNT_BYTES (opt & 0x2) |
diff --git a/coreutils/uniq.c b/coreutils/uniq.c index e0133998a..ec7bde418 100644 --- a/coreutils/uniq.c +++ b/coreutils/uniq.c | |||
@@ -50,8 +50,7 @@ int uniq_main(int argc UNUSED_PARAM, char **argv) | |||
50 | skip_fields = skip_chars = 0; | 50 | skip_fields = skip_chars = 0; |
51 | max_chars = INT_MAX; | 51 | max_chars = INT_MAX; |
52 | 52 | ||
53 | opt_complementary = "f+:s+:w+"; | 53 | opt = getopt32(argv, "cduf:+s:+w:+", &skip_fields, &skip_chars, &max_chars); |
54 | opt = getopt32(argv, "cduf:s:w:", &skip_fields, &skip_chars, &max_chars); | ||
55 | argv += optind; | 54 | argv += optind; |
56 | 55 | ||
57 | input_filename = argv[0]; | 56 | input_filename = argv[0]; |
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index c671b9252..0bb666abc 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c | |||
@@ -181,8 +181,8 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv) | |||
181 | applet_long_options = runparts_longopts; | 181 | applet_long_options = runparts_longopts; |
182 | #endif | 182 | #endif |
183 | /* We require exactly one argument: the directory name */ | 183 | /* We require exactly one argument: the directory name */ |
184 | opt_complementary = "=1:a::"; | 184 | opt_complementary = "=1"; |
185 | getopt32(argv, "a:u:", &arg_list, &umask_p); | 185 | getopt32(argv, "a:*u:", &arg_list, &umask_p); |
186 | 186 | ||
187 | umask(xstrtou_range(umask_p, 8, 0, 07777)); | 187 | umask(xstrtou_range(umask_p, 8, 0, 07777)); |
188 | 188 | ||
diff --git a/editors/awk.c b/editors/awk.c index 69816464d..d0269b9f4 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -72,12 +72,9 @@ | |||
72 | 72 | ||
73 | 73 | ||
74 | #define OPTSTR_AWK \ | 74 | #define OPTSTR_AWK \ |
75 | "F:v:f:" \ | 75 | "F:v:*f:*" \ |
76 | IF_FEATURE_AWK_GNU_EXTENSIONS("e:") \ | 76 | IF_FEATURE_AWK_GNU_EXTENSIONS("e:*") \ |
77 | "W:" | 77 | "W:" |
78 | #define OPTCOMPLSTR_AWK \ | ||
79 | "v::f::" \ | ||
80 | IF_FEATURE_AWK_GNU_EXTENSIONS("e::") | ||
81 | enum { | 78 | enum { |
82 | OPTBIT_F, /* define field separator */ | 79 | OPTBIT_F, /* define field separator */ |
83 | OPTBIT_v, /* define variable */ | 80 | OPTBIT_v, /* define variable */ |
@@ -3209,7 +3206,6 @@ int awk_main(int argc, char **argv) | |||
3209 | *s1 = '='; | 3206 | *s1 = '='; |
3210 | } | 3207 | } |
3211 | } | 3208 | } |
3212 | opt_complementary = OPTCOMPLSTR_AWK; | ||
3213 | opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL); | 3209 | opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL); |
3214 | argv += optind; | 3210 | argv += optind; |
3215 | argc -= optind; | 3211 | argc -= optind; |
diff --git a/editors/diff.c b/editors/diff.c index ff269360f..75229ad8c 100644 --- a/editors/diff.c +++ b/editors/diff.c | |||
@@ -982,11 +982,11 @@ int diff_main(int argc UNUSED_PARAM, char **argv) | |||
982 | INIT_G(); | 982 | INIT_G(); |
983 | 983 | ||
984 | /* exactly 2 params; collect multiple -L <label>; -U N */ | 984 | /* exactly 2 params; collect multiple -L <label>; -U N */ |
985 | opt_complementary = "=2:L::U+"; | 985 | opt_complementary = "=2"; |
986 | #if ENABLE_FEATURE_DIFF_LONG_OPTIONS | 986 | #if ENABLE_FEATURE_DIFF_LONG_OPTIONS |
987 | applet_long_options = diff_longopts; | 987 | applet_long_options = diff_longopts; |
988 | #endif | 988 | #endif |
989 | getopt32(argv, "abdiL:NqrsS:tTU:wupBE", | 989 | getopt32(argv, "abdiL:*NqrsS:tTU:+wupBE", |
990 | &L_arg, &s_start, &opt_U_context); | 990 | &L_arg, &s_start, &opt_U_context); |
991 | argv += optind; | 991 | argv += optind; |
992 | while (L_arg) | 992 | while (L_arg) |
diff --git a/editors/sed.c b/editors/sed.c index f37c37d88..c0d79cc7b 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -1503,8 +1503,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1503 | /* do normal option parsing */ | 1503 | /* do normal option parsing */ |
1504 | opt_e = opt_f = NULL; | 1504 | opt_e = opt_f = NULL; |
1505 | opt_i = NULL; | 1505 | opt_i = NULL; |
1506 | opt_complementary = "e::f::" /* can occur multiple times */ | 1506 | opt_complementary = "nn"; /* count -n */ |
1507 | "nn"; /* count -n */ | ||
1508 | 1507 | ||
1509 | IF_LONG_OPTS(applet_long_options = sed_longopts); | 1508 | IF_LONG_OPTS(applet_long_options = sed_longopts); |
1510 | 1509 | ||
@@ -1513,7 +1512,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1513 | * GNU sed 4.2.1 mentions it in neither --help | 1512 | * GNU sed 4.2.1 mentions it in neither --help |
1514 | * nor manpage, but does recognize it. | 1513 | * nor manpage, but does recognize it. |
1515 | */ | 1514 | */ |
1516 | opt = getopt32(argv, "i::rEne:f:", &opt_i, &opt_e, &opt_f, | 1515 | opt = getopt32(argv, "i::rEne:*f:*", &opt_i, &opt_e, &opt_f, |
1517 | &G.be_quiet); /* counter for -n */ | 1516 | &G.be_quiet); /* counter for -n */ |
1518 | //argc -= optind; | 1517 | //argc -= optind; |
1519 | argv += optind; | 1518 | argv += optind; |
diff --git a/findutils/grep.c b/findutils/grep.c index aeb7977e9..7e0120ba2 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -115,8 +115,8 @@ | |||
115 | //usage:#define fgrep_full_usage "" | 115 | //usage:#define fgrep_full_usage "" |
116 | 116 | ||
117 | #define OPTSTR_GREP \ | 117 | #define OPTSTR_GREP \ |
118 | "lnqvscFiHhe:f:Lorm:wx" \ | 118 | "lnqvscFiHhe:*f:*Lorm:+wx" \ |
119 | IF_FEATURE_GREP_CONTEXT("A:B:C:") \ | 119 | IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \ |
120 | IF_FEATURE_GREP_EGREP_ALIAS("E") \ | 120 | IF_FEATURE_GREP_EGREP_ALIAS("E") \ |
121 | IF_EXTRA_COMPAT("z") \ | 121 | IF_EXTRA_COMPAT("z") \ |
122 | "aI" | 122 | "aI" |
@@ -695,7 +695,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv) | |||
695 | #if ENABLE_FEATURE_GREP_CONTEXT | 695 | #if ENABLE_FEATURE_GREP_CONTEXT |
696 | /* -H unsets -h; -C unsets -A,-B; -e,-f are lists; | 696 | /* -H unsets -h; -C unsets -A,-B; -e,-f are lists; |
697 | * -m,-A,-B,-C have numeric param */ | 697 | * -m,-A,-B,-C have numeric param */ |
698 | opt_complementary = "H-h:C-AB:e::f::m+:A+:B+:C+"; | 698 | opt_complementary = "H-h:C-AB"; |
699 | opts = getopt32(argv, | 699 | opts = getopt32(argv, |
700 | OPTSTR_GREP, | 700 | OPTSTR_GREP, |
701 | &pattern_head, &fopt, &max_matches, | 701 | &pattern_head, &fopt, &max_matches, |
@@ -724,7 +724,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv) | |||
724 | #else | 724 | #else |
725 | /* with auto sanity checks */ | 725 | /* with auto sanity checks */ |
726 | /* -H unsets -h; -c,-q or -l unset -n; -e,-f are lists; -m N */ | 726 | /* -H unsets -h; -c,-q or -l unset -n; -e,-f are lists; -m N */ |
727 | opt_complementary = "H-h:c-n:q-n:l-n:e::f::m+"; | 727 | opt_complementary = "H-h:c-n:q-n:l-n:"; |
728 | getopt32(argv, OPTSTR_GREP, | 728 | getopt32(argv, OPTSTR_GREP, |
729 | &pattern_head, &fopt, &max_matches); | 729 | &pattern_head, &fopt, &max_matches); |
730 | #endif | 730 | #endif |
diff --git a/init/halt.c b/init/halt.c index 572d751b0..29e60657b 100644 --- a/init/halt.c +++ b/init/halt.c | |||
@@ -113,12 +113,11 @@ int halt_main(int argc UNUSED_PARAM, char **argv) | |||
113 | continue; | 113 | continue; |
114 | 114 | ||
115 | /* Parse and handle arguments */ | 115 | /* Parse and handle arguments */ |
116 | opt_complementary = "d+"; /* -d N */ | ||
117 | /* We support -w even if !ENABLE_FEATURE_WTMP, | 116 | /* We support -w even if !ENABLE_FEATURE_WTMP, |
118 | * in order to not break scripts. | 117 | * in order to not break scripts. |
119 | * -i (shut down network interfaces) is ignored. | 118 | * -i (shut down network interfaces) is ignored. |
120 | */ | 119 | */ |
121 | flags = getopt32(argv, "d:nfwi", &delay); | 120 | flags = getopt32(argv, "d:+nfwi", &delay); |
122 | 121 | ||
123 | sleep(delay); | 122 | sleep(delay); |
124 | 123 | ||
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index d0e83d88e..15b6efc09 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c | |||
@@ -17,23 +17,20 @@ | |||
17 | uint32_t | 17 | uint32_t |
18 | getopt32(char **argv, const char *applet_opts, ...) | 18 | getopt32(char **argv, const char *applet_opts, ...) |
19 | 19 | ||
20 | The command line options must be declared in const char | 20 | The command line options are passed as the applet_opts string. |
21 | *applet_opts as a string of chars, for example: | ||
22 | |||
23 | flags = getopt32(argv, "rnug"); | ||
24 | 21 | ||
25 | If one of the given options is found, a flag value is added to | 22 | If one of the given options is found, a flag value is added to |
26 | the return value (an unsigned long). | 23 | the return value. |
27 | 24 | ||
28 | The flag value is determined by the position of the char in | 25 | The flag value is determined by the position of the char in |
29 | applet_opts string. For example, in the above case: | 26 | applet_opts string. For example: |
30 | 27 | ||
31 | flags = getopt32(argv, "rnug"); | 28 | flags = getopt32(argv, "rnug"); |
32 | 29 | ||
33 | "r" will add 1 (bit 0) | 30 | "r" will set 1 (bit 0) |
34 | "n" will add 2 (bit 1) | 31 | "n" will set 2 (bit 1) |
35 | "u" will add 4 (bit 2) | 32 | "u" will set 4 (bit 2) |
36 | "g" will add 8 (bit 3) | 33 | "g" will set 8 (bit 3) |
37 | 34 | ||
38 | and so on. You can also look at the return value as a bit | 35 | and so on. You can also look at the return value as a bit |
39 | field and each option sets one bit. | 36 | field and each option sets one bit. |
@@ -45,7 +42,7 @@ getopt32(char **argv, const char *applet_opts, ...) | |||
45 | (options and their parameters will be moved into argv[] | 42 | (options and their parameters will be moved into argv[] |
46 | positions prior to argv[optind]). | 43 | positions prior to argv[optind]). |
47 | 44 | ||
48 | ":" If one of the options requires an argument, then add a ":" | 45 | "o:" If one of the options requires an argument, then add a ":" |
49 | after the char in applet_opts and provide a pointer to store | 46 | after the char in applet_opts and provide a pointer to store |
50 | the argument. For example: | 47 | the argument. For example: |
51 | 48 | ||
@@ -58,15 +55,39 @@ getopt32(char **argv, const char *applet_opts, ...) | |||
58 | &pointer_to_arg_for_a, &pointer_to_arg_for_b, | 55 | &pointer_to_arg_for_a, &pointer_to_arg_for_b, |
59 | &pointer_to_arg_for_c, &pointer_to_arg_for_d); | 56 | &pointer_to_arg_for_c, &pointer_to_arg_for_d); |
60 | 57 | ||
61 | The type of the pointer (char* or llist_t*) may be controlled | 58 | The type of the pointer may be controlled by "o::" or "o+" in |
62 | by the "::" special separator that is set in the external string | 59 | the external string opt_complementary (see below for more info). |
63 | opt_complementary (see below for more info). | ||
64 | 60 | ||
65 | "::" If option can have an *optional* argument, then add a "::" | 61 | "o::" If option can have an *optional* argument, then add a "::" |
66 | after its char in applet_opts and provide a pointer to store | 62 | after its char in applet_opts and provide a pointer to store |
67 | the argument. Note that optional arguments _must_ | 63 | the argument. Note that optional arguments _must_ |
68 | immediately follow the option: -oparam, not -o param. | 64 | immediately follow the option: -oparam, not -o param. |
69 | 65 | ||
66 | "o:+" This means that the parameter for this option is a nonnegative integer. | ||
67 | It will be processed with xatoi_positive() - allowed range | ||
68 | is 0..INT_MAX. | ||
69 | |||
70 | int param; // "unsigned param;" will also work | ||
71 | getopt32(argv, "p:+", ¶m); | ||
72 | |||
73 | "o:*" This means that the option can occur multiple times. Each occurrence | ||
74 | will be saved as a llist_t element instead of char*. | ||
75 | |||
76 | For example: | ||
77 | The grep applet can have one or more "-e pattern" arguments. | ||
78 | In this case you should use getopt32() as follows: | ||
79 | |||
80 | llist_t *patterns = NULL; | ||
81 | |||
82 | (this pointer must be initializated to NULL if the list is empty | ||
83 | as required by llist_add_to_end(llist_t **old_head, char *new_item).) | ||
84 | |||
85 | getopt32(argv, "e:*", &patterns); | ||
86 | |||
87 | $ grep -e user -e root /etc/passwd | ||
88 | root:x:0:0:root:/root:/bin/bash | ||
89 | user:x:500:500::/home/user:/bin/bash | ||
90 | |||
70 | "+" If the first character in the applet_opts string is a plus, | 91 | "+" If the first character in the applet_opts string is a plus, |
71 | then option processing will stop as soon as a non-option is | 92 | then option processing will stop as soon as a non-option is |
72 | encountered in the argv array. Useful for applets like env | 93 | encountered in the argv array. Useful for applets like env |
@@ -82,7 +103,7 @@ const char *applet_long_options | |||
82 | This struct allows you to define long options: | 103 | This struct allows you to define long options: |
83 | 104 | ||
84 | static const char applet_longopts[] ALIGN1 = | 105 | static const char applet_longopts[] ALIGN1 = |
85 | //"name\0" has_arg val | 106 | //"name\0" has_arg val |
86 | "verbose\0" No_argument "v" | 107 | "verbose\0" No_argument "v" |
87 | ; | 108 | ; |
88 | applet_long_options = applet_longopts; | 109 | applet_long_options = applet_longopts; |
@@ -90,7 +111,7 @@ const char *applet_long_options | |||
90 | The last member of struct option (val) typically is set to | 111 | The last member of struct option (val) typically is set to |
91 | matching short option from applet_opts. If there is no matching | 112 | matching short option from applet_opts. If there is no matching |
92 | char in applet_opts, then: | 113 | char in applet_opts, then: |
93 | - return bit have next position after short options | 114 | - return bit has next position after short options |
94 | - if has_arg is not "No_argument", use ptr for arg also | 115 | - if has_arg is not "No_argument", use ptr for arg also |
95 | - opt_complementary affects it too | 116 | - opt_complementary affects it too |
96 | 117 | ||
@@ -139,8 +160,8 @@ const char *opt_complementary | |||
139 | 160 | ||
140 | llist_t *my_b = NULL; | 161 | llist_t *my_b = NULL; |
141 | int verbose_level = 0; | 162 | int verbose_level = 0; |
142 | opt_complementary = "vv:b::b-c:c-b"; | 163 | opt_complementary = "vv:b-c:c-b"; |
143 | f = getopt32(argv, "vb:c", &my_b, &verbose_level); | 164 | f = getopt32(argv, "vb:*c", &my_b, &verbose_level); |
144 | if (f & 2) // -c after -b unsets -b flag | 165 | if (f & 2) // -c after -b unsets -b flag |
145 | while (my_b) dosomething_with(llist_pop(&my_b)); | 166 | while (my_b) dosomething_with(llist_pop(&my_b)); |
146 | if (my_b) // but llist is stored if -b is specified | 167 | if (my_b) // but llist is stored if -b is specified |
@@ -233,7 +254,7 @@ Special characters: | |||
233 | "x--x" Variation of the above, it means that -x option should occur | 254 | "x--x" Variation of the above, it means that -x option should occur |
234 | at most once. | 255 | at most once. |
235 | 256 | ||
236 | "a+" A plus after a char in opt_complementary means that the parameter | 257 | "o+" A plus after a char in opt_complementary means that the parameter |
237 | for this option is a nonnegative integer. It will be processed | 258 | for this option is a nonnegative integer. It will be processed |
238 | with xatoi_positive() - allowed range is 0..INT_MAX. | 259 | with xatoi_positive() - allowed range is 0..INT_MAX. |
239 | 260 | ||
@@ -241,7 +262,7 @@ Special characters: | |||
241 | opt_complementary = "p+"; | 262 | opt_complementary = "p+"; |
242 | getopt32(argv, "p:", ¶m); | 263 | getopt32(argv, "p:", ¶m); |
243 | 264 | ||
244 | "a::" A double colon after a char in opt_complementary means that the | 265 | "o::" A double colon after a char in opt_complementary means that the |
245 | option can occur multiple times. Each occurrence will be saved as | 266 | option can occur multiple times. Each occurrence will be saved as |
246 | a llist_t element instead of char*. | 267 | a llist_t element instead of char*. |
247 | 268 | ||
@@ -255,12 +276,17 @@ Special characters: | |||
255 | as required by llist_add_to_end(llist_t **old_head, char *new_item).) | 276 | as required by llist_add_to_end(llist_t **old_head, char *new_item).) |
256 | 277 | ||
257 | opt_complementary = "e::"; | 278 | opt_complementary = "e::"; |
258 | |||
259 | getopt32(argv, "e:", &patterns); | 279 | getopt32(argv, "e:", &patterns); |
280 | |||
260 | $ grep -e user -e root /etc/passwd | 281 | $ grep -e user -e root /etc/passwd |
261 | root:x:0:0:root:/root:/bin/bash | 282 | root:x:0:0:root:/root:/bin/bash |
262 | user:x:500:500::/home/user:/bin/bash | 283 | user:x:500:500::/home/user:/bin/bash |
263 | 284 | ||
285 | "o+" and "o::" can be handled by "o:+" and "o:*" specifiers | ||
286 | in option string (and it is preferred), but this does not work | ||
287 | for "long options only" cases, such as tar --exclude=PATTERN, | ||
288 | wget --header=HDR cases. | ||
289 | |||
264 | "a?b" A "?" between an option and a group of options means that | 290 | "a?b" A "?" between an option and a group of options means that |
265 | at least one of them is required to occur if the first option | 291 | at least one of them is required to occur if the first option |
266 | occurs in preceding command line arguments. | 292 | occurs in preceding command line arguments. |
@@ -359,10 +385,11 @@ getopt32(char **argv, const char *applet_opts, ...) | |||
359 | 385 | ||
360 | va_start(p, applet_opts); | 386 | va_start(p, applet_opts); |
361 | 387 | ||
362 | c = 0; | ||
363 | on_off = complementary; | 388 | on_off = complementary; |
364 | memset(on_off, 0, sizeof(complementary)); | 389 | memset(on_off, 0, sizeof(complementary)); |
365 | 390 | ||
391 | applet_opts = strcpy(alloca(strlen(applet_opts) + 1), applet_opts); | ||
392 | |||
366 | /* skip bbox extension */ | 393 | /* skip bbox extension */ |
367 | first_char = applet_opts[0]; | 394 | first_char = applet_opts[0]; |
368 | if (first_char == '!') | 395 | if (first_char == '!') |
@@ -372,6 +399,7 @@ getopt32(char **argv, const char *applet_opts, ...) | |||
372 | s = (const unsigned char *)applet_opts; | 399 | s = (const unsigned char *)applet_opts; |
373 | if (*s == '+' || *s == '-') | 400 | if (*s == '+' || *s == '-') |
374 | s++; | 401 | s++; |
402 | c = 0; | ||
375 | while (*s) { | 403 | while (*s) { |
376 | if (c >= 32) | 404 | if (c >= 32) |
377 | break; | 405 | break; |
@@ -379,6 +407,13 @@ getopt32(char **argv, const char *applet_opts, ...) | |||
379 | on_off->switch_on = (1 << c); | 407 | on_off->switch_on = (1 << c); |
380 | if (*++s == ':') { | 408 | if (*++s == ':') { |
381 | on_off->optarg = va_arg(p, void **); | 409 | on_off->optarg = va_arg(p, void **); |
410 | if (s[1] == '+' || s[1] == '*') { | ||
411 | /* 'o:+' or 'o:*' */ | ||
412 | on_off->param_type = (s[1] == '+') ? | ||
413 | PARAM_INT : PARAM_LIST; | ||
414 | overlapping_strcpy((char*)s + 1, (char*)s + 2); | ||
415 | } | ||
416 | /* skip possible 'o::' (or 'o:+:' !) */ | ||
382 | while (*++s == ':') | 417 | while (*++s == ':') |
383 | continue; | 418 | continue; |
384 | } | 419 | } |
@@ -431,6 +466,7 @@ getopt32(char **argv, const char *applet_opts, ...) | |||
431 | applet_long_options = NULL; | 466 | applet_long_options = NULL; |
432 | } | 467 | } |
433 | #endif /* ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG */ | 468 | #endif /* ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG */ |
469 | |||
434 | for (s = (const unsigned char *)opt_complementary; s && *s; s++) { | 470 | for (s = (const unsigned char *)opt_complementary; s && *s; s++) { |
435 | t_complementary *pair; | 471 | t_complementary *pair; |
436 | unsigned *pair_switch; | 472 | unsigned *pair_switch; |
diff --git a/libbb/parse_config.c b/libbb/parse_config.c index 1590d9a4c..408439766 100644 --- a/libbb/parse_config.c +++ b/libbb/parse_config.c | |||
@@ -42,8 +42,8 @@ int parse_main(int argc UNUSED_PARAM, char **argv) | |||
42 | int mintokens = 0, ntokens = 128; | 42 | int mintokens = 0, ntokens = 128; |
43 | unsigned noout; | 43 | unsigned noout; |
44 | 44 | ||
45 | opt_complementary = "-1:n+:m+:f+"; | 45 | opt_complementary = "-1"; |
46 | noout = 1 & getopt32(argv, "xn:m:d:f:", &ntokens, &mintokens, &delims, &flags); | 46 | noout = 1 & getopt32(argv, "xn:+m:+d:f:+", &ntokens, &mintokens, &delims, &flags); |
47 | //argc -= optind; | 47 | //argc -= optind; |
48 | argv += optind; | 48 | argv += optind; |
49 | 49 | ||
diff --git a/loginutils/cryptpw.c b/loginutils/cryptpw.c index 23a1884f4..9f5f40686 100644 --- a/loginutils/cryptpw.c +++ b/loginutils/cryptpw.c | |||
@@ -111,8 +111,8 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv) | |||
111 | opt_m = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO; | 111 | opt_m = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO; |
112 | opt_S = NULL; | 112 | opt_S = NULL; |
113 | /* at most two non-option arguments; -P NUM */ | 113 | /* at most two non-option arguments; -P NUM */ |
114 | opt_complementary = "?2:P+"; | 114 | opt_complementary = "?2"; |
115 | getopt32(argv, "sP:S:m:a:", &fd, &opt_S, &opt_m, &opt_m); | 115 | getopt32(argv, "sP:+S:m:a:", &fd, &opt_S, &opt_m, &opt_m); |
116 | argv += optind; | 116 | argv += optind; |
117 | 117 | ||
118 | /* have no idea how to handle -s... */ | 118 | /* have no idea how to handle -s... */ |
diff --git a/loginutils/getty.c b/loginutils/getty.c index b10bdbdbf..162c1697e 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c | |||
@@ -131,7 +131,7 @@ struct globals { | |||
131 | //usage: "\n" | 131 | //usage: "\n" |
132 | //usage: "\nBAUD_RATE of 0 leaves it unchanged" | 132 | //usage: "\nBAUD_RATE of 0 leaves it unchanged" |
133 | 133 | ||
134 | static const char opt_string[] ALIGN1 = "I:LH:f:hil:mt:wn"; | 134 | static const char opt_string[] ALIGN1 = "I:LH:f:hil:mt:+wn"; |
135 | #define F_INITSTRING (1 << 0) /* -I */ | 135 | #define F_INITSTRING (1 << 0) /* -I */ |
136 | #define F_LOCAL (1 << 1) /* -L */ | 136 | #define F_LOCAL (1 << 1) /* -L */ |
137 | #define F_FAKEHOST (1 << 2) /* -H */ | 137 | #define F_FAKEHOST (1 << 2) /* -H */ |
@@ -179,7 +179,7 @@ static void parse_args(char **argv) | |||
179 | char *ts; | 179 | char *ts; |
180 | int flags; | 180 | int flags; |
181 | 181 | ||
182 | opt_complementary = "-2:t+"; /* at least 2 args; -t N */ | 182 | opt_complementary = "-2"; /* at least 2 args; -t N */ |
183 | flags = getopt32(argv, opt_string, | 183 | flags = getopt32(argv, opt_string, |
184 | &G.initstring, &G.fakehost, &G.issue, | 184 | &G.initstring, &G.fakehost, &G.issue, |
185 | &G.login, &G.timeout | 185 | &G.login, &G.timeout |
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index f32469551..6befea933 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c | |||
@@ -43,8 +43,7 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) | |||
43 | logmode = LOGMODE_BOTH; | 43 | logmode = LOGMODE_BOTH; |
44 | openlog(applet_name, 0, LOG_AUTH); | 44 | openlog(applet_name, 0, LOG_AUTH); |
45 | 45 | ||
46 | opt_complementary = "t+"; /* -t N */ | 46 | getopt32(argv, "t:+", &timeout); |
47 | getopt32(argv, "t:", &timeout); | ||
48 | argv += optind; | 47 | argv += optind; |
49 | 48 | ||
50 | if (argv[0]) { | 49 | if (argv[0]) { |
diff --git a/mailutils/makemime.c b/mailutils/makemime.c index 1dadd715f..8e1bc664c 100644 --- a/mailutils/makemime.c +++ b/mailutils/makemime.c | |||
@@ -184,9 +184,8 @@ int makemime_main(int argc UNUSED_PARAM, char **argv) | |||
184 | INIT_G(); | 184 | INIT_G(); |
185 | 185 | ||
186 | // parse options | 186 | // parse options |
187 | opt_complementary = "a::"; | ||
188 | opts = getopt32(argv, | 187 | opts = getopt32(argv, |
189 | "c:e:o:C:N:a:", // "m:j:", | 188 | "c:e:o:C:N:a:*", // "m:j:", |
190 | &content_type, NULL, &opt_output, &G.opt_charset, NULL, &opt_headers //, NULL, NULL | 189 | &content_type, NULL, &opt_output, &G.opt_charset, NULL, &opt_headers //, NULL, NULL |
191 | ); | 190 | ); |
192 | //argc -= optind; | 191 | //argc -= optind; |
diff --git a/mailutils/popmaildir.c b/mailutils/popmaildir.c index 62030331e..69eca6164 100644 --- a/mailutils/popmaildir.c +++ b/mailutils/popmaildir.c | |||
@@ -107,9 +107,9 @@ int popmaildir_main(int argc UNUSED_PARAM, char **argv) | |||
107 | INIT_G(); | 107 | INIT_G(); |
108 | 108 | ||
109 | // parse options | 109 | // parse options |
110 | opt_complementary = "-1:dd:t+:R+:L+:H+"; | 110 | opt_complementary = "-1:dd"; |
111 | opts = getopt32(argv, | 111 | opts = getopt32(argv, |
112 | "bdmVcasTkt:" "R:Z:L:H:" IF_FEATURE_POPMAILDIR_DELIVERY("M:F:"), | 112 | "bdmVcasTkt:+" "R:+Z:L:+H:+" IF_FEATURE_POPMAILDIR_DELIVERY("M:F:"), |
113 | &timeout, NULL, NULL, NULL, &opt_nlines | 113 | &timeout, NULL, NULL, NULL, &opt_nlines |
114 | IF_FEATURE_POPMAILDIR_DELIVERY(, &delivery, &delivery) // we treat -M and -F the same | 114 | IF_FEATURE_POPMAILDIR_DELIVERY(, &delivery, &delivery) // we treat -M and -F the same |
115 | ); | 115 | ); |
diff --git a/mailutils/reformime.c b/mailutils/reformime.c index 86b2cfed3..b967dfbc7 100644 --- a/mailutils/reformime.c +++ b/mailutils/reformime.c | |||
@@ -265,9 +265,9 @@ int reformime_main(int argc UNUSED_PARAM, char **argv) | |||
265 | 265 | ||
266 | // parse options | 266 | // parse options |
267 | // N.B. only -x and -X are supported so far | 267 | // N.B. only -x and -X are supported so far |
268 | opt_complementary = "x--X:X--x" IF_FEATURE_REFORMIME_COMPAT(":m::"); | 268 | opt_complementary = "x--X:X--x"; |
269 | opts = getopt32(argv, | 269 | opts = getopt32(argv, |
270 | "x:X" IF_FEATURE_REFORMIME_COMPAT("deis:r:c:m:h:o:O:"), | 270 | "x:X" IF_FEATURE_REFORMIME_COMPAT("deis:r:c:m:*h:o:O:"), |
271 | &opt_prefix | 271 | &opt_prefix |
272 | IF_FEATURE_REFORMIME_COMPAT(, NULL, NULL, &G.opt_charset, NULL, NULL, NULL, NULL) | 272 | IF_FEATURE_REFORMIME_COMPAT(, NULL, NULL, &G.opt_charset, NULL, NULL, NULL, NULL) |
273 | ); | 273 | ); |
diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c index 5143fac8f..fb4dbb3da 100644 --- a/mailutils/sendmail.c +++ b/mailutils/sendmail.c | |||
@@ -247,11 +247,11 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
247 | 247 | ||
248 | // parse options | 248 | // parse options |
249 | // -v is a counter, -H and -S are mutually exclusive, -a is a list | 249 | // -v is a counter, -H and -S are mutually exclusive, -a is a list |
250 | opt_complementary = "vv:w+:H--S:S--H:a::"; | 250 | opt_complementary = "vv:H--S:S--H"; |
251 | // N.B. since -H and -S are mutually exclusive they do not interfere in opt_connect | 251 | // N.B. since -H and -S are mutually exclusive they do not interfere in opt_connect |
252 | // -a is for ssmtp (http://downloads.openwrt.org/people/nico/man/man8/ssmtp.8.html) compatibility, | 252 | // -a is for ssmtp (http://downloads.openwrt.org/people/nico/man/man8/ssmtp.8.html) compatibility, |
253 | // it is still under development. | 253 | // it is still under development. |
254 | opts = getopt32(argv, "tf:o:iw:H:S:a::v", &opt_from, NULL, | 254 | opts = getopt32(argv, "tf:o:iw:+H:S:a:*:v", &opt_from, NULL, |
255 | &timeout, &opt_connect, &opt_connect, &list, &verbose); | 255 | &timeout, &opt_connect, &opt_connect, &list, &verbose); |
256 | //argc -= optind; | 256 | //argc -= optind; |
257 | argv += optind; | 257 | argv += optind; |
diff --git a/miscutils/conspy.c b/miscutils/conspy.c index f6468c116..e80158e39 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c | |||
@@ -388,8 +388,8 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) | |||
388 | INIT_G(); | 388 | INIT_G(); |
389 | strcpy(G.vcsa_name, DEV_VCSA); | 389 | strcpy(G.vcsa_name, DEV_VCSA); |
390 | 390 | ||
391 | opt_complementary = "x+:y+"; // numeric params | 391 | // numeric params |
392 | opts = getopt32(argv, "vcQsndfFx:y:", &G.x, &G.y); | 392 | opts = getopt32(argv, "vcQsndfFx:+y:+", &G.x, &G.y); |
393 | argv += optind; | 393 | argv += optind; |
394 | ttynum = 0; | 394 | ttynum = 0; |
395 | if (argv[0]) { | 395 | if (argv[0]) { |
diff --git a/miscutils/ionice.c b/miscutils/ionice.c index 0c14256ab..5fcb653a8 100644 --- a/miscutils/ionice.c +++ b/miscutils/ionice.c | |||
@@ -60,9 +60,8 @@ int ionice_main(int argc UNUSED_PARAM, char **argv) | |||
60 | }; | 60 | }; |
61 | 61 | ||
62 | /* Numeric params */ | 62 | /* Numeric params */ |
63 | opt_complementary = "n+:c+:p+"; | ||
64 | /* '+': stop at first non-option */ | 63 | /* '+': stop at first non-option */ |
65 | opt = getopt32(argv, "+n:c:p:", &pri, &ioclass, &pid); | 64 | opt = getopt32(argv, "+n:+c:+p:+", &pri, &ioclass, &pid); |
66 | argv += optind; | 65 | argv += optind; |
67 | 66 | ||
68 | if (opt & OPT_c) { | 67 | if (opt & OPT_c) { |
diff --git a/miscutils/microcom.c b/miscutils/microcom.c index d9e8f9187..dfc9771d8 100644 --- a/miscutils/microcom.c +++ b/miscutils/microcom.c | |||
@@ -64,8 +64,7 @@ int microcom_main(int argc UNUSED_PARAM, char **argv) | |||
64 | unsigned opts; | 64 | unsigned opts; |
65 | 65 | ||
66 | // fetch options | 66 | // fetch options |
67 | opt_complementary = "=1:s+:d+:t+"; // exactly one arg, numeric options | 67 | opts = getopt32(argv, "Xs:+d:+t:+", &speed, &delay, &timeout); |
68 | opts = getopt32(argv, "Xs:d:t:", &speed, &delay, &timeout); | ||
69 | // argc -= optind; | 68 | // argc -= optind; |
70 | argv += optind; | 69 | argv += optind; |
71 | 70 | ||
diff --git a/miscutils/timeout.c b/miscutils/timeout.c index 9d56593ba..8df9ff0fd 100644 --- a/miscutils/timeout.c +++ b/miscutils/timeout.c | |||
@@ -52,9 +52,8 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
52 | /* -p option is not documented, it is needed to support NOMMU. */ | 52 | /* -p option is not documented, it is needed to support NOMMU. */ |
53 | 53 | ||
54 | /* -t SECONDS; -p PARENT_PID */ | 54 | /* -t SECONDS; -p PARENT_PID */ |
55 | opt_complementary = "t+" USE_FOR_NOMMU(":p+"); | ||
56 | /* '+': stop at first non-option */ | 55 | /* '+': stop at first non-option */ |
57 | getopt32(argv, "+s:t:" USE_FOR_NOMMU("p:"), &opt_s, &timeout, &parent); | 56 | getopt32(argv, "+s:t:+" USE_FOR_NOMMU("p:+"), &opt_s, &timeout, &parent); |
58 | /*argv += optind; - no, wait for bb_daemonize_or_rexec! */ | 57 | /*argv += optind; - no, wait for bb_daemonize_or_rexec! */ |
59 | signo = get_signum(opt_s); | 58 | signo = get_signum(opt_s); |
60 | if (signo < 0) | 59 | if (signo < 0) |
diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c index 4364bc807..8e55e9577 100644 --- a/miscutils/ubi_tools.c +++ b/miscutils/ubi_tools.c | |||
@@ -134,8 +134,8 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) | |||
134 | #define OPTION_a (1 << 5) | 134 | #define OPTION_a (1 << 5) |
135 | #define OPTION_t (1 << 6) | 135 | #define OPTION_t (1 << 6) |
136 | if (do_mkvol) { | 136 | if (do_mkvol) { |
137 | opt_complementary = "-1:d+:n+:a+:O+"; | 137 | opt_complementary = "-1"; |
138 | opts = getopt32(argv, "md:n:N:s:a:t:O:", | 138 | opts = getopt32(argv, "md:+n:+N:s:a:+t:O:+", |
139 | &dev_num, &vol_id, | 139 | &dev_num, &vol_id, |
140 | &vol_name, &size_bytes_str, &alignment, &type, | 140 | &vol_name, &size_bytes_str, &alignment, &type, |
141 | &vid_hdr_offset | 141 | &vid_hdr_offset |
@@ -146,8 +146,8 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) | |||
146 | opts = getopt32(argv, "s:at", &size_bytes_str); | 146 | opts = getopt32(argv, "s:at", &size_bytes_str); |
147 | opts *= OPTION_s; | 147 | opts *= OPTION_s; |
148 | } else { | 148 | } else { |
149 | opt_complementary = "-1:m+:d+:n+:a+"; | 149 | opt_complementary = "-1"; |
150 | opts = getopt32(argv, "m:d:n:N:s:a:t:", | 150 | opts = getopt32(argv, "m:+d:+n:+N:s:a:+t:", |
151 | &mtd_num, &dev_num, &vol_id, | 151 | &mtd_num, &dev_num, &vol_id, |
152 | &vol_name, &size_bytes_str, &alignment, &type | 152 | &vol_name, &size_bytes_str, &alignment, &type |
153 | ); | 153 | ); |
diff --git a/networking/arping.c b/networking/arping.c index 4f207eaa5..46bd65e36 100644 --- a/networking/arping.c +++ b/networking/arping.c | |||
@@ -295,8 +295,8 @@ int arping_main(int argc UNUSED_PARAM, char **argv) | |||
295 | /* Dad also sets quit_on_reply. | 295 | /* Dad also sets quit_on_reply. |
296 | * Advert also sets unsolicited. | 296 | * Advert also sets unsolicited. |
297 | */ | 297 | */ |
298 | opt_complementary = "=1:Df:AU:c+"; | 298 | opt_complementary = "=1:Df:AU"; |
299 | opt = getopt32(argv, "DUAqfbc:w:I:s:", | 299 | opt = getopt32(argv, "DUAqfbc:+w:I:s:", |
300 | &count, &str_timeout, &device, &source); | 300 | &count, &str_timeout, &device, &source); |
301 | if (opt & 0x80) /* -w: timeout */ | 301 | if (opt & 0x80) /* -w: timeout */ |
302 | timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000 + 500000; | 302 | timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000 + 500000; |
diff --git a/networking/ftpd.c b/networking/ftpd.c index 360d1e6be..4cbb9b6fe 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c | |||
@@ -1130,11 +1130,11 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv) | |||
1130 | abs_timeout = 1 * 60 * 60; | 1130 | abs_timeout = 1 * 60 * 60; |
1131 | verbose_S = 0; | 1131 | verbose_S = 0; |
1132 | G.timeout = 2 * 60; | 1132 | G.timeout = 2 * 60; |
1133 | opt_complementary = "t+:T+:vv:SS"; | 1133 | opt_complementary = "vv:SS"; |
1134 | #if BB_MMU | 1134 | #if BB_MMU |
1135 | opts = getopt32(argv, "vS" IF_FEATURE_FTP_WRITE("w") "t:T:", &G.timeout, &abs_timeout, &G.verbose, &verbose_S); | 1135 | opts = getopt32(argv, "vS" IF_FEATURE_FTP_WRITE("w") "t:+T:+", &G.timeout, &abs_timeout, &G.verbose, &verbose_S); |
1136 | #else | 1136 | #else |
1137 | opts = getopt32(argv, "l1AvS" IF_FEATURE_FTP_WRITE("w") "t:T:", &G.timeout, &abs_timeout, &G.verbose, &verbose_S); | 1137 | opts = getopt32(argv, "l1AvS" IF_FEATURE_FTP_WRITE("w") "t:+T:+", &G.timeout, &abs_timeout, &G.verbose, &verbose_S); |
1138 | if (opts & (OPT_l|OPT_1)) { | 1138 | if (opts & (OPT_l|OPT_1)) { |
1139 | /* Our secret backdoor to ls */ | 1139 | /* Our secret backdoor to ls */ |
1140 | /* TODO: pass --group-directories-first? would be nice, but ls doesn't do that yet */ | 1140 | /* TODO: pass --group-directories-first? would be nice, but ls doesn't do that yet */ |
diff --git a/networking/ifplugd.c b/networking/ifplugd.c index f0defb5c8..28c49e218 100644 --- a/networking/ifplugd.c +++ b/networking/ifplugd.c | |||
@@ -107,9 +107,9 @@ enum { | |||
107 | #endif | 107 | #endif |
108 | }; | 108 | }; |
109 | #if ENABLE_FEATURE_PIDFILE | 109 | #if ENABLE_FEATURE_PIDFILE |
110 | # define OPTION_STR "+ansfFi:r:It:u:d:m:pqlx:Mk" | 110 | # define OPTION_STR "+ansfFi:r:It:+u:+d:+m:pqlx:Mk" |
111 | #else | 111 | #else |
112 | # define OPTION_STR "+ansfFi:r:It:u:d:m:pqlx:M" | 112 | # define OPTION_STR "+ansfFi:r:It:+u:+d:+m:pqlx:M" |
113 | #endif | 113 | #endif |
114 | 114 | ||
115 | enum { // interface status | 115 | enum { // interface status |
@@ -560,7 +560,6 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) | |||
560 | 560 | ||
561 | INIT_G(); | 561 | INIT_G(); |
562 | 562 | ||
563 | opt_complementary = "t+:u+:d+"; | ||
564 | opts = getopt32(argv, OPTION_STR, | 563 | opts = getopt32(argv, OPTION_STR, |
565 | &G.iface, &G.script_name, &G.poll_time, &G.delay_up, | 564 | &G.iface, &G.script_name, &G.poll_time, &G.delay_up, |
566 | &G.delay_down, &G.api_mode, &G.extra_arg); | 565 | &G.delay_down, &G.api_mode, &G.extra_arg); |
diff --git a/networking/inetd.c b/networking/inetd.c index 8d44b5198..f9295e38b 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -1153,8 +1153,8 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) | |||
1153 | if (real_uid != 0) /* run by non-root user */ | 1153 | if (real_uid != 0) /* run by non-root user */ |
1154 | config_filename = NULL; | 1154 | config_filename = NULL; |
1155 | 1155 | ||
1156 | opt_complementary = "R+:q+"; /* -q N, -R N */ | 1156 | /* -q N, -R N */ |
1157 | opt = getopt32(argv, "R:feq:", &max_concurrency, &global_queuelen); | 1157 | opt = getopt32(argv, "R:+feq:+", &max_concurrency, &global_queuelen); |
1158 | argv += optind; | 1158 | argv += optind; |
1159 | //argc -= optind; | 1159 | //argc -= optind; |
1160 | if (argv[0]) | 1160 | if (argv[0]) |
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c index 471ae1a12..192e42fe5 100644 --- a/networking/nc_bloaty.c +++ b/networking/nc_bloaty.c | |||
@@ -794,8 +794,8 @@ int nc_main(int argc UNUSED_PARAM, char **argv) | |||
794 | e_found: | 794 | e_found: |
795 | 795 | ||
796 | // -g -G -t -r deleted, unimplemented -a deleted too | 796 | // -g -G -t -r deleted, unimplemented -a deleted too |
797 | opt_complementary = "?2:vv:ll:w+"; /* max 2 params; -v and -l are counters; -w N */ | 797 | opt_complementary = "?2:vv:ll"; /* max 2 params; -v and -l are counters; -w N */ |
798 | getopt32(argv, "np:s:uvw:" IF_NC_SERVER("lk") | 798 | getopt32(argv, "np:s:uvw:+" IF_NC_SERVER("lk") |
799 | IF_NC_EXTRA("i:o:z"), | 799 | IF_NC_EXTRA("i:o:z"), |
800 | &str_p, &str_s, &o_wait | 800 | &str_p, &str_s, &o_wait |
801 | IF_NC_EXTRA(, &str_i, &str_o), &o_verbose IF_NC_SERVER(, &cnt_l)); | 801 | IF_NC_EXTRA(, &str_i, &str_o), &o_verbose IF_NC_SERVER(, &cnt_l)); |
diff --git a/networking/ntpd.c b/networking/ntpd.c index 8e7175063..130cef0af 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -2197,11 +2197,11 @@ static NOINLINE void ntp_init(char **argv) | |||
2197 | 2197 | ||
2198 | /* Parse options */ | 2198 | /* Parse options */ |
2199 | peers = NULL; | 2199 | peers = NULL; |
2200 | opt_complementary = "dd:p::wn" /* -d: counter; -p: list; -w implies -n */ | 2200 | opt_complementary = "dd:wn" /* -d: counter; -p: list; -w implies -n */ |
2201 | IF_FEATURE_NTPD_SERVER(":Il"); /* -I implies -l */ | 2201 | IF_FEATURE_NTPD_SERVER(":Il"); /* -I implies -l */ |
2202 | opts = getopt32(argv, | 2202 | opts = getopt32(argv, |
2203 | "nqNx" /* compat */ | 2203 | "nqNx" /* compat */ |
2204 | "wp:S:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */ | 2204 | "wp:*S:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */ |
2205 | IF_FEATURE_NTPD_SERVER("I:") /* compat */ | 2205 | IF_FEATURE_NTPD_SERVER("I:") /* compat */ |
2206 | "d" /* compat */ | 2206 | "d" /* compat */ |
2207 | "46aAbgL", /* compat, ignored */ | 2207 | "46aAbgL", /* compat, ignored */ |
diff --git a/networking/ping.c b/networking/ping.c index d8767a39f..82d5b7a85 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -341,7 +341,7 @@ static int common_ping_main(sa_family_t af, char **argv) | |||
341 | 341 | ||
342 | /* Full(er) version */ | 342 | /* Full(er) version */ |
343 | 343 | ||
344 | #define OPT_STRING ("qvc:s:t:w:W:I:np:4" IF_PING6("6")) | 344 | #define OPT_STRING ("qvc:+s:t:+w:+W:+I:np:4" IF_PING6("6")) |
345 | enum { | 345 | enum { |
346 | OPT_QUIET = 1 << 0, | 346 | OPT_QUIET = 1 << 0, |
347 | OPT_VERBOSE = 1 << 1, | 347 | OPT_VERBOSE = 1 << 1, |
@@ -865,7 +865,7 @@ static int common_ping_main(int opt, char **argv) | |||
865 | INIT_G(); | 865 | INIT_G(); |
866 | 866 | ||
867 | /* exactly one argument needed; -v and -q don't mix; -c NUM, -t NUM, -w NUM, -W NUM */ | 867 | /* exactly one argument needed; -v and -q don't mix; -c NUM, -t NUM, -w NUM, -W NUM */ |
868 | opt_complementary = "=1:q--v:v--q:c+:t+:w+:W+"; | 868 | opt_complementary = "=1:q--v:v--q"; |
869 | opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &opt_ttl, &deadline, &timeout, &str_I, &str_p); | 869 | opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &opt_ttl, &deadline, &timeout, &str_I, &str_p); |
870 | if (opt & OPT_s) | 870 | if (opt & OPT_s) |
871 | datalen = xatou16(str_s); // -s | 871 | datalen = xatou16(str_s); // -s |
diff --git a/networking/tcpudp.c b/networking/tcpudp.c index 31bc70459..fbd1f1c45 100644 --- a/networking/tcpudp.c +++ b/networking/tcpudp.c | |||
@@ -232,9 +232,9 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv) | |||
232 | tcp = (applet_name[0] == 't'); | 232 | tcp = (applet_name[0] == 't'); |
233 | 233 | ||
234 | /* 3+ args, -i at most once, -p implies -h, -v is counter, -b N, -c N */ | 234 | /* 3+ args, -i at most once, -p implies -h, -v is counter, -b N, -c N */ |
235 | opt_complementary = "-3:i--i:ph:vv:b+:c+"; | 235 | opt_complementary = "-3:i--i:ph:vv"; |
236 | #ifdef SSLSVD | 236 | #ifdef SSLSVD |
237 | opts = getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:vU:/:Z:K:", | 237 | opts = getopt32(argv, "+c:+C:i:x:u:l:Eb:+hpt:vU:/:Z:K:", |
238 | &cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname, | 238 | &cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname, |
239 | &backlog, &str_t, &ssluser, &root, &cert, &key, &verbose | 239 | &backlog, &str_t, &ssluser, &root, &cert, &key, &verbose |
240 | ); | 240 | ); |
diff --git a/networking/telnetd.c b/networking/telnetd.c index 13c36aa46..2fbdc3bb3 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -496,12 +496,12 @@ int telnetd_main(int argc UNUSED_PARAM, char **argv) | |||
496 | INIT_G(); | 496 | INIT_G(); |
497 | 497 | ||
498 | /* -w NUM, and implies -F. -w and -i don't mix */ | 498 | /* -w NUM, and implies -F. -w and -i don't mix */ |
499 | IF_FEATURE_TELNETD_INETD_WAIT(opt_complementary = "wF:w+:i--w:w--i";) | 499 | IF_FEATURE_TELNETD_INETD_WAIT(opt_complementary = "wF:i--w:w--i";) |
500 | /* Even if !STANDALONE, we accept (and ignore) -i, thus people | 500 | /* Even if !STANDALONE, we accept (and ignore) -i, thus people |
501 | * don't need to guess whether it's ok to pass -i to us */ | 501 | * don't need to guess whether it's ok to pass -i to us */ |
502 | opt = getopt32(argv, "f:l:Ki" | 502 | opt = getopt32(argv, "f:l:Ki" |
503 | IF_FEATURE_TELNETD_STANDALONE("p:b:F") | 503 | IF_FEATURE_TELNETD_STANDALONE("p:b:F") |
504 | IF_FEATURE_TELNETD_INETD_WAIT("Sw:"), | 504 | IF_FEATURE_TELNETD_INETD_WAIT("Sw:+"), |
505 | &G.issuefile, &G.loginpath | 505 | &G.issuefile, &G.loginpath |
506 | IF_FEATURE_TELNETD_STANDALONE(, &opt_portnbr, &opt_bindaddr) | 506 | IF_FEATURE_TELNETD_STANDALONE(, &opt_portnbr, &opt_bindaddr) |
507 | IF_FEATURE_TELNETD_INETD_WAIT(, &sec_linger) | 507 | IF_FEATURE_TELNETD_INETD_WAIT(, &sec_linger) |
diff --git a/networking/traceroute.c b/networking/traceroute.c index eee4f8873..e43a36dc7 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -294,7 +294,7 @@ | |||
294 | 294 | ||
295 | #define OPT_STRING \ | 295 | #define OPT_STRING \ |
296 | "FIlnrdvxt:i:m:p:q:s:w:z:f:" \ | 296 | "FIlnrdvxt:i:m:p:q:s:w:z:f:" \ |
297 | IF_FEATURE_TRACEROUTE_SOURCE_ROUTE("g:") \ | 297 | IF_FEATURE_TRACEROUTE_SOURCE_ROUTE("g:*") \ |
298 | "4" IF_TRACEROUTE6("6") | 298 | "4" IF_TRACEROUTE6("6") |
299 | enum { | 299 | enum { |
300 | OPT_DONT_FRAGMNT = (1 << 0), /* F */ | 300 | OPT_DONT_FRAGMNT = (1 << 0), /* F */ |
@@ -819,7 +819,7 @@ common_traceroute_main(int op, char **argv) | |||
819 | INIT_G(); | 819 | INIT_G(); |
820 | 820 | ||
821 | /* minimum 1 arg */ | 821 | /* minimum 1 arg */ |
822 | opt_complementary = "-1:x-x" IF_FEATURE_TRACEROUTE_SOURCE_ROUTE(":g::"); | 822 | opt_complementary = "-1:x-x"; |
823 | op |= getopt32(argv, OPT_STRING | 823 | op |= getopt32(argv, OPT_STRING |
824 | , &tos_str, &device, &max_ttl_str, &port_str, &nprobes_str | 824 | , &tos_str, &device, &max_ttl_str, &port_str, &nprobes_str |
825 | , &source, &waittime_str, &pausemsecs_str, &first_ttl_str | 825 | , &source, &waittime_str, &pausemsecs_str, &first_ttl_str |
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 12f8f1125..6ff040d9e 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c | |||
@@ -944,9 +944,9 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
944 | 944 | ||
945 | /* Parse command line */ | 945 | /* Parse command line */ |
946 | /* O,x: list; -T,-t,-A take numeric param */ | 946 | /* O,x: list; -T,-t,-A take numeric param */ |
947 | opt_complementary = "O::x::T+:t+:A+" IF_UDHCP_VERBOSE(":vv") ; | 947 | IF_UDHCP_VERBOSE(opt_complementary = "vv";) |
948 | IF_LONG_OPTS(applet_long_options = udhcpc6_longopts;) | 948 | IF_LONG_OPTS(applet_long_options = udhcpc6_longopts;) |
949 | opt = getopt32(argv, "i:np:qRr:s:T:t:SA:O:ox:f" | 949 | opt = getopt32(argv, "i:np:qRr:s:T:+t:+SA:+O:*ox:*f" |
950 | USE_FOR_MMU("b") | 950 | USE_FOR_MMU("b") |
951 | ///IF_FEATURE_UDHCPC_ARPING("a") | 951 | ///IF_FEATURE_UDHCPC_ARPING("a") |
952 | IF_FEATURE_UDHCP_PORT("P:") | 952 | IF_FEATURE_UDHCP_PORT("P:") |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index e58acbaca..8a16e987d 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -1283,9 +1283,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1283 | 1283 | ||
1284 | /* Parse command line */ | 1284 | /* Parse command line */ |
1285 | /* O,x: list; -T,-t,-A take numeric param */ | 1285 | /* O,x: list; -T,-t,-A take numeric param */ |
1286 | opt_complementary = "O::x::T+:t+:A+" IF_UDHCP_VERBOSE(":vv") ; | 1286 | IF_UDHCP_VERBOSE(opt_complementary = "vv";) |
1287 | IF_LONG_OPTS(applet_long_options = udhcpc_longopts;) | 1287 | IF_LONG_OPTS(applet_long_options = udhcpc_longopts;) |
1288 | opt = getopt32(argv, "CV:H:h:F:i:np:qRr:s:T:t:SA:O:ox:fB" | 1288 | opt = getopt32(argv, "CV:H:h:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fB" |
1289 | USE_FOR_MMU("b") | 1289 | USE_FOR_MMU("b") |
1290 | IF_FEATURE_UDHCPC_ARPING("a::") | 1290 | IF_FEATURE_UDHCPC_ARPING("a::") |
1291 | IF_FEATURE_UDHCP_PORT("P:") | 1291 | IF_FEATURE_UDHCP_PORT("P:") |
diff --git a/networking/wget.c b/networking/wget.c index 28c12540b..37950ed39 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -1268,9 +1268,8 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0") | |||
1268 | applet_long_options = wget_longopts; | 1268 | applet_long_options = wget_longopts; |
1269 | #endif | 1269 | #endif |
1270 | opt_complementary = "-1" /* at least one URL */ | 1270 | opt_complementary = "-1" /* at least one URL */ |
1271 | IF_FEATURE_WGET_TIMEOUT(":T+") /* -T NUM */ | ||
1272 | IF_FEATURE_WGET_LONG_OPTIONS(":\xff::"); /* --header is a list */ | 1271 | IF_FEATURE_WGET_LONG_OPTIONS(":\xff::"); /* --header is a list */ |
1273 | getopt32(argv, "csqO:P:Y:U:T:" | 1272 | getopt32(argv, "csqO:P:Y:U:T:+" |
1274 | /*ignored:*/ "t:" | 1273 | /*ignored:*/ "t:" |
1275 | /*ignored:*/ "n::" | 1274 | /*ignored:*/ "n::" |
1276 | /* wget has exactly four -n<letter> opts, all of which we can ignore: | 1275 | /* wget has exactly four -n<letter> opts, all of which we can ignore: |
diff --git a/networking/whois.c b/networking/whois.c index 6ba8dfd20..c9dfcf5ee 100644 --- a/networking/whois.c +++ b/networking/whois.c | |||
@@ -167,8 +167,8 @@ int whois_main(int argc UNUSED_PARAM, char **argv) | |||
167 | int port = 43; | 167 | int port = 43; |
168 | const char *host = "whois.iana.org"; | 168 | const char *host = "whois.iana.org"; |
169 | 169 | ||
170 | opt_complementary = "-1:p+"; | 170 | opt_complementary = "-1"; |
171 | getopt32(argv, "ih:p:", &host, &port); | 171 | getopt32(argv, "ih:p:+", &host, &port); |
172 | argv += optind; | 172 | argv += optind; |
173 | 173 | ||
174 | do { | 174 | do { |
diff --git a/procps/pgrep.c b/procps/pgrep.c index 1c7c7c48b..1c594cf96 100644 --- a/procps/pgrep.c +++ b/procps/pgrep.c | |||
@@ -106,8 +106,7 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) | |||
106 | /* Parse remaining options */ | 106 | /* Parse remaining options */ |
107 | ppid2match = -1; | 107 | ppid2match = -1; |
108 | sid2match = -1; | 108 | sid2match = -1; |
109 | opt_complementary = "s+:P+"; /* numeric opts */ | 109 | opt = getopt32(argv, "vlfxons:+P:+", &sid2match, &ppid2match); |
110 | opt = getopt32(argv, "vlfxons:P:", &sid2match, &ppid2match); | ||
111 | argv += optind; | 110 | argv += optind; |
112 | 111 | ||
113 | if (pkill && OPT_LIST) { /* -l: print the whole signal list */ | 112 | if (pkill && OPT_LIST) { /* -l: print the whole signal list */ |
diff --git a/procps/pidof.c b/procps/pidof.c index 6d7b59109..6d265667f 100644 --- a/procps/pidof.c +++ b/procps/pidof.c | |||
@@ -51,13 +51,12 @@ int pidof_main(int argc UNUSED_PARAM, char **argv) | |||
51 | unsigned opt; | 51 | unsigned opt; |
52 | #if ENABLE_FEATURE_PIDOF_OMIT | 52 | #if ENABLE_FEATURE_PIDOF_OMIT |
53 | llist_t *omits = NULL; /* list of pids to omit */ | 53 | llist_t *omits = NULL; /* list of pids to omit */ |
54 | opt_complementary = "o::"; | ||
55 | #endif | 54 | #endif |
56 | 55 | ||
57 | /* do unconditional option parsing */ | 56 | /* do unconditional option parsing */ |
58 | opt = getopt32(argv, "" | 57 | opt = getopt32(argv, "" |
59 | IF_FEATURE_PIDOF_SINGLE ("s") | 58 | IF_FEATURE_PIDOF_SINGLE ("s") |
60 | IF_FEATURE_PIDOF_OMIT("o:", &omits)); | 59 | IF_FEATURE_PIDOF_OMIT("o:*", &omits)); |
61 | 60 | ||
62 | #if ENABLE_FEATURE_PIDOF_OMIT | 61 | #if ENABLE_FEATURE_PIDOF_OMIT |
63 | /* fill omit list. */ | 62 | /* fill omit list. */ |
diff --git a/procps/ps.c b/procps/ps.c index 08dfce12e..ce638261a 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -593,8 +593,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv) | |||
593 | * procps v3.2.7 supports -T and shows tids as SPID column, | 593 | * procps v3.2.7 supports -T and shows tids as SPID column, |
594 | * it also supports -L where it shows tids as LWP column. | 594 | * it also supports -L where it shows tids as LWP column. |
595 | */ | 595 | */ |
596 | opt_complementary = "o::"; | 596 | opt = getopt32(argv, "Zo:*aAdefl"IF_FEATURE_SHOW_THREADS("T"), &opt_o); |
597 | opt = getopt32(argv, "Zo:aAdefl"IF_FEATURE_SHOW_THREADS("T"), &opt_o); | ||
598 | if (opt_o) { | 597 | if (opt_o) { |
599 | do { | 598 | do { |
600 | parse_o(llist_pop(&opt_o)); | 599 | parse_o(llist_pop(&opt_o)); |
diff --git a/procps/watch.c b/procps/watch.c index 97aa04767..20859c3cd 100644 --- a/procps/watch.c +++ b/procps/watch.c | |||
@@ -51,9 +51,9 @@ int watch_main(int argc UNUSED_PARAM, char **argv) | |||
51 | xopen("/dev/null", O_RDONLY); | 51 | xopen("/dev/null", O_RDONLY); |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | opt_complementary = "-1:n+"; // at least one param; -n NUM | 54 | opt_complementary = "-1"; // at least one param; -n NUM |
55 | // "+": stop at first non-option (procps 3.x only) | 55 | // "+": stop at first non-option (procps 3.x only) |
56 | opt = getopt32(argv, "+dtn:", &period); | 56 | opt = getopt32(argv, "+dtn:+", &period); |
57 | argv += optind; | 57 | argv += optind; |
58 | 58 | ||
59 | // watch from both procps 2.x and 3.x does concatenation. Example: | 59 | // watch from both procps 2.x and 3.x does concatenation. Example: |
diff --git a/runit/chpst.c b/runit/chpst.c index 7fe5151db..3769af25e 100644 --- a/runit/chpst.c +++ b/runit/chpst.c | |||
@@ -300,8 +300,8 @@ int chpst_main(int argc UNUSED_PARAM, char **argv) | |||
300 | // FIXME: can we live with int-sized limits? | 300 | // FIXME: can we live with int-sized limits? |
301 | // can we live with 40000 days? | 301 | // can we live with 40000 days? |
302 | // if yes -> getopt converts strings to numbers for us | 302 | // if yes -> getopt converts strings to numbers for us |
303 | opt_complementary = "-1:a+:c+:d+:f+:l+:m+:o+:p+:r+:s+:t+"; | 303 | opt_complementary = "-1"; |
304 | opt = getopt32(argv, "+a:c:d:f:l:m:o:p:r:s:t:u:U:e:" | 304 | opt = getopt32(argv, "+a:+c:+d:+f:+l:+m:+o:+p:+r:+s:+t:+u:U:e:" |
305 | IF_CHPST("/:n:vP012"), | 305 | IF_CHPST("/:n:vP012"), |
306 | &limita, &limitc, &limitd, &limitf, &limitl, | 306 | &limita, &limitc, &limitd, &limitf, &limitl, |
307 | &limitm, &limito, &limitp, &limitr, &limits, &limitt, | 307 | &limitm, &limito, &limitp, &limitr, &limits, &limitt, |
diff --git a/runit/sv.c b/runit/sv.c index 2a256a6b4..37df9a929 100644 --- a/runit/sv.c +++ b/runit/sv.c | |||
@@ -474,8 +474,8 @@ int sv_main(int argc UNUSED_PARAM, char **argv) | |||
474 | x = getenv("SVWAIT"); | 474 | x = getenv("SVWAIT"); |
475 | if (x) waitsec = xatou(x); | 475 | if (x) waitsec = xatou(x); |
476 | 476 | ||
477 | opt_complementary = "w+:vv"; /* -w N, -v is a counter */ | 477 | opt_complementary = "vv"; /* -w N, -v is a counter */ |
478 | getopt32(argv, "w:v", &waitsec, &verbose); | 478 | getopt32(argv, "w:+v", &waitsec, &verbose); |
479 | argv += optind; | 479 | argv += optind; |
480 | action = *argv++; | 480 | action = *argv++; |
481 | if (!action || !*argv) bb_show_usage(); | 481 | if (!action || !*argv) bb_show_usage(); |
diff --git a/selinux/setfiles.c b/selinux/setfiles.c index 51a7e63bd..c9597d54e 100644 --- a/selinux/setfiles.c +++ b/selinux/setfiles.c | |||
@@ -577,13 +577,13 @@ int setfiles_main(int argc UNUSED_PARAM, char **argv) | |||
577 | 577 | ||
578 | set_matchpathcon_flags(matchpathcon_flags); | 578 | set_matchpathcon_flags(matchpathcon_flags); |
579 | 579 | ||
580 | opt_complementary = "e::vv:v--p:p--v:v--q:q--v"; | 580 | opt_complementary = "vv:v--p:p--v:v--q:q--v"; |
581 | /* Option order must match OPT_x definitions! */ | 581 | /* Option order must match OPT_x definitions! */ |
582 | if (applet_name[0] == 'r') { /* restorecon */ | 582 | if (applet_name[0] == 'r') { /* restorecon */ |
583 | flags = getopt32(argv, "de:f:ilnpqrsvo:FWR", | 583 | flags = getopt32(argv, "de:*f:ilnpqrsvo:FWR", |
584 | &exclude_dir, &input_filename, &out_filename, &verbose); | 584 | &exclude_dir, &input_filename, &out_filename, &verbose); |
585 | } else { /* setfiles */ | 585 | } else { /* setfiles */ |
586 | flags = getopt32(argv, "de:f:ilnpqr:svo:FW" | 586 | flags = getopt32(argv, "de:*f:ilnpqr:svo:FW" |
587 | IF_FEATURE_SETFILES_CHECK_OPTION("c:"), | 587 | IF_FEATURE_SETFILES_CHECK_OPTION("c:"), |
588 | &exclude_dir, &input_filename, &rootpath, &out_filename, | 588 | &exclude_dir, &input_filename, &rootpath, &out_filename, |
589 | IF_FEATURE_SETFILES_CHECK_OPTION(&policyfile,) | 589 | IF_FEATURE_SETFILES_CHECK_OPTION(&policyfile,) |
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index a119bdeae..ae0840bff 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -342,7 +342,7 @@ enum { | |||
342 | #define OPTION_STR "m:nO:l:S" \ | 342 | #define OPTION_STR "m:nO:l:S" \ |
343 | IF_FEATURE_ROTATE_LOGFILE("s:" ) \ | 343 | IF_FEATURE_ROTATE_LOGFILE("s:" ) \ |
344 | IF_FEATURE_ROTATE_LOGFILE("b:" ) \ | 344 | IF_FEATURE_ROTATE_LOGFILE("b:" ) \ |
345 | IF_FEATURE_REMOTE_LOG( "R:" ) \ | 345 | IF_FEATURE_REMOTE_LOG( "R:*") \ |
346 | IF_FEATURE_REMOTE_LOG( "L" ) \ | 346 | IF_FEATURE_REMOTE_LOG( "L" ) \ |
347 | IF_FEATURE_IPC_SYSLOG( "C::") \ | 347 | IF_FEATURE_IPC_SYSLOG( "C::") \ |
348 | IF_FEATURE_SYSLOGD_DUP( "D" ) \ | 348 | IF_FEATURE_SYSLOGD_DUP( "D" ) \ |
@@ -1108,8 +1108,8 @@ int syslogd_main(int argc UNUSED_PARAM, char **argv) | |||
1108 | 1108 | ||
1109 | INIT_G(); | 1109 | INIT_G(); |
1110 | 1110 | ||
1111 | /* No non-option params, -R can occur multiple times */ | 1111 | /* No non-option params */ |
1112 | opt_complementary = "=0" IF_FEATURE_REMOTE_LOG(":R::"); | 1112 | opt_complementary = "=0"; |
1113 | opts = getopt32(argv, OPTION_STR, OPTION_PARAM); | 1113 | opts = getopt32(argv, OPTION_STR, OPTION_PARAM); |
1114 | #if ENABLE_FEATURE_REMOTE_LOG | 1114 | #if ENABLE_FEATURE_REMOTE_LOG |
1115 | while (remoteAddrList) { | 1115 | while (remoteAddrList) { |
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c index e543446c1..50e8a0fce 100644 --- a/util-linux/dmesg.c +++ b/util-linux/dmesg.c | |||
@@ -34,8 +34,7 @@ int dmesg_main(int argc UNUSED_PARAM, char **argv) | |||
34 | OPT_r = 1 << 3 | 34 | OPT_r = 1 << 3 |
35 | }; | 35 | }; |
36 | 36 | ||
37 | opt_complementary = "s+:n+"; /* numeric */ | 37 | opts = getopt32(argv, "cs:+n:+r", &len, &level); |
38 | opts = getopt32(argv, "cs:n:r", &len, &level); | ||
39 | if (opts & OPT_n) { | 38 | if (opts & OPT_n) { |
40 | if (klogctl(8, NULL, (long) level)) | 39 | if (klogctl(8, NULL, (long) level)) |
41 | bb_perror_msg_and_die("klogctl"); | 40 | bb_perror_msg_and_die("klogctl"); |
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index f49ce95a4..6391f9bd9 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -2919,8 +2919,7 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
2919 | 2919 | ||
2920 | close_dev_fd(); /* needed: fd 3 must not stay closed */ | 2920 | close_dev_fd(); /* needed: fd 3 must not stay closed */ |
2921 | 2921 | ||
2922 | opt_complementary = "b+:C+:H+:S+"; /* numeric params */ | 2922 | opt = getopt32(argv, "b:+C:+H:+lS:+u" IF_FEATURE_FDISK_BLKSIZE("s"), |
2923 | opt = getopt32(argv, "b:C:H:lS:u" IF_FEATURE_FDISK_BLKSIZE("s"), | ||
2924 | §or_size, &user_cylinders, &user_heads, &user_sectors); | 2923 | §or_size, &user_cylinders, &user_heads, &user_sectors); |
2925 | argv += optind; | 2924 | argv += optind; |
2926 | if (opt & OPT_b) { | 2925 | if (opt & OPT_b) { |
diff --git a/util-linux/getopt.c b/util-linux/getopt.c index b9dadf13c..18d490987 100644 --- a/util-linux/getopt.c +++ b/util-linux/getopt.c | |||
@@ -397,8 +397,7 @@ int getopt_main(int argc, char **argv) | |||
397 | opt = getopt32(argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg); | 397 | opt = getopt32(argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg); |
398 | #else | 398 | #else |
399 | applet_long_options = getopt_longopts; | 399 | applet_long_options = getopt_longopts; |
400 | opt_complementary = "l::"; | 400 | opt = getopt32(argv, "+o:n:qQs:Tual:*", |
401 | opt = getopt32(argv, "+o:n:qQs:Tual:", | ||
402 | &optstr, &name, &s_arg, &l_arg); | 401 | &optstr, &name, &s_arg, &l_arg); |
403 | /* Effectuate the read options for the applet itself */ | 402 | /* Effectuate the read options for the applet itself */ |
404 | while (l_arg) { | 403 | while (l_arg) { |
diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c index f91a0b4bf..413e7aa15 100644 --- a/util-linux/mkfs_ext2.c +++ b/util-linux/mkfs_ext2.c | |||
@@ -244,8 +244,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
244 | 244 | ||
245 | // using global "option_mask32" instead of local "opts": | 245 | // using global "option_mask32" instead of local "opts": |
246 | // we are register starved here | 246 | // we are register starved here |
247 | opt_complementary = "-1:b+:i+:I+:m+"; | 247 | /*opts =*/ getopt32(argv, "cl:b:+f:i:+I:+J:G:N:m:+o:g:L:M:O:r:E:T:U:jnqvFS", |
248 | /*opts =*/ getopt32(argv, "cl:b:f:i:I:J:G:N:m:o:g:L:M:O:r:E:T:U:jnqvFS", | ||
249 | /*lbfi:*/ NULL, &bs, NULL, &bpi, | 248 | /*lbfi:*/ NULL, &bs, NULL, &bpi, |
250 | /*IJGN:*/ &user_inodesize, NULL, NULL, NULL, | 249 | /*IJGN:*/ &user_inodesize, NULL, NULL, NULL, |
251 | /*mogL:*/ &reserved_percent, NULL, NULL, &label, | 250 | /*mogL:*/ &reserved_percent, NULL, NULL, &label, |
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c index 88d797584..aaabf8453 100644 --- a/util-linux/mkfs_minix.c +++ b/util-linux/mkfs_minix.c | |||
@@ -604,8 +604,7 @@ int mkfs_minix_main(int argc UNUSED_PARAM, char **argv) | |||
604 | bb_error_msg_and_die("bad inode size"); | 604 | bb_error_msg_and_die("bad inode size"); |
605 | #endif | 605 | #endif |
606 | 606 | ||
607 | opt_complementary = "n+"; /* -n N */ | 607 | opt = getopt32(argv, "ci:l:n:+v", &str_i, &listfile, &G.namelen); |
608 | opt = getopt32(argv, "ci:l:n:v", &str_i, &listfile, &G.namelen); | ||
609 | argv += optind; | 608 | argv += optind; |
610 | //if (opt & 1) -c | 609 | //if (opt & 1) -c |
611 | if (opt & 2) G.req_nr_inodes = xatoul(str_i); // -i | 610 | if (opt & 2) G.req_nr_inodes = xatoul(str_i); // -i |
diff --git a/util-linux/mkfs_reiser.c b/util-linux/mkfs_reiser.c index 56c8f0ab5..0a31ee44f 100644 --- a/util-linux/mkfs_reiser.c +++ b/util-linux/mkfs_reiser.c | |||
@@ -169,8 +169,8 @@ int mkfs_reiser_main(int argc UNUSED_PARAM, char **argv) | |||
169 | 169 | ||
170 | // using global "option_mask32" instead of local "opts": | 170 | // using global "option_mask32" instead of local "opts": |
171 | // we are register starved here | 171 | // we are register starved here |
172 | opt_complementary = "-1:b+"; | 172 | opt_complementary = "-1"; |
173 | /*opts =*/ getopt32(argv, "b:j:s:o:t:B:h:u:l:fqd", | 173 | /*opts =*/ getopt32(argv, "b:+j:s:o:t:B:h:u:l:fqd", |
174 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &label); | 174 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &label); |
175 | argv += optind; // argv[0] -- device | 175 | argv += optind; // argv[0] -- device |
176 | 176 | ||
diff --git a/util-linux/mount.c b/util-linux/mount.c index cef4f7415..13590ceb4 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -268,7 +268,7 @@ enum { | |||
268 | }; | 268 | }; |
269 | 269 | ||
270 | 270 | ||
271 | #define OPTION_STR "o:t:rwanfvsiO:" IF_FEATURE_MOUNT_OTHERTAB("T:") | 271 | #define OPTION_STR "o:*t:rwanfvsiO:" IF_FEATURE_MOUNT_OTHERTAB("T:") |
272 | enum { | 272 | enum { |
273 | OPT_o = (1 << 0), | 273 | OPT_o = (1 << 0), |
274 | OPT_t = (1 << 1), | 274 | OPT_t = (1 << 1), |
@@ -2167,7 +2167,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
2167 | 2167 | ||
2168 | // Parse remaining options | 2168 | // Parse remaining options |
2169 | // Max 2 params; -o is a list, -v is a counter | 2169 | // Max 2 params; -o is a list, -v is a counter |
2170 | opt_complementary = "?2o::" IF_FEATURE_MOUNT_VERBOSE("vv"); | 2170 | opt_complementary = "?2" IF_FEATURE_MOUNT_VERBOSE("vv"); |
2171 | opt = getopt32(argv, OPTION_STR, &lst_o, &fstype, &O_optmatch | 2171 | opt = getopt32(argv, OPTION_STR, &lst_o, &fstype, &O_optmatch |
2172 | IF_FEATURE_MOUNT_OTHERTAB(, &fstabname) | 2172 | IF_FEATURE_MOUNT_OTHERTAB(, &fstabname) |
2173 | IF_FEATURE_MOUNT_VERBOSE(, &verbose)); | 2173 | IF_FEATURE_MOUNT_VERBOSE(, &verbose)); |
diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c index a64540464..345b676ba 100644 --- a/util-linux/readprofile.c +++ b/util-linux/readprofile.c | |||
@@ -99,8 +99,7 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv) | |||
99 | proFile = defaultpro; | 99 | proFile = defaultpro; |
100 | mapFile = defaultmap; | 100 | mapFile = defaultmap; |
101 | 101 | ||
102 | opt_complementary = "M+"; /* -M N */ | 102 | opt = getopt32(argv, "M:+m:p:nabsirv", &multiplier, &mapFile, &proFile); |
103 | opt = getopt32(argv, "M:m:p:nabsirv", &multiplier, &mapFile, &proFile); | ||
104 | 103 | ||
105 | if (opt & (OPT_M|OPT_r)) { /* mult or reset, or both */ | 104 | if (opt & (OPT_M|OPT_r)) { /* mult or reset, or both */ |
106 | int fd, to_write; | 105 | int fd, to_write; |