X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fargp-help.c;h=60357649618650101b41340e617df8635dcadae6;hb=d33e27b00b65fc12a046ca1f1bdb17bc5c1d1585;hp=61acecd619abd85a8f70d15d8e9cf9c4e3b759f2;hpb=35bf0dc2d01c7b90f6c264ac7c5f737a751b0734;p=gnulib.git diff --git a/lib/argp-help.c b/lib/argp-help.c index 61acecd61..603576496 100644 --- a/lib/argp-help.c +++ b/lib/argp-help.c @@ -25,21 +25,8 @@ #include #endif -/* AIX requires this to be the first thing in the file. */ -#ifndef __GNUC__ -# if HAVE_ALLOCA_H || defined _LIBC -# include -# else -# ifdef _AIX -#pragma alloca -# else -# ifndef alloca /* predefined by HP cc +Olibcalls */ -char *alloca (); -# endif -# endif -# endif -#endif - +#include +#include #include #include #include @@ -51,30 +38,13 @@ char *alloca (); # include #endif -#ifndef _ -/* This is for other GNU distributions with internationalized messages. */ -# if defined HAVE_LIBINTL_H || defined _LIBC -# include -# ifdef _LIBC -# undef dgettext -# define dgettext(domain, msgid) \ - INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES) -# endif -# else -# define dgettext(domain, msgid) (msgid) -# endif -#endif - -#ifndef _LIBC -# if HAVE_STRERROR_R -# if !HAVE_DECL_STRERROR_R -char *strerror_r (int errnum, char *buf, size_t buflen); -# endif -# else -# if !HAVE_DECL_STRERROR -char *strerror (int errnum); -# endif -# endif +#ifdef _LIBC +# include +# undef dgettext +# define dgettext(domain, msgid) \ + INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES) +#else +# include "gettext.h" #endif #include "argp.h" @@ -258,6 +228,9 @@ fill_in_uparams (const struct argp_state *state) /* Returns true if OPT is an documentation-only entry. */ #define odoc(opt) ((opt)->flags & OPTION_DOC) +/* Returns true if OPT should not be translated */ +#define onotrans(opt) ((opt)->flags & OPTION_NO_TRANS) + /* Returns true if OPT is the end-of-list marker for a list of options. */ #define oend(opt) __option_is_end (opt) @@ -453,9 +426,8 @@ make_hol (const struct argp *argp, struct hol_cluster *cluster) hol->short_options = malloc (num_short_options + 1); assert (hol->entries && hol->short_options); -#if SIZE_MAX <= UINT_MAX - assert (hol->num_entries <= SIZE_MAX / sizeof (struct hol_entry)); -#endif + if (SIZE_MAX <= UINT_MAX) + assert (hol->num_entries <= SIZE_MAX / sizeof (struct hol_entry)); /* Fill in the entries. */ so = hol->short_options; @@ -707,14 +679,20 @@ static int canon_doc_option (const char **name) { int non_opt; - /* Skip initial whitespace. */ - while (isspace (**name)) - (*name)++; - /* Decide whether this looks like an option (leading `-') or not. */ - non_opt = (**name != '-'); - /* Skip until part of name used for sorting. */ - while (**name && !isalnum (**name)) - (*name)++; + + if (!*name) + non_opt = 1; + else + { + /* Skip initial whitespace. */ + while (isspace (**name)) + (*name)++; + /* Decide whether this looks like an option (leading `-') or not. */ + non_opt = (**name != '-'); + /* Skip until part of name used for sorting. */ + while (**name && !isalnum (**name)) + (*name)++; + } return non_opt; } @@ -849,9 +827,8 @@ hol_append (struct hol *hol, struct hol *more) malloc (hol_so_len + strlen (more->short_options) + 1); assert (entries && short_options); -#if SIZE_MAX <= UINT_MAX - assert (num_entries <= SIZE_MAX / sizeof (struct hol_entry)); -#endif + if (SIZE_MAX <= UINT_MAX) + assert (num_entries <= SIZE_MAX / sizeof (struct hol_entry)); __mempcpy (__mempcpy (entries, hol->entries, hol->num_entries * sizeof (struct hol_entry)), @@ -1113,13 +1090,15 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state, { __argp_fmtstream_set_wmargin (stream, uparams.doc_opt_col); for (opt = real, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) + if (opt->name && *opt->name && ovisible (opt)) { comma (uparams.doc_opt_col, &pest); - /* Calling gettext here isn't quite right, since sorting will + /* Calling dgettext here isn't quite right, since sorting will have been done on the original; but documentation options should be pretty rare anyway... */ __argp_fmtstream_puts (stream, + onotrans (opt) ? + opt->name : dgettext (state->root_argp->argp_domain, opt->name)); } @@ -1690,20 +1669,13 @@ void __argp_help (const struct argp *argp, FILE *stream, weak_alias (__argp_help, argp_help) #endif -#ifndef _LIBC -char *__argp_basename (char *name) -{ - char *short_name = strrchr (name, '/'); - return short_name ? short_name + 1 : name; -} - +#if ! (defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME) char * __argp_short_program_name (void) { -# if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME - return program_invocation_short_name; -# elif HAVE_DECL_PROGRAM_INVOCATION_NAME - return __argp_basename (program_invocation_name); +# if HAVE_DECL_PROGRAM_INVOCATION_NAME + char *name = strrchr (program_invocation_name, '/'); + return name ? name + 1 : program_invocation_name; # else /* FIXME: What now? Miles suggests that it is better to use NULL, but currently the value is passed on directly to fputs_unlocked, @@ -1874,13 +1846,20 @@ __argp_failure (const struct argp_state *state, int status, int errnum, else #endif { + char const *s = NULL; putc_unlocked (':', stream); putc_unlocked (' ', stream); -#if defined _LIBC || defined HAVE_STRERROR_R - fputs (__strerror_r (errnum, buf, sizeof (buf)), stream); -#else - fputs (strerror (errnum), stream); +#if _LIBC || (HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P) + s = __strerror_r (errnum, buf, sizeof buf); +#elif HAVE_DECL_STRERROR_R + if (__strerror_r (errnum, buf, sizeof buf) == 0) + s = buf; +#endif +#if !_LIBC + if (! s && ! (s = strerror (errnum))) + s = "Unknown system error"; /* FIXME: translate this */ #endif + fputs (s, stream); } }