1 /* Hierarchial argument parsing, layered over getopt
2 Copyright (C) 1995-2000, 2002, 2003, 2004 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Written by Miles Bader <miles@gnu.ai.mit.edu>.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 #include <getopt_int.h>
35 # define dgettext(domain, msgid) \
36 INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES)
40 #define N_(msgid) (msgid)
43 #include "argp-namefrob.h"
45 /* Getopt return values. */
46 #define KEY_END (-1) /* The end of the options. */
47 #define KEY_ARG 1 /* A non-option argument. */
48 #define KEY_ERR '?' /* An error parsing the options. */
50 /* The meta-argument used to prevent any further arguments being interpreted
54 /* The number of bits we steal in a long-option value for our own use. */
55 #define GROUP_BITS CHAR_BIT
57 /* The number of bits available for the user value. */
58 #define USER_BITS ((sizeof ((struct option *)0)->val * CHAR_BIT) - GROUP_BITS)
59 #define USER_MASK ((1 << USER_BITS) - 1)
61 /* EZ alias for ARGP_ERR_UNKNOWN. */
62 #define EBADKEY ARGP_ERR_UNKNOWN
64 /* Default options. */
66 /* When argp is given the --HANG switch, _ARGP_HANG is set and argp will sleep
67 for one second intervals, decrementing _ARGP_HANG until it's zero. Thus
68 you can force the program to continue by attaching a debugger and setting
70 static volatile int _argp_hang;
72 #define OPT_PROGNAME -2
76 static const struct argp_option argp_default_options[] =
78 {"help", '?', 0, 0, N_("Give this help list"), -1},
79 {"usage", OPT_USAGE, 0, 0, N_("Give a short usage message"), 0},
80 {"program-name",OPT_PROGNAME,"NAME", OPTION_HIDDEN, N_("Set the program name"), 0},
81 {"HANG", OPT_HANG, "SECS", OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
82 N_("Hang for SECS seconds (default 3600)"), 0},
83 {NULL, 0, 0, 0, NULL, 0}
87 argp_default_parser (int key, char *arg, struct argp_state *state)
92 __argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP);
95 __argp_state_help (state, state->out_stream,
96 ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
99 case OPT_PROGNAME: /* Set the program name. */
100 #if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_NAME
101 program_invocation_name = arg;
103 /* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka
104 __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined
105 to be that, so we have to be a bit careful here.] */
107 /* Update what we use for messages. */
108 state->name = strrchr (arg, '/');
114 #if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
115 program_invocation_short_name = state->name;
118 if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
120 /* Update what getopt uses too. */
121 state->argv[0] = arg;
126 _argp_hang = atoi (arg ? arg : "3600");
127 while (_argp_hang-- > 0)
137 static const struct argp argp_default_argp =
138 {argp_default_options, &argp_default_parser, NULL, NULL, NULL, NULL, "libc"};
141 static const struct argp_option argp_version_options[] =
143 {"version", 'V', 0, 0, N_("Print program version"), -1},
144 {NULL, 0, 0, 0, NULL, 0}
148 argp_version_parser (int key, char *arg, struct argp_state *state)
153 if (argp_program_version_hook)
154 (*argp_program_version_hook) (state->out_stream, state);
155 else if (argp_program_version)
156 fprintf (state->out_stream, "%s\n", argp_program_version);
158 __argp_error (state, dgettext (state->root_argp->argp_domain,
159 "(PROGRAM ERROR) No version known!?"));
160 if (! (state->flags & ARGP_NO_EXIT))
169 static const struct argp argp_version_argp =
170 {argp_version_options, &argp_version_parser, NULL, NULL, NULL, NULL, "libc"};
172 /* Returns the offset into the getopt long options array LONG_OPTIONS of a
173 long option with called NAME, or -1 if none is found. Passing NULL as
174 NAME will return the number of options. */
176 find_long_option (struct option *long_options, const char *name)
178 struct option *l = long_options;
179 while (l->name != NULL)
180 if (name != NULL && strcmp (l->name, name) == 0)
181 return l - long_options;
185 return l - long_options;
191 /* The state of a `group' during parsing. Each group corresponds to a
192 particular argp structure from the tree of such descending from the top
193 level argp passed to argp_parse. */
196 /* This group's parsing function. */
197 argp_parser_t parser;
199 /* Which argp this group is from. */
200 const struct argp *argp;
202 /* Points to the point in SHORT_OPTS corresponding to the end of the short
203 options for this group. We use it to determine from which group a
204 particular short options is from. */
207 /* The number of non-option args sucessfully handled by this parser. */
208 unsigned args_processed;
210 /* This group's parser's parent's group. */
211 struct group *parent;
212 unsigned parent_index; /* And the our position in the parent. */
214 /* These fields are swapped into and out of the state structure when
215 calling this group's parser. */
216 void *input, **child_inputs;
220 /* Call GROUP's parser with KEY and ARG, swapping any group-specific info
221 from STATE before calling, and back into state afterwards. If GROUP has
222 no parser, EBADKEY is returned. */
224 group_parse (struct group *group, struct argp_state *state, int key, char *arg)
229 state->hook = group->hook;
230 state->input = group->input;
231 state->child_inputs = group->child_inputs;
232 state->arg_num = group->args_processed;
233 err = (*group->parser)(key, arg, state);
234 group->hook = state->hook;
243 const struct argp *argp;
245 /* SHORT_OPTS is the getopt short options string for the union of all the
246 groups of options. */
248 /* LONG_OPTS is the array of getop long option structures for the union of
249 all the groups of options. */
250 struct option *long_opts;
251 /* OPT_DATA is the getopt data used for the re-entrant getopt. */
252 struct _getopt_data opt_data;
254 /* States of the various parsing groups. */
255 struct group *groups;
256 /* The end of the GROUPS array. */
257 struct group *egroup;
258 /* An vector containing storage for the CHILD_INPUTS field in all groups. */
261 /* True if we think using getopt is still useful; if false, then
262 remaining arguments are just passed verbatim with ARGP_KEY_ARG. This is
263 cleared whenever getopt returns KEY_END, but may be set again if the user
264 moves the next argument pointer backwards. */
267 /* State block supplied to parsing routines. */
268 struct argp_state state;
270 /* Memory used by this parser. */
274 /* The next usable entries in the various parser tables being filled in by
276 struct parser_convert_state
278 struct parser *parser;
280 struct option *long_end;
281 void **child_inputs_end;
284 /* Converts all options in ARGP (which is put in GROUP) and ancestors
285 into getopt options stored in SHORT_OPTS and LONG_OPTS; SHORT_END and
286 CVT->LONG_END are the points at which new options are added. Returns the
287 next unused group entry. CVT holds state used during the conversion. */
288 static struct group *
289 convert_options (const struct argp *argp,
290 struct group *parent, unsigned parent_index,
291 struct group *group, struct parser_convert_state *cvt)
293 /* REAL is the most recent non-alias value of OPT. */
294 const struct argp_option *real = argp->options;
295 const struct argp_child *children = argp->children;
297 if (real || argp->parser)
299 const struct argp_option *opt;
302 for (opt = real; !__option_is_end (opt); opt++)
304 if (! (opt->flags & OPTION_ALIAS))
305 /* OPT isn't an alias, so we can use values from it. */
308 if (! (real->flags & OPTION_DOC))
309 /* A real option (not just documentation). */
311 if (__option_is_short (opt))
312 /* OPT can be used as a short option. */
314 *cvt->short_end++ = opt->key;
317 *cvt->short_end++ = ':';
318 if (real->flags & OPTION_ARG_OPTIONAL)
319 *cvt->short_end++ = ':';
321 *cvt->short_end = '\0'; /* keep 0 terminated */
325 && find_long_option (cvt->parser->long_opts, opt->name) < 0)
326 /* OPT can be used as a long option. */
328 cvt->long_end->name = opt->name;
329 cvt->long_end->has_arg =
331 ? (real->flags & OPTION_ARG_OPTIONAL
335 cvt->long_end->flag = 0;
336 /* we add a disambiguating code to all the user's
337 values (which is removed before we actually call
338 the function to parse the value); this means that
339 the user loses use of the high 8 bits in all his
340 values (the sign of the lower bits is preserved
343 ((opt->key | real->key) & USER_MASK)
344 + (((group - cvt->parser->groups) + 1) << USER_BITS);
346 /* Keep the LONG_OPTS list terminated. */
347 (++cvt->long_end)->name = NULL;
352 group->parser = argp->parser;
354 group->short_end = cvt->short_end;
355 group->args_processed = 0;
356 group->parent = parent;
357 group->parent_index = parent_index;
360 group->child_inputs = 0;
363 /* Assign GROUP's CHILD_INPUTS field some space from
364 CVT->child_inputs_end.*/
366 unsigned num_children = 0;
367 while (children[num_children].argp)
369 group->child_inputs = cvt->child_inputs_end;
370 cvt->child_inputs_end += num_children;
381 while (children->argp)
383 convert_options (children++->argp, parent, index++, group, cvt);
389 /* Find the merged set of getopt options, with keys appropiately prefixed. */
391 parser_convert (struct parser *parser, const struct argp *argp, int flags)
393 struct parser_convert_state cvt;
396 cvt.short_end = parser->short_opts;
397 cvt.long_end = parser->long_opts;
398 cvt.child_inputs_end = parser->child_inputs;
400 if (flags & ARGP_IN_ORDER)
401 *cvt.short_end++ = '-';
402 else if (flags & ARGP_NO_ARGS)
403 *cvt.short_end++ = '+';
404 *cvt.short_end = '\0';
406 cvt.long_end->name = NULL;
411 parser->egroup = convert_options (argp, 0, 0, parser->groups, &cvt);
413 parser->egroup = parser->groups; /* No parsers at all! */
416 /* Lengths of various parser fields which we will allocated. */
419 size_t short_len; /* Getopt short options string. */
420 size_t long_len; /* Getopt long options vector. */
421 size_t num_groups; /* Group structures we allocate. */
422 size_t num_child_inputs; /* Child input slots. */
425 /* For ARGP, increments the NUM_GROUPS field in SZS by the total number of
426 argp structures descended from it, and the SHORT_LEN & LONG_LEN fields by
427 the maximum lengths of the resulting merged getopt short options string and
428 long-options array, respectively. */
430 calc_sizes (const struct argp *argp, struct parser_sizes *szs)
432 const struct argp_child *child = argp->children;
433 const struct argp_option *opt = argp->options;
435 if (opt || argp->parser)
441 while (!__option_is_end (opt++))
443 szs->short_len += num_opts * 3; /* opt + up to 2 `:'s */
444 szs->long_len += num_opts;
451 calc_sizes ((child++)->argp, szs);
452 szs->num_child_inputs++;
456 /* Initializes PARSER to parse ARGP in a manner described by FLAGS. */
458 parser_init (struct parser *parser, const struct argp *argp,
459 int argc, char **argv, int flags, void *input)
463 struct parser_sizes szs;
464 struct _getopt_data opt_data = _GETOPT_DATA_INITIALIZER;
466 szs.short_len = (flags & ARGP_NO_ARGS) ? 0 : 1;
469 szs.num_child_inputs = 0;
472 calc_sizes (argp, &szs);
474 /* Lengths of the various bits of storage used by PARSER. */
475 #define GLEN (szs.num_groups + 1) * sizeof (struct group)
476 #define CLEN (szs.num_child_inputs * sizeof (void *))
477 #define LLEN ((szs.long_len + 1) * sizeof (struct option))
478 #define SLEN (szs.short_len + 1)
480 parser->storage = malloc (GLEN + CLEN + LLEN + SLEN);
481 if (! parser->storage)
484 parser->groups = parser->storage;
485 parser->child_inputs = (void **)((char*) parser->storage + GLEN);
486 parser->long_opts = (struct option *)((char*) parser->storage + GLEN + CLEN);
487 parser->short_opts = (char*) parser->storage + GLEN + CLEN + LLEN;
488 parser->opt_data = opt_data;
490 memset (parser->child_inputs, 0, szs.num_child_inputs * sizeof (void *));
491 parser_convert (parser, argp, flags);
493 memset (&parser->state, 0, sizeof (struct argp_state));
494 parser->state.root_argp = parser->argp;
495 parser->state.argc = argc;
496 parser->state.argv = argv;
497 parser->state.flags = flags;
498 parser->state.err_stream = stderr;
499 parser->state.out_stream = stdout;
500 parser->state.next = 0; /* Tell getopt to initialize. */
501 parser->state.pstate = parser;
503 parser->try_getopt = 1;
505 /* Call each parser for the first time, giving it a chance to propagate
506 values to child parsers. */
507 if (parser->groups < parser->egroup)
508 parser->groups->input = input;
509 for (group = parser->groups;
510 group < parser->egroup && (!err || err == EBADKEY);
514 /* If a child parser, get the initial input value from the parent. */
515 group->input = group->parent->child_inputs[group->parent_index];
518 && group->argp->children && group->argp->children->argp)
519 /* For the special case where no parsing function is supplied for an
520 argp, propagate its input to its first child, if any (this just
521 makes very simple wrapper argps more convenient). */
522 group->child_inputs[0] = group->input;
524 err = group_parse (group, &parser->state, ARGP_KEY_INIT, 0);
527 err = 0; /* Some parser didn't understand. */
532 if (parser->state.flags & ARGP_NO_ERRS)
534 parser->opt_data.opterr = 0;
535 if (parser->state.flags & ARGP_PARSE_ARGV0)
536 /* getopt always skips ARGV[0], so we have to fake it out. As long
537 as OPTERR is 0, then it shouldn't actually try to access it. */
538 parser->state.argv--, parser->state.argc++;
541 parser->opt_data.opterr = 1; /* Print error messages. */
543 if (parser->state.argv == argv && argv[0])
544 /* There's an argv[0]; use it for messages. */
546 char *short_name = strrchr (argv[0], '/');
547 parser->state.name = short_name ? short_name + 1 : argv[0];
550 parser->state.name = __argp_short_program_name ();
555 /* Free any storage consumed by PARSER (but not PARSER itself). */
557 parser_finalize (struct parser *parser,
558 error_t err, int arg_ebadkey, int *end_index)
562 if (err == EBADKEY && arg_ebadkey)
563 /* Suppress errors generated by unparsed arguments. */
568 if (parser->state.next == parser->state.argc)
569 /* We successfully parsed all arguments! Call all the parsers again,
570 just a few more times... */
572 for (group = parser->groups;
573 group < parser->egroup && (!err || err==EBADKEY);
575 if (group->args_processed == 0)
576 err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0);
577 for (group = parser->egroup - 1;
578 group >= parser->groups && (!err || err==EBADKEY);
580 err = group_parse (group, &parser->state, ARGP_KEY_END, 0);
583 err = 0; /* Some parser didn't understand. */
585 /* Tell the user that all arguments are parsed. */
587 *end_index = parser->state.next;
590 /* Return any remaining arguments to the user. */
591 *end_index = parser->state.next;
593 /* No way to return the remaining arguments, they must be bogus. */
595 if (!(parser->state.flags & ARGP_NO_ERRS)
596 && parser->state.err_stream)
597 fprintf (parser->state.err_stream,
598 dgettext (parser->argp->argp_domain,
599 "%s: Too many arguments\n"),
605 /* Okay, we're all done, with either an error or success; call the parsers
606 to indicate which one. */
610 /* Maybe print an error message. */
612 /* An appropriate message describing what the error was should have
613 been printed earlier. */
614 __argp_state_help (&parser->state, parser->state.err_stream,
617 /* Since we didn't exit, give each parser an error indication. */
618 for (group = parser->groups; group < parser->egroup; group++)
619 group_parse (group, &parser->state, ARGP_KEY_ERROR, 0);
622 /* Notify parsers of success, and propagate back values from parsers. */
624 /* We pass over the groups in reverse order so that child groups are
625 given a chance to do there processing before passing back a value to
627 for (group = parser->egroup - 1
628 ; group >= parser->groups && (!err || err == EBADKEY)
630 err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, 0);
632 err = 0; /* Some parser didn't understand. */
635 /* Call parsers once more, to do any final cleanup. Errors are ignored. */
636 for (group = parser->egroup - 1; group >= parser->groups; group--)
637 group_parse (group, &parser->state, ARGP_KEY_FINI, 0);
642 free (parser->storage);
647 /* Call the user parsers to parse the non-option argument VAL, at the current
648 position, returning any error. The state NEXT pointer is assumed to have
649 been adjusted (by getopt) to point after this argument; this function will
650 adjust it correctly to reflect however many args actually end up being
653 parser_parse_arg (struct parser *parser, char *val)
655 /* Save the starting value of NEXT, first adjusting it so that the arg
656 we're parsing is again the front of the arg vector. */
657 int index = --parser->state.next;
658 error_t err = EBADKEY;
660 int key = 0; /* Which of ARGP_KEY_ARG[S] we used. */
662 /* Try to parse the argument in each parser. */
663 for (group = parser->groups
664 ; group < parser->egroup && err == EBADKEY
667 parser->state.next++; /* For ARGP_KEY_ARG, consume the arg. */
669 err = group_parse (group, &parser->state, key, val);
672 /* This parser doesn't like ARGP_KEY_ARG; try ARGP_KEY_ARGS instead. */
674 parser->state.next--; /* For ARGP_KEY_ARGS, put back the arg. */
676 err = group_parse (group, &parser->state, key, 0);
682 if (key == ARGP_KEY_ARGS)
683 /* The default for ARGP_KEY_ARGS is to assume that if NEXT isn't
684 changed by the user, *all* arguments should be considered
686 parser->state.next = parser->state.argc;
688 if (parser->state.next > index)
689 /* Remember that we successfully processed a non-option
690 argument -- but only if the user hasn't gotten tricky and set
692 (--group)->args_processed += (parser->state.next - index);
694 /* The user wants to reparse some args, give getopt another try. */
695 parser->try_getopt = 1;
701 /* Call the user parsers to parse the option OPT, with argument VAL, at the
702 current position, returning any error. */
704 parser_parse_opt (struct parser *parser, int opt, char *val)
706 /* The group key encoded in the high bits; 0 for short opts or
707 group_number + 1 for long opts. */
708 int group_key = opt >> USER_BITS;
709 error_t err = EBADKEY;
712 /* A short option. By comparing OPT's position in SHORT_OPTS to the
713 various starting positions in each group's SHORT_END field, we can
714 determine which group OPT came from. */
717 char *short_index = strchr (parser->short_opts, opt);
720 for (group = parser->groups; group < parser->egroup; group++)
721 if (group->short_end > short_index)
723 err = group_parse (group, &parser->state, opt,
724 parser->opt_data.optarg);
729 /* A long option. We use shifts instead of masking for extracting
730 the user value in order to preserve the sign. */
732 group_parse (&parser->groups[group_key - 1], &parser->state,
733 (opt << GROUP_BITS) >> GROUP_BITS,
734 parser->opt_data.optarg);
737 /* At least currently, an option not recognized is an error in the
738 parser, because we pre-compute which parser is supposed to deal
741 static const char bad_key_err[] =
742 N_("(PROGRAM ERROR) Option should have been recognized!?");
744 __argp_error (&parser->state, "-%c: %s", opt,
745 dgettext (parser->argp->argp_domain, bad_key_err));
748 struct option *long_opt = parser->long_opts;
749 while (long_opt->val != opt && long_opt->name)
751 __argp_error (&parser->state, "--%s: %s",
752 long_opt->name ? long_opt->name : "???",
753 dgettext (parser->argp->argp_domain, bad_key_err));
760 /* Parse the next argument in PARSER (as indicated by PARSER->state.next).
761 Any error from the parsers is returned, and *ARGP_EBADKEY indicates
762 whether a value of EBADKEY is due to an unrecognized argument (which is
763 generally not fatal). */
765 parser_parse_next (struct parser *parser, int *arg_ebadkey)
770 if (parser->state.quoted && parser->state.next < parser->state.quoted)
771 /* The next argument pointer has been moved to before the quoted
772 region, so pretend we never saw the quoting `--', and give getopt
773 another chance. If the user hasn't removed it, getopt will just
775 parser->state.quoted = 0;
777 if (parser->try_getopt && !parser->state.quoted)
778 /* Give getopt a chance to parse this. */
780 /* Put it back in OPTIND for getopt. */
781 parser->opt_data.optind = parser->state.next;
782 /* Distinguish KEY_ERR from a real option. */
783 parser->opt_data.optopt = KEY_END;
784 if (parser->state.flags & ARGP_LONG_ONLY)
785 opt = _getopt_long_only_r (parser->state.argc, parser->state.argv,
786 parser->short_opts, parser->long_opts, 0,
789 opt = _getopt_long_r (parser->state.argc, parser->state.argv,
790 parser->short_opts, parser->long_opts, 0,
792 /* And see what getopt did. */
793 parser->state.next = parser->opt_data.optind;
796 /* Getopt says there are no more options, so stop using
797 getopt; we'll continue if necessary on our own. */
799 parser->try_getopt = 0;
800 if (parser->state.next > 1
801 && strcmp (parser->state.argv[parser->state.next - 1], QUOTE)
803 /* Not only is this the end of the options, but it's a
804 `quoted' region, which may have args that *look* like
805 options, so we definitely shouldn't try to use getopt past
806 here, whatever happens. */
807 parser->state.quoted = parser->state.next;
809 else if (opt == KEY_ERR && parser->opt_data.optopt != KEY_END)
810 /* KEY_ERR can have the same value as a valid user short
811 option, but in the case of a real error, getopt sets OPTOPT
812 to the offending character, which can never be KEY_END. */
823 /* We're past what getopt considers the options. */
824 if (parser->state.next >= parser->state.argc
825 || (parser->state.flags & ARGP_NO_ARGS))
826 /* Indicate that we're done. */
832 /* A non-option arg; simulate what getopt might have done. */
835 parser->opt_data.optarg = parser->state.argv[parser->state.next++];
840 /* A non-option argument; try each parser in turn. */
841 err = parser_parse_arg (parser, parser->opt_data.optarg);
843 err = parser_parse_opt (parser, opt, parser->opt_data.optarg);
846 *arg_ebadkey = (opt == KEY_END || opt == KEY_ARG);
851 /* Parse the options strings in ARGC & ARGV according to the argp in ARGP.
852 FLAGS is one of the ARGP_ flags above. If END_INDEX is non-NULL, the
853 index in ARGV of the first unparsed option is returned in it. If an
854 unknown option is present, EINVAL is returned; if some parser routine
855 returned a non-zero value, it is returned; otherwise 0 is returned. */
857 __argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags,
858 int *end_index, void *input)
861 struct parser parser;
863 /* If true, then err == EBADKEY is a result of a non-option argument failing
864 to be parsed (which in some cases isn't actually an error). */
867 if (! (flags & ARGP_NO_HELP))
868 /* Add our own options. */
870 struct argp_child *child = alloca (4 * sizeof (struct argp_child));
871 struct argp *top_argp = alloca (sizeof (struct argp));
873 /* TOP_ARGP has no options, it just serves to group the user & default
875 memset (top_argp, 0, sizeof (*top_argp));
876 top_argp->children = child;
878 memset (child, 0, 4 * sizeof (struct argp_child));
881 (child++)->argp = argp;
882 (child++)->argp = &argp_default_argp;
883 if (argp_program_version || argp_program_version_hook)
884 (child++)->argp = &argp_version_argp;
890 /* Construct a parser for these arguments. */
891 err = parser_init (&parser, argp, argc, argv, flags, input);
897 err = parser_parse_next (&parser, &arg_ebadkey);
898 err = parser_finalize (&parser, err, arg_ebadkey, end_index);
904 weak_alias (__argp_parse, argp_parse)
907 /* Return the input field for ARGP in the parser corresponding to STATE; used
908 by the help routines. */
910 __argp_input (const struct argp *argp, const struct argp_state *state)
915 struct parser *parser = state->pstate;
917 for (group = parser->groups; group < parser->egroup; group++)
918 if (group->argp == argp)
925 weak_alias (__argp_input, _argp_input)