In many cases, this aqllows to drop use of opt_complementary.
Approximately -400 bytes:
function old new delta
getopt32 1423 1502 +79
opt_string 17 18 +1
OPT_STR 24 25 +1
uniq_main 416 406 -10
timeout_main 279 269 -10
sulogin_main 270 260 -10
readprofile_main 1825 1815 -10
ps_main 543 533 -10
pidof_main 245 235 -10
pgrep_main 611 601 -10
od_main 2600 2590 -10
mkfs_minix_main 2684 2674 -10
mkfs_ext2_main 2603 2593 -10
microcom_main 712 702 -10
makemime_main 315 305 -10
ionice_main 282 272 -10
inetd_main 2074 2064 -10
ifplugd_main 1144 1134 -10
halt_main 353 343 -10
getopt_main 636 626 -10
fdisk_main 2854 2844 -10
env_main 206 196 -10
dmesg_main 319 309 -10
conspy_main 1214 1204 -10
awk_main 981 971 -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/22 up/down: 81/-220) Total: -139 bytes
text data bss dec hex filename
919373 906 14060 934339 e41c3 busybox_old
918969 906 14060 933935 e402f busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
/* Prepend '-' to the first argument if required */
opt_complementary = "--:" // first arg is options
"tt:vv:" // count -t,-v
- IF_FEATURE_TAR_FROM("X::T::") // cumulative lists
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
"\xff::" // --exclude=PATTERN is a list
#endif
#endif
opt = getopt32(argv,
"txC:f:Oopvk"
- IF_FEATURE_TAR_CREATE( "ch" )
- IF_FEATURE_SEAMLESS_BZ2( "j" )
- IF_FEATURE_SEAMLESS_LZMA("a" )
- IF_FEATURE_TAR_FROM( "T:X:")
- IF_FEATURE_SEAMLESS_GZ( "z" )
- IF_FEATURE_SEAMLESS_XZ( "J" )
- IF_FEATURE_SEAMLESS_Z( "Z" )
+ IF_FEATURE_TAR_CREATE( "ch" )
+ IF_FEATURE_SEAMLESS_BZ2( "j" )
+ IF_FEATURE_SEAMLESS_LZMA("a" )
+ IF_FEATURE_TAR_FROM( "T:*X:*")
+ IF_FEATURE_SEAMLESS_GZ( "z" )
+ IF_FEATURE_SEAMLESS_XZ( "J" )
+ IF_FEATURE_SEAMLESS_Z( "Z" )
IF_FEATURE_TAR_NOPRESERVE_TIME("m")
IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
, &base_dir // -C dir
* 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:d+";
- opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth);
+ 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);
argv += optind;
if (opt & OPT_h_for_humans) {
G.disp_unit = 0;
G.disp_unit = 1024;
}
#else
- opt_complementary = "H-L:L-H:s-d:d-s:d+";
- opt = getopt32(argv, "aHkLsx" "d:" "lc", &G.max_print_depth);
+ opt_complementary = "H-L:L-H:s-d:d-s";
+ opt = getopt32(argv, "aHkLsx" "d:+" "lc", &G.max_print_depth);
argv += optind;
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
if (opt & OPT_k_kbytes) {
unsigned opts;
llist_t *unset_env = NULL;
- opt_complementary = "u::";
#if ENABLE_FEATURE_ENV_LONG_OPTIONS
applet_long_options = env_longopts;
#endif
- opts = getopt32(argv, "+iu:", &unset_env);
+ opts = getopt32(argv, "+iu:+", &unset_env);
argv += optind;
if (argv[0] && LONE_DASH(argv[0])) {
opts |= 1;
};
#define OD_GETOPT32() getopt32(argv, \
- "A:N:abcdfhij:lot:vxsS:w::", \
+ "A:N:abcdfhij:lot:*vxsS:w:+:", \
/* -w with optional param */ \
/* -S was -s and also had optional parameter */ \
/* but in coreutils 6.3 it was renamed and now has */ \
address_pad_len_char = '7';
/* Parse command line */
- opt_complementary = "w+:t::"; /* -w N, -t is a list */
#if ENABLE_LONG_OPTS
applet_long_options = od_longopts;
#endif
*/
/* These are sort types */
-static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:t:";
+static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:*t:";
enum {
FLAG_n = 1, /* Numeric sort */
FLAG_g = 2, /* Sort using strtod() */
/* 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 */
- "k::"; /* -k takes list */
+ 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);
/* global b strips leading and trailing spaces */
if (opts & FLAG_b)
setup_common_bufsiz();
- opt_complementary = "?2:a+"; /* max 2 args; -a N */
- opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len);
+ opt_complementary = "?2"; /* max 2 args; -a N */
+ opt = getopt32(argv, "l:b:a:+", &count_p, &count_p, &suffix_len);
if (opt & SPLIT_OPT_l)
cnt = XATOOFF(count_p);
#endif
/* -s NUM, -F imlies -f */
- IF_FEATURE_FANCY_TAIL(opt_complementary = "s+:Ff";)
- opt = getopt32(argv, "fc:n:" IF_FEATURE_FANCY_TAIL("qs:vF"),
+ 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));
#define FOLLOW (opt & 0x1)
#define COUNT_BYTES (opt & 0x2)
skip_fields = skip_chars = 0;
max_chars = INT_MAX;
- opt_complementary = "f+:s+:w+";
- opt = getopt32(argv, "cduf:s:w:", &skip_fields, &skip_chars, &max_chars);
+ opt = getopt32(argv, "cduf:+s:+w:+", &skip_fields, &skip_chars, &max_chars);
argv += optind;
input_filename = argv[0];
applet_long_options = runparts_longopts;
#endif
/* We require exactly one argument: the directory name */
- opt_complementary = "=1:a::";
- getopt32(argv, "a:u:", &arg_list, &umask_p);
+ opt_complementary = "=1";
+ getopt32(argv, "a:*u:", &arg_list, &umask_p);
umask(xstrtou_range(umask_p, 8, 0, 07777));
#define OPTSTR_AWK \
- "F:v:f:" \
- IF_FEATURE_AWK_GNU_EXTENSIONS("e:") \
+ "F:v:*f:*" \
+ IF_FEATURE_AWK_GNU_EXTENSIONS("e:*") \
"W:"
-#define OPTCOMPLSTR_AWK \
- "v::f::" \
- IF_FEATURE_AWK_GNU_EXTENSIONS("e::")
enum {
OPTBIT_F, /* define field separator */
OPTBIT_v, /* define variable */
*s1 = '=';
}
}
- opt_complementary = OPTCOMPLSTR_AWK;
opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL);
argv += optind;
argc -= optind;
INIT_G();
/* exactly 2 params; collect multiple -L <label>; -U N */
- opt_complementary = "=2:L::U+";
+ opt_complementary = "=2";
#if ENABLE_FEATURE_DIFF_LONG_OPTIONS
applet_long_options = diff_longopts;
#endif
- getopt32(argv, "abdiL:NqrsS:tTU:wupBE",
+ getopt32(argv, "abdiL:*NqrsS:tTU:+wupBE",
&L_arg, &s_start, &opt_U_context);
argv += optind;
while (L_arg)
/* do normal option parsing */
opt_e = opt_f = NULL;
opt_i = NULL;
- opt_complementary = "e::f::" /* can occur multiple times */
- "nn"; /* count -n */
+ opt_complementary = "nn"; /* count -n */
IF_LONG_OPTS(applet_long_options = sed_longopts);
* GNU sed 4.2.1 mentions it in neither --help
* nor manpage, but does recognize it.
*/
- opt = getopt32(argv, "i::rEne:f:", &opt_i, &opt_e, &opt_f,
+ opt = getopt32(argv, "i::rEne:*f:*", &opt_i, &opt_e, &opt_f,
&G.be_quiet); /* counter for -n */
//argc -= optind;
argv += optind;
//usage:#define fgrep_full_usage ""
#define OPTSTR_GREP \
- "lnqvscFiHhe:f:Lorm:wx" \
- IF_FEATURE_GREP_CONTEXT("A:B:C:") \
+ "lnqvscFiHhe:*f:*Lorm:+wx" \
+ IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \
IF_FEATURE_GREP_EGREP_ALIAS("E") \
IF_EXTRA_COMPAT("z") \
"aI"
#if ENABLE_FEATURE_GREP_CONTEXT
/* -H unsets -h; -C unsets -A,-B; -e,-f are lists;
* -m,-A,-B,-C have numeric param */
- opt_complementary = "H-h:C-AB:e::f::m+:A+:B+:C+";
+ opt_complementary = "H-h:C-AB";
opts = getopt32(argv,
OPTSTR_GREP,
&pattern_head, &fopt, &max_matches,
#else
/* with auto sanity checks */
/* -H unsets -h; -c,-q or -l unset -n; -e,-f are lists; -m N */
- opt_complementary = "H-h:c-n:q-n:l-n:e::f::m+";
+ opt_complementary = "H-h:c-n:q-n:l-n:";
getopt32(argv, OPTSTR_GREP,
&pattern_head, &fopt, &max_matches);
#endif
continue;
/* Parse and handle arguments */
- opt_complementary = "d+"; /* -d N */
/* We support -w even if !ENABLE_FEATURE_WTMP,
* in order to not break scripts.
* -i (shut down network interfaces) is ignored.
*/
- flags = getopt32(argv, "d:nfwi", &delay);
+ flags = getopt32(argv, "d:+nfwi", &delay);
sleep(delay);
uint32_t
getopt32(char **argv, const char *applet_opts, ...)
- The command line options must be declared in const char
- *applet_opts as a string of chars, for example:
-
- flags = getopt32(argv, "rnug");
+ The command line options are passed as the applet_opts string.
If one of the given options is found, a flag value is added to
- the return value (an unsigned long).
+ the return value.
The flag value is determined by the position of the char in
- applet_opts string. For example, in the above case:
+ applet_opts string. For example:
flags = getopt32(argv, "rnug");
- "r" will add 1 (bit 0)
- "n" will add 2 (bit 1)
- "u" will add 4 (bit 2)
- "g" will add 8 (bit 3)
+ "r" will set 1 (bit 0)
+ "n" will set 2 (bit 1)
+ "u" will set 4 (bit 2)
+ "g" will set 8 (bit 3)
and so on. You can also look at the return value as a bit
field and each option sets one bit.
(options and their parameters will be moved into argv[]
positions prior to argv[optind]).
- ":" If one of the options requires an argument, then add a ":"
+ "o:" If one of the options requires an argument, then add a ":"
after the char in applet_opts and provide a pointer to store
the argument. For example:
&pointer_to_arg_for_a, &pointer_to_arg_for_b,
&pointer_to_arg_for_c, &pointer_to_arg_for_d);
- The type of the pointer (char* or llist_t*) may be controlled
- by the "::" special separator that is set in the external string
- opt_complementary (see below for more info).
+ The type of the pointer may be controlled by "o::" or "o+" in
+ the external string opt_complementary (see below for more info).
- "::" If option can have an *optional* argument, then add a "::"
+ "o::" If option can have an *optional* argument, then add a "::"
after its char in applet_opts and provide a pointer to store
the argument. Note that optional arguments _must_
immediately follow the option: -oparam, not -o param.
+ "o:+" This means that the parameter for this option is a nonnegative integer.
+ It will be processed with xatoi_positive() - allowed range
+ is 0..INT_MAX.
+
+ int param; // "unsigned param;" will also work
+ getopt32(argv, "p:+", ¶m);
+
+ "o:*" This means that the option can occur multiple times. Each occurrence
+ will be saved as a llist_t element instead of char*.
+
+ For example:
+ The grep applet can have one or more "-e pattern" arguments.
+ In this case you should use getopt32() as follows:
+
+ llist_t *patterns = NULL;
+
+ (this pointer must be initializated to NULL if the list is empty
+ as required by llist_add_to_end(llist_t **old_head, char *new_item).)
+
+ getopt32(argv, "e:*", &patterns);
+
+ $ grep -e user -e root /etc/passwd
+ root:x:0:0:root:/root:/bin/bash
+ user:x:500:500::/home/user:/bin/bash
+
"+" If the first character in the applet_opts string is a plus,
then option processing will stop as soon as a non-option is
encountered in the argv array. Useful for applets like env
This struct allows you to define long options:
static const char applet_longopts[] ALIGN1 =
- //"name\0" has_arg val
+ //"name\0" has_arg val
"verbose\0" No_argument "v"
;
applet_long_options = applet_longopts;
The last member of struct option (val) typically is set to
matching short option from applet_opts. If there is no matching
char in applet_opts, then:
- - return bit have next position after short options
+ - return bit has next position after short options
- if has_arg is not "No_argument", use ptr for arg also
- opt_complementary affects it too
llist_t *my_b = NULL;
int verbose_level = 0;
- opt_complementary = "vv:b::b-c:c-b";
- f = getopt32(argv, "vb:c", &my_b, &verbose_level);
+ opt_complementary = "vv:b-c:c-b";
+ f = getopt32(argv, "vb:*c", &my_b, &verbose_level);
if (f & 2) // -c after -b unsets -b flag
while (my_b) dosomething_with(llist_pop(&my_b));
if (my_b) // but llist is stored if -b is specified
"x--x" Variation of the above, it means that -x option should occur
at most once.
- "a+" A plus after a char in opt_complementary means that the parameter
+ "o+" A plus after a char in opt_complementary means that the parameter
for this option is a nonnegative integer. It will be processed
with xatoi_positive() - allowed range is 0..INT_MAX.
opt_complementary = "p+";
getopt32(argv, "p:", ¶m);
- "a::" A double colon after a char in opt_complementary means that the
+ "o::" A double colon after a char in opt_complementary means that the
option can occur multiple times. Each occurrence will be saved as
a llist_t element instead of char*.
as required by llist_add_to_end(llist_t **old_head, char *new_item).)
opt_complementary = "e::";
-
getopt32(argv, "e:", &patterns);
+
$ grep -e user -e root /etc/passwd
root:x:0:0:root:/root:/bin/bash
user:x:500:500::/home/user:/bin/bash
+ "o+" and "o::" can be handled by "o:+" and "o:*" specifiers
+ in option string (and it is preferred), but this does not work
+ for "long options only" cases, such as tar --exclude=PATTERN,
+ wget --header=HDR cases.
+
"a?b" A "?" between an option and a group of options means that
at least one of them is required to occur if the first option
occurs in preceding command line arguments.
va_start(p, applet_opts);
- c = 0;
on_off = complementary;
memset(on_off, 0, sizeof(complementary));
+ applet_opts = strcpy(alloca(strlen(applet_opts) + 1), applet_opts);
+
/* skip bbox extension */
first_char = applet_opts[0];
if (first_char == '!')
s = (const unsigned char *)applet_opts;
if (*s == '+' || *s == '-')
s++;
+ c = 0;
while (*s) {
if (c >= 32)
break;
on_off->switch_on = (1 << c);
if (*++s == ':') {
on_off->optarg = va_arg(p, void **);
+ if (s[1] == '+' || s[1] == '*') {
+ /* 'o:+' or 'o:*' */
+ on_off->param_type = (s[1] == '+') ?
+ PARAM_INT : PARAM_LIST;
+ overlapping_strcpy((char*)s + 1, (char*)s + 2);
+ }
+ /* skip possible 'o::' (or 'o:+:' !) */
while (*++s == ':')
continue;
}
applet_long_options = NULL;
}
#endif /* ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG */
+
for (s = (const unsigned char *)opt_complementary; s && *s; s++) {
t_complementary *pair;
unsigned *pair_switch;
int mintokens = 0, ntokens = 128;
unsigned noout;
- opt_complementary = "-1:n+:m+:f+";
- noout = 1 & getopt32(argv, "xn:m:d:f:", &ntokens, &mintokens, &delims, &flags);
+ opt_complementary = "-1";
+ noout = 1 & getopt32(argv, "xn:+m:+d:f:+", &ntokens, &mintokens, &delims, &flags);
//argc -= optind;
argv += optind;
opt_m = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO;
opt_S = NULL;
/* at most two non-option arguments; -P NUM */
- opt_complementary = "?2:P+";
- getopt32(argv, "sP:S:m:a:", &fd, &opt_S, &opt_m, &opt_m);
+ opt_complementary = "?2";
+ getopt32(argv, "sP:+S:m:a:", &fd, &opt_S, &opt_m, &opt_m);
argv += optind;
/* have no idea how to handle -s... */
//usage: "\n"
//usage: "\nBAUD_RATE of 0 leaves it unchanged"
-static const char opt_string[] ALIGN1 = "I:LH:f:hil:mt:wn";
+static const char opt_string[] ALIGN1 = "I:LH:f:hil:mt:+wn";
#define F_INITSTRING (1 << 0) /* -I */
#define F_LOCAL (1 << 1) /* -L */
#define F_FAKEHOST (1 << 2) /* -H */
char *ts;
int flags;
- opt_complementary = "-2:t+"; /* at least 2 args; -t N */
+ opt_complementary = "-2"; /* at least 2 args; -t N */
flags = getopt32(argv, opt_string,
&G.initstring, &G.fakehost, &G.issue,
&G.login, &G.timeout
logmode = LOGMODE_BOTH;
openlog(applet_name, 0, LOG_AUTH);
- opt_complementary = "t+"; /* -t N */
- getopt32(argv, "t:", &timeout);
+ getopt32(argv, "t:+", &timeout);
argv += optind;
if (argv[0]) {
INIT_G();
// parse options
- opt_complementary = "a::";
opts = getopt32(argv,
- "c:e:o:C:N:a:", // "m:j:",
+ "c:e:o:C:N:a:*", // "m:j:",
&content_type, NULL, &opt_output, &G.opt_charset, NULL, &opt_headers //, NULL, NULL
);
//argc -= optind;
INIT_G();
// parse options
- opt_complementary = "-1:dd:t+:R+:L+:H+";
+ opt_complementary = "-1:dd";
opts = getopt32(argv,
- "bdmVcasTkt:" "R:Z:L:H:" IF_FEATURE_POPMAILDIR_DELIVERY("M:F:"),
+ "bdmVcasTkt:+" "R:+Z:L:+H:+" IF_FEATURE_POPMAILDIR_DELIVERY("M:F:"),
&timeout, NULL, NULL, NULL, &opt_nlines
IF_FEATURE_POPMAILDIR_DELIVERY(, &delivery, &delivery) // we treat -M and -F the same
);
// parse options
// N.B. only -x and -X are supported so far
- opt_complementary = "x--X:X--x" IF_FEATURE_REFORMIME_COMPAT(":m::");
+ opt_complementary = "x--X:X--x";
opts = getopt32(argv,
- "x:X" IF_FEATURE_REFORMIME_COMPAT("deis:r:c:m:h:o:O:"),
+ "x:X" IF_FEATURE_REFORMIME_COMPAT("deis:r:c:m:*h:o:O:"),
&opt_prefix
IF_FEATURE_REFORMIME_COMPAT(, NULL, NULL, &G.opt_charset, NULL, NULL, NULL, NULL)
);
// parse options
// -v is a counter, -H and -S are mutually exclusive, -a is a list
- opt_complementary = "vv:w+:H--S:S--H:a::";
+ opt_complementary = "vv:H--S:S--H";
// N.B. since -H and -S are mutually exclusive they do not interfere in opt_connect
// -a is for ssmtp (http://downloads.openwrt.org/people/nico/man/man8/ssmtp.8.html) compatibility,
// it is still under development.
- opts = getopt32(argv, "tf:o:iw:H:S:a::v", &opt_from, NULL,
+ opts = getopt32(argv, "tf:o:iw:+H:S:a:*:v", &opt_from, NULL,
&timeout, &opt_connect, &opt_connect, &list, &verbose);
//argc -= optind;
argv += optind;
INIT_G();
strcpy(G.vcsa_name, DEV_VCSA);
- opt_complementary = "x+:y+"; // numeric params
- opts = getopt32(argv, "vcQsndfFx:y:", &G.x, &G.y);
+ // numeric params
+ opts = getopt32(argv, "vcQsndfFx:+y:+", &G.x, &G.y);
argv += optind;
ttynum = 0;
if (argv[0]) {
};
/* Numeric params */
- opt_complementary = "n+:c+:p+";
/* '+': stop at first non-option */
- opt = getopt32(argv, "+n:c:p:", &pri, &ioclass, &pid);
+ opt = getopt32(argv, "+n:+c:+p:+", &pri, &ioclass, &pid);
argv += optind;
if (opt & OPT_c) {
unsigned opts;
// fetch options
- opt_complementary = "=1:s+:d+:t+"; // exactly one arg, numeric options
- opts = getopt32(argv, "Xs:d:t:", &speed, &delay, &timeout);
+ opts = getopt32(argv, "Xs:+d:+t:+", &speed, &delay, &timeout);
// argc -= optind;
argv += optind;
/* -p option is not documented, it is needed to support NOMMU. */
/* -t SECONDS; -p PARENT_PID */
- opt_complementary = "t+" USE_FOR_NOMMU(":p+");
/* '+': stop at first non-option */
- getopt32(argv, "+s:t:" USE_FOR_NOMMU("p:"), &opt_s, &timeout, &parent);
+ getopt32(argv, "+s:t:+" USE_FOR_NOMMU("p:+"), &opt_s, &timeout, &parent);
/*argv += optind; - no, wait for bb_daemonize_or_rexec! */
signo = get_signum(opt_s);
if (signo < 0)
#define OPTION_a (1 << 5)
#define OPTION_t (1 << 6)
if (do_mkvol) {
- opt_complementary = "-1:d+:n+:a+:O+";
- opts = getopt32(argv, "md:n:N:s:a:t:O:",
+ opt_complementary = "-1";
+ opts = getopt32(argv, "md:+n:+N:s:a:+t:O:+",
&dev_num, &vol_id,
&vol_name, &size_bytes_str, &alignment, &type,
&vid_hdr_offset
opts = getopt32(argv, "s:at", &size_bytes_str);
opts *= OPTION_s;
} else {
- opt_complementary = "-1:m+:d+:n+:a+";
- opts = getopt32(argv, "m:d:n:N:s:a:t:",
+ opt_complementary = "-1";
+ opts = getopt32(argv, "m:+d:+n:+N:s:a:+t:",
&mtd_num, &dev_num, &vol_id,
&vol_name, &size_bytes_str, &alignment, &type
);
/* Dad also sets quit_on_reply.
* Advert also sets unsolicited.
*/
- opt_complementary = "=1:Df:AU:c+";
- opt = getopt32(argv, "DUAqfbc:w:I:s:",
+ opt_complementary = "=1:Df:AU";
+ opt = getopt32(argv, "DUAqfbc:+w:I:s:",
&count, &str_timeout, &device, &source);
if (opt & 0x80) /* -w: timeout */
timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000 + 500000;
abs_timeout = 1 * 60 * 60;
verbose_S = 0;
G.timeout = 2 * 60;
- opt_complementary = "t+:T+:vv:SS";
+ opt_complementary = "vv:SS";
#if BB_MMU
- opts = getopt32(argv, "vS" IF_FEATURE_FTP_WRITE("w") "t:T:", &G.timeout, &abs_timeout, &G.verbose, &verbose_S);
+ opts = getopt32(argv, "vS" IF_FEATURE_FTP_WRITE("w") "t:+T:+", &G.timeout, &abs_timeout, &G.verbose, &verbose_S);
#else
- opts = getopt32(argv, "l1AvS" IF_FEATURE_FTP_WRITE("w") "t:T:", &G.timeout, &abs_timeout, &G.verbose, &verbose_S);
+ opts = getopt32(argv, "l1AvS" IF_FEATURE_FTP_WRITE("w") "t:+T:+", &G.timeout, &abs_timeout, &G.verbose, &verbose_S);
if (opts & (OPT_l|OPT_1)) {
/* Our secret backdoor to ls */
/* TODO: pass --group-directories-first? would be nice, but ls doesn't do that yet */
#endif
};
#if ENABLE_FEATURE_PIDFILE
-# define OPTION_STR "+ansfFi:r:It:u:d:m:pqlx:Mk"
+# define OPTION_STR "+ansfFi:r:It:+u:+d:+m:pqlx:Mk"
#else
-# define OPTION_STR "+ansfFi:r:It:u:d:m:pqlx:M"
+# define OPTION_STR "+ansfFi:r:It:+u:+d:+m:pqlx:M"
#endif
enum { // interface status
INIT_G();
- opt_complementary = "t+:u+:d+";
opts = getopt32(argv, OPTION_STR,
&G.iface, &G.script_name, &G.poll_time, &G.delay_up,
&G.delay_down, &G.api_mode, &G.extra_arg);
if (real_uid != 0) /* run by non-root user */
config_filename = NULL;
- opt_complementary = "R+:q+"; /* -q N, -R N */
- opt = getopt32(argv, "R:feq:", &max_concurrency, &global_queuelen);
+ /* -q N, -R N */
+ opt = getopt32(argv, "R:+feq:+", &max_concurrency, &global_queuelen);
argv += optind;
//argc -= optind;
if (argv[0])
e_found:
// -g -G -t -r deleted, unimplemented -a deleted too
- opt_complementary = "?2:vv:ll:w+"; /* max 2 params; -v and -l are counters; -w N */
- getopt32(argv, "np:s:uvw:" IF_NC_SERVER("lk")
+ opt_complementary = "?2:vv:ll"; /* max 2 params; -v and -l are counters; -w N */
+ getopt32(argv, "np:s:uvw:+" IF_NC_SERVER("lk")
IF_NC_EXTRA("i:o:z"),
&str_p, &str_s, &o_wait
IF_NC_EXTRA(, &str_i, &str_o), &o_verbose IF_NC_SERVER(, &cnt_l));
/* Parse options */
peers = NULL;
- opt_complementary = "dd:p::wn" /* -d: counter; -p: list; -w implies -n */
+ opt_complementary = "dd:wn" /* -d: counter; -p: list; -w implies -n */
IF_FEATURE_NTPD_SERVER(":Il"); /* -I implies -l */
opts = getopt32(argv,
"nqNx" /* compat */
- "wp:S:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */
+ "wp:*S:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */
IF_FEATURE_NTPD_SERVER("I:") /* compat */
"d" /* compat */
"46aAbgL", /* compat, ignored */
/* Full(er) version */
-#define OPT_STRING ("qvc:s:t:w:W:I:np:4" IF_PING6("6"))
+#define OPT_STRING ("qvc:+s:t:+w:+W:+I:np:4" IF_PING6("6"))
enum {
OPT_QUIET = 1 << 0,
OPT_VERBOSE = 1 << 1,
INIT_G();
/* exactly one argument needed; -v and -q don't mix; -c NUM, -t NUM, -w NUM, -W NUM */
- opt_complementary = "=1:q--v:v--q:c+:t+:w+:W+";
+ opt_complementary = "=1:q--v:v--q";
opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &opt_ttl, &deadline, &timeout, &str_I, &str_p);
if (opt & OPT_s)
datalen = xatou16(str_s); // -s
tcp = (applet_name[0] == 't');
/* 3+ args, -i at most once, -p implies -h, -v is counter, -b N, -c N */
- opt_complementary = "-3:i--i:ph:vv:b+:c+";
+ opt_complementary = "-3:i--i:ph:vv";
#ifdef SSLSVD
- opts = getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:vU:/:Z:K:",
+ opts = getopt32(argv, "+c:+C:i:x:u:l:Eb:+hpt:vU:/:Z:K:",
&cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
&backlog, &str_t, &ssluser, &root, &cert, &key, &verbose
);
INIT_G();
/* -w NUM, and implies -F. -w and -i don't mix */
- IF_FEATURE_TELNETD_INETD_WAIT(opt_complementary = "wF:w+:i--w:w--i";)
+ IF_FEATURE_TELNETD_INETD_WAIT(opt_complementary = "wF:i--w:w--i";)
/* Even if !STANDALONE, we accept (and ignore) -i, thus people
* don't need to guess whether it's ok to pass -i to us */
opt = getopt32(argv, "f:l:Ki"
IF_FEATURE_TELNETD_STANDALONE("p:b:F")
- IF_FEATURE_TELNETD_INETD_WAIT("Sw:"),
+ IF_FEATURE_TELNETD_INETD_WAIT("Sw:+"),
&G.issuefile, &G.loginpath
IF_FEATURE_TELNETD_STANDALONE(, &opt_portnbr, &opt_bindaddr)
IF_FEATURE_TELNETD_INETD_WAIT(, &sec_linger)
#define OPT_STRING \
"FIlnrdvxt:i:m:p:q:s:w:z:f:" \
- IF_FEATURE_TRACEROUTE_SOURCE_ROUTE("g:") \
+ IF_FEATURE_TRACEROUTE_SOURCE_ROUTE("g:*") \
"4" IF_TRACEROUTE6("6")
enum {
OPT_DONT_FRAGMNT = (1 << 0), /* F */
INIT_G();
/* minimum 1 arg */
- opt_complementary = "-1:x-x" IF_FEATURE_TRACEROUTE_SOURCE_ROUTE(":g::");
+ opt_complementary = "-1:x-x";
op |= getopt32(argv, OPT_STRING
, &tos_str, &device, &max_ttl_str, &port_str, &nprobes_str
, &source, &waittime_str, &pausemsecs_str, &first_ttl_str
/* Parse command line */
/* O,x: list; -T,-t,-A take numeric param */
- opt_complementary = "O::x::T+:t+:A+" IF_UDHCP_VERBOSE(":vv") ;
+ IF_UDHCP_VERBOSE(opt_complementary = "vv";)
IF_LONG_OPTS(applet_long_options = udhcpc6_longopts;)
- opt = getopt32(argv, "i:np:qRr:s:T:t:SA:O:ox:f"
+ opt = getopt32(argv, "i:np:qRr:s:T:+t:+SA:+O:*ox:*f"
USE_FOR_MMU("b")
///IF_FEATURE_UDHCPC_ARPING("a")
IF_FEATURE_UDHCP_PORT("P:")
/* Parse command line */
/* O,x: list; -T,-t,-A take numeric param */
- opt_complementary = "O::x::T+:t+:A+" IF_UDHCP_VERBOSE(":vv") ;
+ IF_UDHCP_VERBOSE(opt_complementary = "vv";)
IF_LONG_OPTS(applet_long_options = udhcpc_longopts;)
- opt = getopt32(argv, "CV:H:h:F:i:np:qRr:s:T:t:SA:O:ox:fB"
+ opt = getopt32(argv, "CV:H:h:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fB"
USE_FOR_MMU("b")
IF_FEATURE_UDHCPC_ARPING("a::")
IF_FEATURE_UDHCP_PORT("P:")
applet_long_options = wget_longopts;
#endif
opt_complementary = "-1" /* at least one URL */
- IF_FEATURE_WGET_TIMEOUT(":T+") /* -T NUM */
IF_FEATURE_WGET_LONG_OPTIONS(":\xff::"); /* --header is a list */
- getopt32(argv, "csqO:P:Y:U:T:"
+ getopt32(argv, "csqO:P:Y:U:T:+"
/*ignored:*/ "t:"
/*ignored:*/ "n::"
/* wget has exactly four -n<letter> opts, all of which we can ignore:
int port = 43;
const char *host = "whois.iana.org";
- opt_complementary = "-1:p+";
- getopt32(argv, "ih:p:", &host, &port);
+ opt_complementary = "-1";
+ getopt32(argv, "ih:p:+", &host, &port);
argv += optind;
do {
/* Parse remaining options */
ppid2match = -1;
sid2match = -1;
- opt_complementary = "s+:P+"; /* numeric opts */
- opt = getopt32(argv, "vlfxons:P:", &sid2match, &ppid2match);
+ opt = getopt32(argv, "vlfxons:+P:+", &sid2match, &ppid2match);
argv += optind;
if (pkill && OPT_LIST) { /* -l: print the whole signal list */
unsigned opt;
#if ENABLE_FEATURE_PIDOF_OMIT
llist_t *omits = NULL; /* list of pids to omit */
- opt_complementary = "o::";
#endif
/* do unconditional option parsing */
opt = getopt32(argv, ""
IF_FEATURE_PIDOF_SINGLE ("s")
- IF_FEATURE_PIDOF_OMIT("o:", &omits));
+ IF_FEATURE_PIDOF_OMIT("o:*", &omits));
#if ENABLE_FEATURE_PIDOF_OMIT
/* fill omit list. */
* procps v3.2.7 supports -T and shows tids as SPID column,
* it also supports -L where it shows tids as LWP column.
*/
- opt_complementary = "o::";
- opt = getopt32(argv, "Zo:aAdefl"IF_FEATURE_SHOW_THREADS("T"), &opt_o);
+ opt = getopt32(argv, "Zo:*aAdefl"IF_FEATURE_SHOW_THREADS("T"), &opt_o);
if (opt_o) {
do {
parse_o(llist_pop(&opt_o));
xopen("/dev/null", O_RDONLY);
#endif
- opt_complementary = "-1:n+"; // at least one param; -n NUM
+ opt_complementary = "-1"; // at least one param; -n NUM
// "+": stop at first non-option (procps 3.x only)
- opt = getopt32(argv, "+dtn:", &period);
+ opt = getopt32(argv, "+dtn:+", &period);
argv += optind;
// watch from both procps 2.x and 3.x does concatenation. Example:
// FIXME: can we live with int-sized limits?
// can we live with 40000 days?
// if yes -> getopt converts strings to numbers for us
- opt_complementary = "-1:a+:c+:d+:f+:l+:m+:o+:p+:r+:s+:t+";
- opt = getopt32(argv, "+a:c:d:f:l:m:o:p:r:s:t:u:U:e:"
+ opt_complementary = "-1";
+ opt = getopt32(argv, "+a:+c:+d:+f:+l:+m:+o:+p:+r:+s:+t:+u:U:e:"
IF_CHPST("/:n:vP012"),
&limita, &limitc, &limitd, &limitf, &limitl,
&limitm, &limito, &limitp, &limitr, &limits, &limitt,
x = getenv("SVWAIT");
if (x) waitsec = xatou(x);
- opt_complementary = "w+:vv"; /* -w N, -v is a counter */
- getopt32(argv, "w:v", &waitsec, &verbose);
+ opt_complementary = "vv"; /* -w N, -v is a counter */
+ getopt32(argv, "w:+v", &waitsec, &verbose);
argv += optind;
action = *argv++;
if (!action || !*argv) bb_show_usage();
set_matchpathcon_flags(matchpathcon_flags);
- opt_complementary = "e::vv:v--p:p--v:v--q:q--v";
+ opt_complementary = "vv:v--p:p--v:v--q:q--v";
/* Option order must match OPT_x definitions! */
if (applet_name[0] == 'r') { /* restorecon */
- flags = getopt32(argv, "de:f:ilnpqrsvo:FWR",
+ flags = getopt32(argv, "de:*f:ilnpqrsvo:FWR",
&exclude_dir, &input_filename, &out_filename, &verbose);
} else { /* setfiles */
- flags = getopt32(argv, "de:f:ilnpqr:svo:FW"
+ flags = getopt32(argv, "de:*f:ilnpqr:svo:FW"
IF_FEATURE_SETFILES_CHECK_OPTION("c:"),
&exclude_dir, &input_filename, &rootpath, &out_filename,
IF_FEATURE_SETFILES_CHECK_OPTION(&policyfile,)
#define OPTION_STR "m:nO:l:S" \
IF_FEATURE_ROTATE_LOGFILE("s:" ) \
IF_FEATURE_ROTATE_LOGFILE("b:" ) \
- IF_FEATURE_REMOTE_LOG( "R:" ) \
+ IF_FEATURE_REMOTE_LOG( "R:*") \
IF_FEATURE_REMOTE_LOG( "L" ) \
IF_FEATURE_IPC_SYSLOG( "C::") \
IF_FEATURE_SYSLOGD_DUP( "D" ) \
INIT_G();
- /* No non-option params, -R can occur multiple times */
- opt_complementary = "=0" IF_FEATURE_REMOTE_LOG(":R::");
+ /* No non-option params */
+ opt_complementary = "=0";
opts = getopt32(argv, OPTION_STR, OPTION_PARAM);
#if ENABLE_FEATURE_REMOTE_LOG
while (remoteAddrList) {
OPT_r = 1 << 3
};
- opt_complementary = "s+:n+"; /* numeric */
- opts = getopt32(argv, "cs:n:r", &len, &level);
+ opts = getopt32(argv, "cs:+n:+r", &len, &level);
if (opts & OPT_n) {
if (klogctl(8, NULL, (long) level))
bb_perror_msg_and_die("klogctl");
close_dev_fd(); /* needed: fd 3 must not stay closed */
- opt_complementary = "b+:C+:H+:S+"; /* numeric params */
- opt = getopt32(argv, "b:C:H:lS:u" IF_FEATURE_FDISK_BLKSIZE("s"),
+ opt = getopt32(argv, "b:+C:+H:+lS:+u" IF_FEATURE_FDISK_BLKSIZE("s"),
§or_size, &user_cylinders, &user_heads, &user_sectors);
argv += optind;
if (opt & OPT_b) {
opt = getopt32(argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg);
#else
applet_long_options = getopt_longopts;
- opt_complementary = "l::";
- opt = getopt32(argv, "+o:n:qQs:Tual:",
+ opt = getopt32(argv, "+o:n:qQs:Tual:*",
&optstr, &name, &s_arg, &l_arg);
/* Effectuate the read options for the applet itself */
while (l_arg) {
// using global "option_mask32" instead of local "opts":
// we are register starved here
- opt_complementary = "-1:b+:i+:I+:m+";
- /*opts =*/ getopt32(argv, "cl:b:f:i:I:J:G:N:m:o:g:L:M:O:r:E:T:U:jnqvFS",
+ /*opts =*/ getopt32(argv, "cl:b:+f:i:+I:+J:G:N:m:+o:g:L:M:O:r:E:T:U:jnqvFS",
/*lbfi:*/ NULL, &bs, NULL, &bpi,
/*IJGN:*/ &user_inodesize, NULL, NULL, NULL,
/*mogL:*/ &reserved_percent, NULL, NULL, &label,
bb_error_msg_and_die("bad inode size");
#endif
- opt_complementary = "n+"; /* -n N */
- opt = getopt32(argv, "ci:l:n:v", &str_i, &listfile, &G.namelen);
+ opt = getopt32(argv, "ci:l:n:+v", &str_i, &listfile, &G.namelen);
argv += optind;
//if (opt & 1) -c
if (opt & 2) G.req_nr_inodes = xatoul(str_i); // -i
// using global "option_mask32" instead of local "opts":
// we are register starved here
- opt_complementary = "-1:b+";
- /*opts =*/ getopt32(argv, "b:j:s:o:t:B:h:u:l:fqd",
+ opt_complementary = "-1";
+ /*opts =*/ getopt32(argv, "b:+j:s:o:t:B:h:u:l:fqd",
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &label);
argv += optind; // argv[0] -- device
};
-#define OPTION_STR "o:t:rwanfvsiO:" IF_FEATURE_MOUNT_OTHERTAB("T:")
+#define OPTION_STR "o:*t:rwanfvsiO:" IF_FEATURE_MOUNT_OTHERTAB("T:")
enum {
OPT_o = (1 << 0),
OPT_t = (1 << 1),
// Parse remaining options
// Max 2 params; -o is a list, -v is a counter
- opt_complementary = "?2o::" IF_FEATURE_MOUNT_VERBOSE("vv");
+ opt_complementary = "?2" IF_FEATURE_MOUNT_VERBOSE("vv");
opt = getopt32(argv, OPTION_STR, &lst_o, &fstype, &O_optmatch
IF_FEATURE_MOUNT_OTHERTAB(, &fstabname)
IF_FEATURE_MOUNT_VERBOSE(, &verbose));
proFile = defaultpro;
mapFile = defaultmap;
- opt_complementary = "M+"; /* -M N */
- opt = getopt32(argv, "M:m:p:nabsirv", &multiplier, &mapFile, &proFile);
+ opt = getopt32(argv, "M:+m:p:nabsirv", &multiplier, &mapFile, &proFile);
if (opt & (OPT_M|OPT_r)) { /* mult or reset, or both */
int fd, to_write;