summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1997-02-20 00:45:24 +0000
committerMiles Bader <miles@gnu.org>1997-02-20 00:45:24 +0000
commit31ee7770cee7342248a744ce910eeca89927b4b5 (patch)
tree3d844661d65afc8e1b3cb22aff914cfb657636c4
parent9550f5cff5c6fb961d5d0662f07ae61b7c1fee99 (diff)
(parser_convert):
Add FLAGS argument back. (parser_init): Once again pass FLAGS argument to parser_convert. Initialize PARSER->state after calling parser_convert.
-rw-r--r--libshouldbeinlibc/argp-parse.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/libshouldbeinlibc/argp-parse.c b/libshouldbeinlibc/argp-parse.c
index 407ba19c..58e5576c 100644
--- a/libshouldbeinlibc/argp-parse.c
+++ b/libshouldbeinlibc/argp-parse.c
@@ -117,9 +117,13 @@ argp_default_parser (int key, char *arg, struct argp_state *state)
else
program_invocation_short_name = program_invocation_name;
+ /* Update what we use for messages. */
+ state->name = program_invocation_short_name;
+
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_name;
break;
@@ -421,7 +425,7 @@ convert_options (const struct argp *argp,
/* Find the merged set of getopt options, with keys appropiately prefixed. */
static void
-parser_convert (struct parser *parser, const struct argp *argp)
+parser_convert (struct parser *parser, const struct argp *argp, int flags)
{
struct parser_convert_state cvt;
@@ -430,9 +434,9 @@ parser_convert (struct parser *parser, const struct argp *argp)
cvt.long_end = parser->long_opts;
cvt.child_inputs_end = parser->child_inputs;
- if (parser->state.flags & ARGP_IN_ORDER)
+ if (flags & ARGP_IN_ORDER)
*cvt.short_end++ = '-';
- else if (parser->state.flags & ARGP_NO_ARGS)
+ else if (flags & ARGP_NO_ARGS)
*cvt.short_end++ = '+';
*cvt.short_end = '\0';
@@ -513,6 +517,14 @@ parser_init (struct parser *parser, const struct argp *argp,
if (! parser->storage)
return ENOMEM;
+ parser->groups = parser->storage;
+ parser->child_inputs = parser->storage + GLEN;
+ parser->long_opts = parser->storage + GLEN + CLEN;
+ parser->short_opts = parser->storage + GLEN + CLEN + LLEN;
+
+ memset (parser->child_inputs, 0, szs.num_child_inputs * sizeof (void *));
+ parser_convert (parser, argp, flags);
+
memset (&parser->state, 0, sizeof (struct argp_state));
parser->state.argp = parser->argp;
parser->state.argc = argc;
@@ -523,14 +535,6 @@ parser_init (struct parser *parser, const struct argp *argp,
parser->state.next = 0; /* Tell getopt to initialize. */
parser->state.pstate = parser;
- parser->groups = parser->storage;
- parser->child_inputs = parser->storage + GLEN;
- parser->long_opts = parser->storage + GLEN + CLEN;
- parser->short_opts = parser->storage + GLEN + CLEN + LLEN;
-
- memset (parser->child_inputs, 0, szs.num_child_inputs * sizeof (void *));
- parser_convert (parser, argp);
-
parser->try_getopt = 1;
/* Call each parser for the first time, giving it a chance to propagate
@@ -568,9 +572,12 @@ parser_init (struct parser *parser, const struct argp *argp,
if (parser->state.argv == argv && argv[0])
/* There's an argv[0]; use it for messages. */
- parser->state.name = argv[0];
+ {
+ char *short_name = strrchr (argv[0], '/');
+ parser->state.name = short_name ? short_name + 1 : argv[0];
+ }
else
- parser->state.name = program_invocation_name;
+ parser->state.name = program_invocation_short_name;
return 0;
}