mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
Add strusage macro replacement feature.
* common/argparse.c (writechar): New. (writestrings): Add macro replacement feature. (show_help): Remove specialized @EMAIL@ replacement. * configure.ac (GNUPG_NAME, GPG_NAME, GPGSM_NAME): Define. (GPG_AGENT_NAME, DIRMNGR_NAME, G13_NAME, GPGCONF_NAME): Define. (GPGTAR_NAME, GPG_AGENT_INFO_NAME, GPG_AGENT_SOCK_NAME): Define. (GPG_AGENT_SSH_SOCK_NAME, DIRMNGR_INFO_NAME): Define. (DIRMNGR_SOCK_NAME): Define. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
5499942571
commit
798daaa1dd
@ -185,6 +185,19 @@ argparse_register_outfnc (int (*fnc)(int, const char *))
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
writechar (int is_error, int c)
|
||||
{
|
||||
char tmp[2];
|
||||
|
||||
tmp[0] = c;
|
||||
tmp[1] = 0;
|
||||
if (custom_outfnc)
|
||||
custom_outfnc (is_error? 2:1, tmp);
|
||||
else
|
||||
fputs (tmp, is_error? stderr : stdout);
|
||||
}
|
||||
|
||||
/* Write STRING and all following const char * arguments either to
|
||||
stdout or, if IS_ERROR is set, to stderr. The list of strings must
|
||||
be terminated by a NULL. */
|
||||
@ -201,11 +214,64 @@ writestrings (int is_error, const char *string, ...)
|
||||
va_start (arg_ptr, string);
|
||||
do
|
||||
{
|
||||
if (custom_outfnc)
|
||||
custom_outfnc (is_error? 2:1, s);
|
||||
const char *s2, *s3;
|
||||
|
||||
/* Check whether to substitute a macro. */
|
||||
if (s && (s2 = strchr (s, '@')) && s2[1] >= 'A' && s2[1] <= 'Z'
|
||||
&& (s3 = (strchr (s2+1, '@'))))
|
||||
{
|
||||
/* Might be. */
|
||||
static struct {
|
||||
const char *name;
|
||||
const char *value;
|
||||
} macros[] = {
|
||||
# ifdef PACKAGE_BUGREPORT
|
||||
{ "EMAIL", PACKAGE_BUGREPORT },
|
||||
# else
|
||||
{ "EMAIL", "bug@example.org" },
|
||||
# endif
|
||||
{ "GNUPG", GNUPG_NAME },
|
||||
{ "GPG", GPG_NAME },
|
||||
{ "GPGSM", GPGSM_NAME },
|
||||
{ "GPG_AGENT", GPG_AGENT_NAME },
|
||||
{ "SCDAEMON", SCDAEMON_NAME },
|
||||
{ "DIRMNGR", DIRMNGR_NAME },
|
||||
{ "G13", G13_NAME },
|
||||
{ "GPGCONF", GPGCONF_NAME },
|
||||
{ "GPGTAR", GPGTAR_NAME }
|
||||
};
|
||||
int idx;
|
||||
|
||||
s2++;
|
||||
for (idx=0; idx < DIM (macros); idx++)
|
||||
if (strlen (macros[idx].name) == (s3 - s2)
|
||||
&& !memcmp (macros[idx].name, s2, (s3 - s2)))
|
||||
break;
|
||||
s2--;
|
||||
if (idx < DIM (macros)) /* Found. Print and substitute. */
|
||||
{
|
||||
for (; s < s2; s++, count++)
|
||||
writechar (is_error, *s);
|
||||
count += writestrings (is_error, macros[idx].value, NULL);
|
||||
s3++;
|
||||
}
|
||||
else /* Not found. Print macro as is. */
|
||||
{
|
||||
for (; s < s3; s++, count++)
|
||||
writechar (is_error, *s);
|
||||
}
|
||||
/* Now recurse so that remaining macros are also
|
||||
substituted. */
|
||||
count += writestrings (is_error, s3, NULL);
|
||||
}
|
||||
else
|
||||
fputs (s, is_error? stderr : stdout);
|
||||
count += strlen (s);
|
||||
{
|
||||
if (custom_outfnc)
|
||||
custom_outfnc (is_error? 2:1, s);
|
||||
else
|
||||
fputs (s, is_error? stderr : stdout);
|
||||
count += strlen (s);
|
||||
}
|
||||
}
|
||||
while ((s = va_arg (arg_ptr, const char *)));
|
||||
va_end (arg_ptr);
|
||||
@ -1222,35 +1288,8 @@ show_help (ARGPARSE_OPTS *opts, unsigned int flags)
|
||||
}
|
||||
if ( (s=strusage(19)) )
|
||||
{
|
||||
/* bug reports to ... */
|
||||
char *s2;
|
||||
|
||||
writestrings (0, "\n", NULL);
|
||||
s2 = strstr (s, "@EMAIL@");
|
||||
if (s2)
|
||||
{
|
||||
if (s2-s)
|
||||
{
|
||||
const char *s3;
|
||||
|
||||
for (s3=s; s3 < s2; s3++)
|
||||
{
|
||||
tmp[0] = *s3;
|
||||
tmp[1] = 0;
|
||||
writestrings (0, tmp, NULL);
|
||||
}
|
||||
}
|
||||
#ifdef PACKAGE_BUGREPORT
|
||||
writestrings (0, PACKAGE_BUGREPORT, NULL);
|
||||
#else
|
||||
writestrings (0, "bug@example.org", NULL);
|
||||
#endif
|
||||
s2 += 7;
|
||||
if (*s2)
|
||||
writestrings (0, s2, NULL);
|
||||
}
|
||||
else
|
||||
writestrings (0, s, NULL);
|
||||
writestrings (0, s, NULL);
|
||||
}
|
||||
flushstrings (0);
|
||||
exit(0);
|
||||
|
26
configure.ac
26
configure.ac
@ -1574,6 +1574,32 @@ if test "$build_g13" = yes ; then
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Define Name strings
|
||||
#
|
||||
AC_DEFINE_UNQUOTED(GNUPG_NAME, "GnuPG", [The name of the project])
|
||||
AC_DEFINE_UNQUOTED(GPG_NAME, "gpg", [The name of the OpenPGP tool])
|
||||
AC_DEFINE_UNQUOTED(GPGSM_NAME, "gpgsm", [The name of the S/MIME tool])
|
||||
AC_DEFINE_UNQUOTED(GPG_AGENT_NAME, "gpg-agent", [The name of the agent])
|
||||
AC_DEFINE_UNQUOTED(SCDAEMON_NAME, "scdaemon", [The name of the scdaemon])
|
||||
AC_DEFINE_UNQUOTED(DIRMNGR_NAME, "dirmngr", [The name of the dirmngr])
|
||||
AC_DEFINE_UNQUOTED(G13_NAME, "g13", [The name of the g13 tool])
|
||||
AC_DEFINE_UNQUOTED(GPGCONF_NAME, "gpgconf", [The name of the gpgconf tool])
|
||||
AC_DEFINE_UNQUOTED(GPGTAR_NAME, "gpgtar", [The name of the gpgtar tool])
|
||||
|
||||
AC_DEFINE_UNQUOTED(GPG_AGENT_INFO_NAME, "GPG_AGENT_INFO",
|
||||
[The name of the agent info envvar])
|
||||
AC_DEFINE_UNQUOTED(GPG_AGENT_SOCK_NAME, "S.gpg-agent",
|
||||
[The name of the agent socket])
|
||||
AC_DEFINE_UNQUOTED(GPG_AGENT_SSH_SOCK_NAME, "S.gpg-agent.ssh",
|
||||
[The name of the agent socket for ssh])
|
||||
AC_DEFINE_UNQUOTED(DIRMNGR_INFO_NAME, "DIRMNGR_INFO",
|
||||
[The name of the dirmngr info envvar])
|
||||
AC_DEFINE_UNQUOTED(DIRMNGR_SOCK_NAME, "S.dirmngr",
|
||||
[The name of the dirmngr socket])
|
||||
|
||||
AC_DEFINE_UNQUOTED(GPGEXT_GPG, "gpg", [The standard binary file suffix])
|
||||
|
||||
|
||||
#
|
||||
# Provide information about the build.
|
||||
|
Loading…
x
Reference in New Issue
Block a user