Date: Tue, 23 Dec 1997 07:11:25 -0800 (PST) From: jose@we.lc.ehu.es To: freebsd-gnats-submit@FreeBSD.ORG Subject: bin/5368: the behavior of isprint(3) is not affected by ISO-8859-1 locale settings Message-ID: <199712231511.HAA12601@hub.freebsd.org> Resent-Message-ID: <199712231520.HAA13046@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 5368
>Category: bin
>Synopsis: the behavior of isprint(3) is not affected by ISO-8859-1 locale settings
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Tue Dec 23 07:20:00 PST 1997
>Last-Modified:
>Originator: Jose M. Alcaide
>Organization:
Universidad del Pais Vasco - Dept. Electricidad y Electronica
>Release: 2.2.5-RELEASE
>Environment:
FreeBSD tiburon.we.lc.ehu.es 2.2.5-RELEASE FreeBSD 2.2.5-RELEASE #0: Wed Oct 29 15:20:18 CET 1997 root@tiburon.we.lc.ehu.es:/usr/src/sys/compile/TIBURON i386
>Description:
The setlocale(3) manual page says:
...
LC_CTYPE Set a locale for the ctype(3), mbrune(3), multibyte(3) and
rune(3) functions. This controls recognition of upper and
lower case, alphabetic or non-alphabetic characters, and so
on. The real work is done by the setrunelocale() function.
...
However, if LANG is set to any locale that uses ISO-8859-1 character
coding, then isprint(c), where c is any printable char such as
ñ, é, ¡, ¿, and so on, returns 0 (not printable).
The incorrect behavior of isprint() affects vi(1). This editor relies
on isprint() to decide whether to display a character "as is", or
substitute it for its hex coding (\xDD).
>How-To-Repeat:
Edit and compile the following tiny program:
--------------------------------
#include <stdio.h>
#include <ctype.h>
#include <locale.h>
main()
{
char c, *s;
printf("Old locale: %s\n", setlocale(LC_CTYPE, NULL));
if ((s = setlocale(LC_CTYPE, "")) == NULL)
{
fprintf(stderr, "setlocale() failed.\n");
exit(1);
}
else
printf("New locale: %s\n", s);
printf("Type any string ended by RETURN: ");
while ((c = getchar()) != '\n')
printf("%c: %s\n", c, isprint(c) ? "PRINTABLE" : "UNPRINTABLE");
exit(0);
}
-------------------------------------
Then, set the LANG environment variable:
LANG=es_ES.ISO_8859-1; export LANG
or setenv LANG es_ES.ISO_8859-1
Next, run the program:
jose@tiburon[~]$ ./a.out
Old locale: C
New locale: es_ES.ISO_8859-1
Type any string ended by RETURN: ñÑéÉ¡¿aeiou
ñ: UNPRINTABLE
Ñ: UNPRINTABLE
é: UNPRINTABLE
É: UNPRINTABLE
¡: UNPRINTABLE
¿: UNPRINTABLE
a: PRINTABLE
e: PRINTABLE
i: PRINTABLE
o: PRINTABLE
u: PRINTABLE
The result is obvious: isprint() does not recognise as printable
ISO-8859-1 characters which _are_ printable in that locale.
>Fix:
None.
>Audit-Trail:
>Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199712231511.HAA12601>
