From nobody  Tue Dec 23 07:11:25 1997
Received: (from nobody@localhost)
          by hub.freebsd.org (8.8.7/8.8.7) id HAA12601;
          Tue, 23 Dec 1997 07:11:25 -0800 (PST)
          (envelope-from nobody)
Message-Id: <199712231511.HAA12601@hub.freebsd.org>
Date: Tue, 23 Dec 1997 07:11:25 -0800 (PST)
From: jose@we.lc.ehu.es
To: freebsd-gnats-submit@freebsd.org
Subject: the behavior of isprint(3) is not affected by ISO-8859-1 locale settings
X-Send-Pr-Version: www-1.0

>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:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 23 07:20:00 PST 1997
>Closed-Date:    Wed Dec 24 16:03:30 PST 1997
>Last-Modified:  Wed Dec 24 16:13:21 PST 1997
>Originator:     Jose M. Alcaide
>Release:        2.2.5-RELEASE
>Organization:
Universidad del Pais Vasco - Dept. Electricidad y Electronica
>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.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: helbig 
State-Changed-When: Wed Dec 24 16:03:30 PST 1997 
State-Changed-Why:  
This is an error of the supplied program, not isprint(3). 
The parameter passed to isprint(3) is declared as char, which 
will be converted to int. Because of sign extension this results 
in negative values for chars greater than 127. 
So just declare "int c" instead of "char c" and everything will 
work as expected. 
>Unformatted:
