From 2e3850cc898dd13f81cc5ed7c14a5131aa06e197 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Mon, 22 Nov 2021 21:54:58 -0500 Subject: [PATCH] help_print_desc: Allow NULL option to disable localisation. This enables the block-indenting functionality to be used in other contexts. --- src/help.c | 5 ++++- src/help.h | 9 +++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/help.c b/src/help.c index d1dd5f5..b09833a 100644 --- a/src/help.c +++ b/src/help.c @@ -179,7 +179,10 @@ out: void help_print_desc(const struct option *opt, const char *s, int i, int w) { - for (s = pgettext_expr(opt->name, s); *s; w = 0) { + if (opt) + s = pgettext_expr(opt->name, s); + + for (; *s; w = 0) { const char *nl = strchr(s, '\n'); int n = (nl ? nl-s : -1); diff --git a/src/help.h b/src/help.h index 9eb2654..a78bc59 100644 --- a/src/help.h +++ b/src/help.h @@ -23,10 +23,11 @@ struct option; int help_print_optstring(const struct option *opt, const char *argname, int l); /* - * Print an option description with each line indented. The string is first - * localized (if NLS is enabled). The first line will be indented by i-w - * spaces (to account for the cursor being in some other column), all other - * lines are indented by i spaces. + * Print an option description with each line indented. If opt is not NULL, + * then the string is first localized (if NLS is enabled) via pgettext_expr + * with the context set to opt->name. The first line will be indented by + * i-w spaces (to account for the cursor being in some other column), all + * other lines are indented by i spaces. */ void help_print_desc(const struct option *opt, const char *desc, int i, int w); -- 2.43.2