Re: GUC names in messages

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Peter Smith <smithpb2250(at)gmail(dot)com>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Daniel Gustafsson <daniel(at)yesql(dot)se>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: GUC names in messages
Date: 2023-11-30 10:57:05
Message-ID: 202311301057.ouymmefjhxng@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


> +/*
> + * Return whether the GUC name should be enclosed in double-quotes.
> + *
> + * Quoting is intended for names which could be mistaken for normal English
> + * words. Quotes are only applied to GUC names that are written entirely with
> + * lower-case alphabetical characters.
> + */
> +static bool
> +quotes_needed_for_GUC_name(const char *name)
> +{
> + for (const char *p = name; *p; p++)
> + {
> + if ('a' > *p || *p > 'z')
> + return false;
> + }
> +
> + return true;
> +}

I think you need a function that the name possibly quoted, in a way that
lets the translator handle the quoting:

static char buffer[SOMEMAXLEN];

quotes_needed = ...;

if (quotes_needed)
/* translator: a quoted configuration parameter name */
snprintf(buffer, _("\"%s\""), name);
return buffer
else
/* no translation needed in this case */
return name;

then the calling code just does a single %s that prints the string
returned by this function. (Do note that the function is not reentrant,
like pg_dump's fmtId. Shouldn't be a problem ...)

> @@ -3621,8 +3673,8 @@ set_config_option_ext(const char *name, const char *value,
> {
> if (changeVal && !makeDefault)
> {
> - elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
> - name);
> + elog(DEBUG3, "%s%s%s: setting ignored because previous source is higher priority",
> + GUC_FORMAT(name));

Note that elog() doesn't do translation, and DEBUG doesn't really need
to worry too much about style anyway. I'd leave these as-is.

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"La primera ley de las demostraciones en vivo es: no trate de usar el sistema.
Escriba un guión que no toque nada para no causar daños." (Jakob Nielsen)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alena Rybakina 2023-11-30 10:57:26 Re: POC, WIP: OR-clause support for indexes
Previous Message Amit Kapila 2023-11-30 10:56:08 Re: [Proposal] global sequence implemented by snowflake ID