diff options
author | Miles Bader <miles@gnu.org> | 1997-02-12 05:45:43 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1997-02-12 05:45:43 +0000 |
commit | 922f103b23332a91915fdd6150a16fc7f693e997 (patch) | |
tree | a53d5b6639e4db1f37337dd2e2e9b7b49dadccc1 /libshouldbeinlibc/argp-test.c | |
parent | 386c0a12858f23109c41d3aa8b99614cc18b192e (diff) |
.
Diffstat (limited to 'libshouldbeinlibc/argp-test.c')
-rw-r--r-- | libshouldbeinlibc/argp-test.c | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/libshouldbeinlibc/argp-test.c b/libshouldbeinlibc/argp-test.c index 378aff86..9c765f58 100644 --- a/libshouldbeinlibc/argp-test.c +++ b/libshouldbeinlibc/argp-test.c @@ -22,7 +22,47 @@ #include <argp.h> char *argp_program_version = "argp-test 1.0"; + +struct argp_option sub_options[] = +{ + {"subopt1", 's', 0, 0, "Nested option 1"}, + {"subopt2", 'S', 0, 0, "Nested option 2"}, + + { 0, 0, 0, 0, "Some more nested options:", 10}, + {"subopt3", 'p', 0, 0, "Nested option 3"}, + + {"subopt4", 'q', 0, 0, "Nested option 4", 1}, + + {0} +}; + +static const char sub_args_doc[] = "STRING...\n-"; +static const char sub_doc[] = "\vThis is the doc string from the sub-arg-parser."; +static error_t +sub_parse_opt (int key, char *arg, struct argp_state *state) +{ + switch (key) + { + case ARGP_KEY_NO_ARGS: + printf ("NO SUB ARGS\n"); + break; + case ARGP_KEY_ARG: + printf ("SUB ARG: %s\n", arg); + break; + + case 's' : case 'S': case 'p': case 'q': + printf ("SUB KEY %c\n", key); + break; + + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +static struct argp sub_argp = { sub_options, sub_parse_opt, sub_args_doc, sub_doc }; + #define OPT_PGRP -1 #define OPT_SESS -2 @@ -52,7 +92,7 @@ the current process)"}, {0} }; -static const char args_doc[] = "STRING...\n-"; +static const char args_doc[] = "STRING"; static const char doc[] = "Test program for argp."; static error_t @@ -63,10 +103,10 @@ parse_opt (int key, char *arg, struct argp_state *state) case ARGP_KEY_NO_ARGS: printf ("NO ARGS\n"); break; + case ARGP_KEY_ARG: - if (state->arg_num == 0 && strcmp (arg, "-") == 0 - && state->next < state->argc) - argp_usage (state); + if (state->arg_num > 0) + return ARGP_ERR_UNKNOWN; /* Leave it for the sub-arg parser. */ printf ("ARG: %s\n", arg); break; @@ -91,8 +131,9 @@ parse_opt (int key, char *arg, struct argp_state *state) return 0; } -static struct argp argp = { options, parse_opt, args_doc, doc }; - +static struct argp_child argp_children[] = { { &sub_argp }, { 0 } }; +static struct argp argp = { options, parse_opt, args_doc, doc, argp_children }; + int main (int argc, char **argv) { |