getopt_ulflags: formatting fixes

This commit is contained in:
Denis Vlasenko
2006-09-29 08:23:42 +00:00
parent 6248a734e2
commit b02ef82c99

View File

@@ -74,6 +74,7 @@ const struct option *bb_applet_long_options
(see getopt(3))
static const struct option applet_long_options[] = {
//name,has_arg,flag,val
{ "verbose", 0, 0, 'v' },
{ 0, 0, 0, 0 }
};
@@ -207,6 +208,9 @@ Special characters:
if (flags & BB_GETOPT_ERROR)
bb_show_usage();
"x--x" Variation of the above, it means that -x option should occur
at most once.
"?" A "?" as the first char in a bb_opt_complementally group means:
if BB_GETOPT_ERROR is detected, don't return, call bb_show_usage
and exit instead. Next char after '?' can't be a digit.
@@ -255,7 +259,7 @@ Special characters:
$ id; id -u; id -g; id -ru; id -nu; id -rg; id -ng; id -rnu; id -rng
"X" A bb_opt_complementally group with just a single letter means
that this this option is required. If more than one such group exists,
that this option is required. If more than one such group exists,
at least one option is required to occur (not all of them).
For example from "start-stop-daemon" applet:
@@ -263,9 +267,6 @@ Special characters:
bb_opt_complementally = "K:S:?K--S:S--K";
flags = bb_getopt_ulflags(argc, argv, "KS...);
"x--x" give error if double or more used -x option
Don't forget to use ':'. For example "?322-22-23X-x-a" is interpreted as
"?3:22:-2:2-2:2-3Xa:2--x": max 3 args; count uses of '-2'; min 2 args;
if there is a '-2' option then unset '-3', '-X' and '-a'; if there is
@@ -439,8 +440,8 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
}
va_end (p);
#if defined(CONFIG_AR) || defined(CONFIG_TAR)
if((spec_flgs & FIRST_ARGV_IS_OPT)) {
#if ENABLE_AR || ENABLE_TAR
if (spec_flgs & FIRST_ARGV_IS_OPT) {
if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') {
argv[1] = xasprintf("-%s", argv[1]);
if (ENABLE_FEATURE_CLEAN_UP)
@@ -454,7 +455,7 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
#else
while ((c = getopt(argc, argv, applet_opts)) >= 0) {
#endif /* ENABLE_GETOPT_LONG */
#ifdef CONFIG_PS
#if ENABLE_PS
loop_arg_is_opt:
#endif
for (on_off = complementally; on_off->opt != c; on_off++) {
@@ -478,14 +479,14 @@ loop_arg_is_opt:
} else if (on_off->optarg) {
*(char **)(on_off->optarg) = optarg;
}
#ifdef CONFIG_PS
#if ENABLE_PS
if (pargv != NULL)
break;
#endif
}
#ifdef CONFIG_PS
if((spec_flgs & ALL_ARGV_IS_OPTS)) {
#if ENABLE_PS
if (spec_flgs & ALL_ARGV_IS_OPTS) {
/* process argv is option, for example "ps" applet */
if (pargv == NULL)
pargv = argv + optind;
@@ -501,9 +502,8 @@ loop_arg_is_opt:
}
#endif
#if (defined(CONFIG_AR) || defined(CONFIG_TAR)) && \
defined(CONFIG_FEATURE_CLEAN_UP)
if((spec_flgs & FREE_FIRST_ARGV_IS_OPT))
#if (ENABLE_AR || ENABLE_TAR) && ENABLE_FEATURE_CLEAN_UP
if (spec_flgs & FREE_FIRST_ARGV_IS_OPT)
free(argv[1]);
#endif
/* check depending requires for given options */