aboutsummaryrefslogtreecommitdiff
path: root/argp/argp-parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'argp/argp-parse.c')
-rw-r--r--argp/argp-parse.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/argp/argp-parse.c b/argp/argp-parse.c
index f1f4ce9..af27757 100644
--- a/argp/argp-parse.c
+++ b/argp/argp-parse.c
@@ -106,7 +106,7 @@ argp_default_parser (int key, char *arg, struct argp_state *state)
break;
case OPT_PROGNAME: /* Set the program name. */
- program_invocation_name = arg;
+ program_invocation_short_name = arg;
/* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka
__PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined
@@ -119,7 +119,8 @@ argp_default_parser (int key, char *arg, struct argp_state *state)
if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
== ARGP_PARSE_ARGV0)
- state->argv[0] = program_invocation_name; /* Update what getopt uses too. */
+ /* Update what getopt uses too. */
+ state->argv[0] = program_invocation_short_name;
break;
@@ -231,6 +232,9 @@ struct group
/* This group's parsing function. */
argp_parser_t parser;
+ /* Which argp this group is from. */
+ const struct argp *argp;
+
/* Points to the point in SHORT_OPTS corresponding to the end of the short
options for this group. We use it to determine from which group a
particular short options is from. */
@@ -380,6 +384,7 @@ convert_options (const struct argp *argp,
}
group->parser = argp->parser;
+ group->argp = argp;
group->short_end = cvt->short_end;
group->args_processed = 0;
group->parent = parent;
@@ -526,6 +531,7 @@ parser_init (struct parser *parser, const struct argp *argp,
parser->state.err_stream = stderr;
parser->state.out_stream = stdout;
parser->state.next = 0; /* Tell getopt to initialize. */
+ parser->state.pstate = parser;
/* Call each parser for the first time, giving it a chance to propagate
values to child parsers. */
@@ -848,3 +854,24 @@ __argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags,
#ifdef weak_alias
weak_alias (__argp_parse, argp_parse)
#endif
+
+/* Return the input field for ARGP in the parser corresponding to STATE; used
+ by the help routines. */
+void *
+__argp_input (const struct argp *argp, const struct argp_state *state)
+{
+ if (state)
+ {
+ struct group *group;
+ struct parser *parser = state->pstate;
+
+ for (group = parser->groups; group < parser->egroup; group++)
+ if (group->argp == argp)
+ return group->input;
+ }
+
+ return 0;
+}
+#ifdef weak_alias
+weak_alias (__argp_input, _argp_input)
+#endif