popt/0004-Make-help-and-usage-translatable.patch

124 lines
4.9 KiB
Diff
Raw Normal View History

From 1d86877a865338e554aa2480f021da517a86954f Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 28 Jul 2017 15:18:46 -0400
Subject: [PATCH 4/4] Make --help and --usage translatable.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Patch initially by Miloslav Trmač <mitr@redhat.com> and revised by Akira Tagoh
<tagoh@redhat.com> for popt <= 1.16 which fixes the problem that help messages
for --help and --usage seem not translatable. There already was some i18n support
for autohelp in popt.c, but not in popthelp.c, where it actually matters.
See https://bugzilla.redhat.com/show_bug.cgi?id=734434 for further details, please.
This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0287.html
---
popthelp.c | 39 ++++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 13 deletions(-)
diff --git a/popthelp.c b/popthelp.c
index 4859980..008fb2b 100644
--- a/popthelp.c
+++ b/popthelp.c
@@ -89,7 +89,7 @@ static struct poptOption poptHelpOptions2[] = {
{ "defaults", '\0', POPT_ARG_NONE, &show_option_defaults, 0,
N_("Display option defaults in message"), NULL },
#endif
- { "", '\0', 0, NULL, 0, N_("Terminate options"), NULL },
+ { NULL, '\0', 0, NULL, 0, N_("Terminate options"), NULL },
POPT_TABLEEND
} ;
@@ -527,8 +527,11 @@ static size_t maxArgWidth(const struct poptOption * opt,
if (opt != NULL)
while (opt->longName || opt->shortName || opt->arg) {
if (poptArgType(opt) == POPT_ARG_INCLUDE_TABLE) {
- if (opt->arg) /* XXX program error */
- len = maxArgWidth(opt->arg, translation_domain);
+ void * arg = opt->arg;
+ /* XXX sick hack to preserve pretense of ABI. */
+ if (arg == poptHelpOptions) arg = poptHelpOptionsI18N;
+ if (arg) /* XXX program error */
+ len = maxArgWidth(arg, translation_domain);
if (len > max) max = len;
} else if (!F_ISSET(opt, DOC_HIDDEN)) {
len = sizeof(" ")-1;
@@ -619,19 +622,22 @@ static void singleTableHelp(poptContext con, FILE * fp,
if (table != NULL)
for (opt = table; opt->longName || opt->shortName || opt->arg; opt++) {
+ void * arg = opt->arg;
if (poptArgType(opt) != POPT_ARG_INCLUDE_TABLE)
continue;
- sub_transdom = getTableTranslationDomain(opt->arg);
+ /* XXX sick hack to preserve pretense of ABI. */
+ if (arg == poptHelpOptions) arg = poptHelpOptionsI18N;
+ sub_transdom = getTableTranslationDomain(arg);
if (sub_transdom == NULL)
sub_transdom = translation_domain;
/* If no popt aliases/execs, skip poptAliasOption processing. */
- if (opt->arg == poptAliasOptions && !(con->numAliases || con->numExecs))
+ if (arg == poptAliasOptions && !(con->numAliases || con->numExecs))
continue;
if (opt->descrip)
xx = POPT_fprintf(fp, "\n%s\n", D_(sub_transdom, opt->descrip));
- singleTableHelp(con, fp, opt->arg, columns, sub_transdom);
+ singleTableHelp(con, fp, arg, columns, sub_transdom);
}
}
@@ -808,22 +814,25 @@ static size_t singleTableUsage(poptContext con, FILE * fp, columns_t columns,
translation_domain = (const char *)opt->arg;
} else
if (poptArgType(opt) == POPT_ARG_INCLUDE_TABLE) {
+ void * arg = opt->arg;
+ /* XXX sick hack to preserve pretense of ABI. */
+ if (arg == poptHelpOptions) arg = poptHelpOptionsI18N;
if (done) {
int i = 0;
if (done->opts != NULL)
for (i = 0; i < done->nopts; i++) {
const void * that = done->opts[i];
- if (that == NULL || that != opt->arg)
+ if (that == NULL || that != arg)
/*@innercontinue@*/ continue;
/*@innerbreak@*/ break;
}
/* Skip if this table has already been processed. */
- if (opt->arg == NULL || i < done->nopts)
+ if (arg == NULL || i < done->nopts)
continue;
if (done->opts != NULL && done->nopts < done->maxopts)
- done->opts[done->nopts++] = (const void *) opt->arg;
+ done->opts[done->nopts++] = (const void *) arg;
}
- columns->cur = singleTableUsage(con, fp, columns, opt->arg,
+ columns->cur = singleTableUsage(con, fp, columns, arg,
translation_domain, done);
} else
if ((opt->longName || opt->shortName) && !F_ISSET(opt, DOC_HIDDEN)) {
@@ -864,9 +873,13 @@ static size_t showShortOptions(const struct poptOption * opt, FILE * fp,
if (!strchr(s, opt->shortName) && isprint((int)opt->shortName)
&& opt->shortName != ' ')
s[strlen(s)] = opt->shortName;
- } else if (poptArgType(opt) == POPT_ARG_INCLUDE_TABLE)
- if (opt->arg) /* XXX program error */
- len = showShortOptions(opt->arg, fp, s);
+ } else if (poptArgType(opt) == POPT_ARG_INCLUDE_TABLE) {
+ void * arg = opt->arg;
+ /* XXX sick hack to preserve pretense of ABI. */
+ if (arg == poptHelpOptions) arg = poptHelpOptionsI18N;
+ if (arg) /* XXX program error */
+ len = showShortOptions(arg, fp, s);
+ }
}
/* On return to top level, print the short options, return print length. */
--
2.13.3