Re: [PATCH 1/2] rpmatch.3: remove first-character-only FUD

Alejandro Colomar (man-pages)
2021-09-21T15:20:38Z

Hi, наб!

On 9/21/21 3:46 PM, наб wrote:
> It's plain not true; locales can and do provide longer matches
> (Aramaic has a "አዎን" alternative, for example)
>
> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>

Are you sure?

I just checked the glibc implementation, and it uses YESEXPR and NOEXPR
(instead of YESSTR and NOSTR, which would match complete strings).

// stdlib/rpmatch.c
int
rpmatch (const char *response)
{
/* We cache the response patterns and compiled regexps here. */
static const char *yesexpr, *noexpr;
static regex_t yesre, nore;

return (try (response, YESEXPR, 1, 0, &yesexpr, &yesre) ?:
try (response, NOEXPR, 0, -1, &noexpr, &nore));
}

$ grep -rn define.*YESEXPR;
locale/langinfo.h:570:#define YESEXPR __YESEXPR

$ grep -rn __YESEXPR;
locale/langinfo.h:569: __YESEXPR = _NL_ITEM (__LC_MESSAGES, 0), /*
Regex matching ``yes'' input. */
locale/langinfo.h:570:#define YESEXPR __YESEXPR

$ grep -rn 'define _NL_ITEM(';
locale/langinfo.h:34:#define _NL_ITEM(category, index) (((category) <<
16) | (index))

$ grep -rn LC_MESSAGES localedata/ | grep es_ES
localedata/locales/es_ES@euro:37:category "i18n:2012";LC_MESSAGES
localedata/locales/es_ES@euro:53:LC_MESSAGES
localedata/locales/es_ES@euro:55:END LC_MESSAGES
localedata/locales/es_ES:45:category "i18n:2012";LC_MESSAGES
localedata/locales/es_ES:113:LC_MESSAGES
localedata/locales/es_ES:118:END LC_MESSAGES

$ sed -n '/^LC_MESSAGES/,/END LC_MESSAGES/p' localedata/locales/es_ES;
LC_MESSAGES
yesexpr "^[+1sSyY]"
noexpr "^[-0nN]"
yesstr "sí"
nostr "no"
END LC_MESSAGES

So, it seems to me that by using {yes,no}expr and not {yes,no}str, it is
limiting itself to the first letter, as the current BUGS section
specifies. Right?

Thanks,

Alex

> ---
> man3/rpmatch.3 | 15 ---------------
> 1 file changed, 15 deletions(-)
>
> diff --git a/man3/rpmatch.3 b/man3/rpmatch.3
> index 846c492b7..e0f92a20d 100644
> --- a/man3/rpmatch.3
> +++ b/man3/rpmatch.3
> @@ -123,21 +123,6 @@ T} Thread safety MT-Safe locale
> is not required by any standard, but
> is available on a few other systems.
> .\" It is available on at least AIX 5.1 and FreeBSD 6.0.
> -.SH BUGS
> -The
> -.BR rpmatch ()
> -implementation looks at only the first character
> -of
> -.IR response .
> -As a consequence, "nyes" returns 0, and
> -"ynever; not in a million years" returns 1.
> -It would be preferable to accept input strings much more
> -strictly, for example (using the extended regular
> -expression notation described in
> -.BR regex (7)):
> -.B \(ha([yY]|yes|YES)$
> -and
> -.BR \(ha([nN]|no|NO)$ .
> .SH EXAMPLES
> The following program displays the results when
> .BR rpmatch ()
>

--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/