X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fargp-parse.c;h=0813afc824fb3cd37db978a53ac6d8b388ac6fa0;hb=8aaff11b82298106fa5ce0ff3d22351d43dd468f;hp=509f6dea8522303f778f8f524a62dbe7bdad31cb;hpb=3d140c4471e983a16c5836de180ddf11a12eaa39;p=gnulib.git diff --git a/lib/argp-parse.c b/lib/argp-parse.c index 509f6dea8..0813afc82 100644 --- a/lib/argp-parse.c +++ b/lib/argp-parse.c @@ -15,10 +15,10 @@ 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H -#include +# include #endif #include @@ -38,7 +38,7 @@ #else # include "gettext.h" #endif -#define N_(msgid) (msgid) +#define N_(msgid) msgid #include "argp.h" #include "argp-namefrob.h" @@ -79,11 +79,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 +97,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 +109,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 +140,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} }; @@ -482,12 +478,18 @@ parser_init (struct parser *parser, const struct argp *argp, /* Lengths of the various bits of storage used by PARSER. */ glen = (szs.num_groups + 1) * sizeof (struct group); - gsum = alignto (glen, alignof (void *)); clen = szs.num_child_inputs * sizeof (void *); - csum = alignto (gsum + clen, alignof (struct option)); llen = (szs.long_len + 1) * sizeof (struct option); - lsum = alignto (csum + llen, alignof (char)); slen = szs.short_len + 1; + + /* Sums of previous lengths, properly aligned. There's no need to + align gsum, since struct group is aligned at least as strictly as + void * (since it contains a void * member). And there's no need + to align lsum, since struct option is aligned at least as + strictly as char. */ + gsum = glen; + csum = alignto (gsum + clen, alignof (struct option)); + lsum = csum + llen; ssum = lsum + slen; parser->storage = malloc (ssum); @@ -556,10 +558,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 ();