X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fargp-parse.c;h=317ce21b36b4a0b82008c11a58d90bda7d1c20d4;hb=cb9819cbb9261bd50c3466cf0a4cd873f0d7ebd7;hp=345bddabe08bf863eefc1a151843036e4ee2d78a;hpb=267a39bafd249d7eb9c37df06dc6defcf41cb343;p=gnulib.git diff --git a/lib/argp-parse.c b/lib/argp-parse.c index 345bddabe..317ce21b3 100644 --- a/lib/argp-parse.c +++ b/lib/argp-parse.c @@ -3,22 +3,21 @@ This file is part of the GNU C Library. Written by Miles Bader . - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #ifdef HAVE_CONFIG_H -#include +# include #endif #include @@ -79,11 +78,11 @@ static volatile int _argp_hang; static const struct argp_option argp_default_options[] = { - {"help", '?', 0, 0, N_("Give this help list"), -1}, - {"usage", OPT_USAGE, 0, 0, N_("Give a short usage message"), 0}, - {"program-name",OPT_PROGNAME,"NAME", OPTION_HIDDEN, N_("Set the program name"), 0}, - {"HANG", OPT_HANG, "SECS", OPTION_ARG_OPTIONAL | OPTION_HIDDEN, - N_("Hang for SECS seconds (default 3600)"), 0}, + {"help", '?', 0, 0, N_("give this help list"), -1}, + {"usage", OPT_USAGE, 0, 0, N_("give a short usage message"), 0}, + {"program-name",OPT_PROGNAME,N_("NAME"), OPTION_HIDDEN, N_("set the program name"), 0}, + {"HANG", OPT_HANG, N_("SECS"), OPTION_ARG_OPTIONAL | OPTION_HIDDEN, + N_("hang for SECS seconds (default 3600)"), 0}, {NULL, 0, 0, 0, NULL, 0} }; @@ -97,7 +96,7 @@ argp_default_parser (int key, char *arg, struct argp_state *state) break; case OPT_USAGE: __argp_state_help (state, state->out_stream, - ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK); + ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK); break; case OPT_PROGNAME: /* Set the program name. */ @@ -109,11 +108,7 @@ argp_default_parser (int key, char *arg, struct argp_state *state) to be that, so we have to be a bit careful here.] */ /* Update what we use for messages. */ - state->name = strrchr (arg, '/'); - if (state->name) - state->name++; - else - state->name = arg; + state->name = __argp_base_name (arg); #if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME program_invocation_short_name = state->name; @@ -144,7 +139,7 @@ static const struct argp argp_default_argp = static const struct argp_option argp_version_options[] = { - {"version", 'V', 0, 0, N_("Print program version"), -1}, + {"version", 'V', 0, 0, N_("print program version"), -1}, {NULL, 0, 0, 0, NULL, 0} }; @@ -562,10 +557,7 @@ 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. */ - { - char *short_name = strrchr (argv[0], '/'); - parser->state.name = short_name ? short_name + 1 : argv[0]; - } + parser->state.name = __argp_base_name (argv[0]); else parser->state.name = __argp_short_program_name (); @@ -884,6 +876,20 @@ __argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, to be parsed (which in some cases isn't actually an error). */ int arg_ebadkey = 0; +#ifndef _LIBC + if (!(flags & ARGP_PARSE_ARGV0)) + { +#ifdef HAVE_DECL_PROGRAM_INVOCATION_NAME + if (!program_invocation_name) + program_invocation_name = argv[0]; +#endif +#ifdef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME + if (!program_invocation_short_name) + program_invocation_short_name = __argp_base_name (argv[0]); +#endif + } +#endif + if (! (flags & ARGP_NO_HELP)) /* Add our own options. */ {