From e5fe9ad9e83e6765cf8fa787f903d4c6792338b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Rolim?= Date: Tue, 16 Feb 2021 01:47:29 -0300 Subject: [PATCH] Check for libintl header and add dgettext wrapper. The dgettext_safe wrapper is used in the few situations where it wasn't possible to immediatelly tell that the msgid parameter wasn't NULL. We can probably add some debug printing code here at some point to try and bring bugs upstream, if it makes sense. Some inspiration from https://github.com/xhebox/libuargp --- argp-help.c | 15 +++++++++------ configure.ac | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/argp-help.c b/argp-help.c index a12367b..6f64056 100644 --- a/argp-help.c +++ b/argp-help.c @@ -56,9 +56,9 @@ char *alloca (); #ifndef _ /* This is for other GNU distributions with internationalized messages. */ -# if defined HAVE_LIBINTL_H || defined _LIBC +# if defined HAVE_LIBINTL_H || 0 # include -# ifdef _LIBC +# if 0 # undef dgettext # define dgettext(domain, msgid) \ __dcgettext (domain, msgid, LC_MESSAGES) @@ -68,6 +68,9 @@ char *alloca (); # endif #endif +/* can't use macro due to double evaluation */ +static char * dgettext_safe(const char *d, const char *m) { return m ? dgettext(d, m) : NULL; } + #include #include #include "argp-namefrob.h" @@ -996,7 +999,7 @@ static void print_header (const char *str, const struct argp *argp, struct pentry_state *pest) { - const char *tstr = dgettext (argp->argp_domain, str); + const char *tstr = dgettext_safe (argp->argp_domain, str); const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_HEADER, argp, pest->state); if (fstr) @@ -1150,7 +1153,7 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state, } else { - const char *tstr = real->doc ? dgettext (state == NULL ? NULL + const char *tstr = real->doc ? dgettext_safe (state == NULL ? NULL : state->root_argp->argp_domain, real->doc) : 0; const char *fstr = filter_doc (tstr, real->key, entry->argp, state); @@ -1387,7 +1390,7 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state, char *our_level = *levels; int multiple = 0; const struct argp_child *child = argp->children; - const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0; + const char *tdoc = dgettext_safe (argp->argp_domain, argp->args_doc), *nl = 0; const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state); if (fdoc) @@ -1452,7 +1455,7 @@ argp_doc (const struct argp *argp, const struct argp_state *state, void *input = 0; int anything = 0; size_t inp_text_limit = 0; - const char *doc = dgettext (argp->argp_domain, argp->doc); + const char *doc = dgettext_safe (argp->argp_domain, argp->doc); const struct argp_child *child = argp->children; if (doc) diff --git a/configure.ac b/configure.ac index 9068110..386215d 100644 --- a/configure.ac +++ b/configure.ac @@ -26,7 +26,7 @@ fi # Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS(limits.h malloc.h unistd.h) +AC_CHECK_HEADERS(limits.h malloc.h unistd.h libintl.h) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST