aboutsummaryrefslogtreecommitdiffstats
path: root/common/t-helpfile.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2025-05-28 13:19:19 +0000
committerWerner Koch <[email protected]>2025-05-30 12:19:02 +0000
commit8d837279bce7fbbf72e1751ff1bd2c8889e96fb4 (patch)
tree7175881d04b4190a2eb782b2f319081f539565ca /common/t-helpfile.c
parentgpgtar: Fix regression exhibited by make check (diff)
downloadgnupg-8d837279bce7fbbf72e1751ff1bd2c8889e96fb4.tar.gz
gnupg-8d837279bce7fbbf72e1751ff1bd2c8889e96fb4.zip
common: Improve helpfile.c to provide a generic template API.
* common/util.h (GET_TEMPLATE_CURRENT_LOCALE): New. (GET_TEMPLATE_SUBST_ENVVARS): New. (GET_TEMPLATE_CRLF): New. * common/helpfile.c (findkey_fname): Add arg flags and terminate line with CRLF if requested. (findkey_locale): Replace arg only_current_locale by flags and add arg domain. (gnupg_get_help_string): Factor all code out to ... (gnupg_get_template): new. Add arg domain. Handle SUBST flags. Do not trim tralins spaces with the CRLF flag. * common/t-helpfile.c (main): Require domain name and add two options.
Diffstat (limited to 'common/t-helpfile.c')
-rw-r--r--common/t-helpfile.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/common/t-helpfile.c b/common/t-helpfile.c
index 0e2c79f2d..adb69ba2d 100644
--- a/common/t-helpfile.c
+++ b/common/t-helpfile.c
@@ -39,6 +39,7 @@ int
main (int argc, char **argv)
{
char *result;
+ unsigned int flags = 0;
if (argc)
{ argc--; argv++; }
@@ -48,17 +49,35 @@ main (int argc, char **argv)
verbose = 1;
argc--; argv++;
}
+ if (argc && !strcmp (argv[0], "--env"))
+ {
+ flags |= GET_TEMPLATE_SUBST_ENVVARS;
+ argc--; argv++;
+ }
+ if (argc && !strcmp (argv[0], "--crlf"))
+ {
+ flags |= GET_TEMPLATE_CRLF;
+ argc--; argv++;
+ }
+ if (argc != 2)
+ {
+ fprintf (stderr, "Usage: t-helpfile [--env] [--crlf] domain key\n");
+ exit (2);
+ }
+
- result = gnupg_get_help_string (argc? argv[0]:NULL, 0);
+ result = gnupg_get_template (argv[0], argv[1], flags);
if (!result)
{
fprintf (stderr,
- "Error: nothing found for '%s'\n", argc?argv[0]:"(null)");
+ "Error: nothing found for '%s' in domain '%s'\n",
+ argv[1], argv[0]);
errcount++;
}
else
{
- printf ("key '%s' result='%s'\n", argc?argv[0]:"(null)", result);
+ printf ("domain '%s' key '%s' result='%s'\n",
+ argv[0], argv[1], result);
xfree (result);
}