diff options
Diffstat (limited to 'test-parse-options.c')
-rw-r--r-- | test-parse-options.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/test-parse-options.c b/test-parse-options.c index 36487c402b..2c8c8f18ed 100644 --- a/test-parse-options.c +++ b/test-parse-options.c @@ -4,6 +4,7 @@ static int boolean = 0; static int integer = 0; +static unsigned long magnitude = 0; static unsigned long timestamp; static int abbrev = 7; static int verbose = 0, dry_run = 0, quiet = 0; @@ -29,7 +30,7 @@ static int number_callback(const struct option *opt, const char *arg, int unset) return 0; } -int main(int argc, const char **argv) +int main(int argc, char **argv) { const char *prefix = "prefix/"; const char *usage[] = { @@ -37,13 +38,18 @@ int main(int argc, const char **argv) NULL }; struct option options[] = { - OPT_BOOLEAN('b', "boolean", &boolean, "get a boolean"), + OPT_BOOL(0, "yes", &boolean, "get a boolean"), + OPT_BOOL('D', "no-doubt", &boolean, "begins with 'no-'"), + { OPTION_SET_INT, 'B', "no-fear", &boolean, NULL, + "be brave", PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 }, + OPT_COUNTUP('b', "boolean", &boolean, "increment by one"), OPT_BIT('4', "or4", &boolean, "bitwise-or boolean with ...0100", 4), OPT_NEGBIT(0, "neg-or4", &boolean, "same as --no-or4", 4), OPT_GROUP(""), OPT_INTEGER('i', "integer", &integer, "get a integer"), OPT_INTEGER('j', NULL, &integer, "get a integer, too"), + OPT_MAGNITUDE('m', "magnitude", &magnitude, "get a magnitude"), OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23), OPT_DATE('t', NULL, ×tamp, "get timestamp of <time>"), OPT_CALLBACK('L', "length", &integer, "str", @@ -55,18 +61,16 @@ int main(int argc, const char **argv) OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"), OPT_STRING('o', NULL, &string, "str", "get another string"), OPT_NOOP_NOARG(0, "obsolete"), - OPT_SET_PTR(0, "default-string", &string, - "set string to default", (unsigned long)"default"), OPT_STRING_LIST(0, "list", &list, "str", "add str to list"), OPT_GROUP("Magic arguments"), OPT_ARGUMENT("quux", "means --quux"), OPT_NUMBER_CALLBACK(&integer, "set integer to NUM", number_callback), - { OPTION_BOOLEAN, '+', NULL, &boolean, NULL, "same as -b", + { OPTION_COUNTUP, '+', NULL, &boolean, NULL, "same as -b", PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH }, - { OPTION_BOOLEAN, 0, "ambiguous", &ambiguous, NULL, + { OPTION_COUNTUP, 0, "ambiguous", &ambiguous, NULL, "positive ambiguity", PARSE_OPT_NOARG | PARSE_OPT_NONEG }, - { OPTION_BOOLEAN, 0, "no-ambiguous", &ambiguous, NULL, + { OPTION_COUNTUP, 0, "no-ambiguous", &ambiguous, NULL, "negative ambiguity", PARSE_OPT_NOARG | PARSE_OPT_NONEG }, OPT_GROUP("Standard options"), OPT__ABBREV(&abbrev), @@ -77,10 +81,11 @@ int main(int argc, const char **argv) }; int i; - argc = parse_options(argc, argv, prefix, options, usage, 0); + argc = parse_options(argc, (const char **)argv, prefix, options, usage, 0); printf("boolean: %d\n", boolean); - printf("integer: %u\n", integer); + printf("integer: %d\n", integer); + printf("magnitude: %lu\n", magnitude); printf("timestamp: %lu\n", timestamp); printf("string: %s\n", string ? string : "(not set)"); printf("abbrev: %d\n", abbrev); |