2007-10-13 18:34:45 +02:00
|
|
|
#include "cache.h"
|
|
|
|
#include "parse-options.h"
|
|
|
|
|
|
|
|
static int boolean = 0;
|
|
|
|
static int integer = 0;
|
|
|
|
static char *string = NULL;
|
|
|
|
|
|
|
|
int main(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
const char *usage[] = {
|
|
|
|
"test-parse-options <options>",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
struct option options[] = {
|
|
|
|
OPT_BOOLEAN('b', "boolean", &boolean, "get a boolean"),
|
|
|
|
OPT_INTEGER('i', "integer", &integer, "get a integer"),
|
|
|
|
OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
|
|
|
|
OPT_GROUP("string options"),
|
|
|
|
OPT_STRING('s', "string", &string, "string", "get a string"),
|
|
|
|
OPT_STRING(0, "string2", &string, "str", "get another string"),
|
2007-11-05 14:15:21 +01:00
|
|
|
OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
|
2008-01-26 12:26:57 +01:00
|
|
|
OPT_STRING('o', NULL, &string, "str", "get another string"),
|
2008-03-02 11:35:56 +01:00
|
|
|
OPT_GROUP("magic arguments"),
|
|
|
|
OPT_ARGUMENT("quux", "means --quux"),
|
2007-10-13 18:34:45 +02:00
|
|
|
OPT_END(),
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, options, usage, 0);
|
|
|
|
|
|
|
|
printf("boolean: %d\n", boolean);
|
|
|
|
printf("integer: %d\n", integer);
|
|
|
|
printf("string: %s\n", string ? string : "(not set)");
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
printf("arg %02d: %s\n", i, argv[i]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|