Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Dec 1997 17:54:18 +0100
From:      "Jose M. Alcaide" <jose@we.lc.ehu.es>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Re: International characters in vi are displayed as hex?  2.2.5-RELEASE
Message-ID:  <349803BA.9616530@we.lc.ehu.es>
References:  <3.0.32.19971209154440.00760f4c@lda>

next in thread | previous in thread | raw e-mail | index | archive | help
Peter Olsson wrote:
> 
> 16:36 1997-12-09 +0200, Ruslan Ermilov wrote:
> >Once Peter Olsson wrote:
> >> In 2.2.5-RELEASE vi displays international characters as hex.
> >>
> >> This worked fine in 2.1.0 after I set the right country-maps.
> >> I don't remember if it worked fine in 2.2.1 and/or 2.2.2.
> >
> >Did you set your LANG= environment variable properly?
> 
> I think so: LANG=sv_SE.ISO_8859-1; export LANG
> 
> This (and setting right iso-fonts in sysconfig/rc.conf) was what fixed
> this problem in 2.1.0 but it seems to have lost its effect now.

I have been working on this problem. Here is an excerpt from
/usr/src/contrib/nvi/FAQ:

> Q: How can I get vi to display my character set?
> A: Vi uses the C library routine isprint(3) to determine if a character
>    is printable, or should be displayed as an octal or hexadecimal value
>    on the screen.  Generally, if vi is displaying printable characters
>    in octal/hexadecimal forms, your environment is not configured correctly.
>    Try looking at the man pages that allow you to configure your locale.
>    For example, to configure an ISO 8859-1 locale under Solaris using csh,
>    you would do:
> 
>         setenv LANG C
>         setenv LC_CTYPE iso_8859_1
> 
>    Other LC_CTYPE systems/values that I'm told work:
> 
>    System       Value
>    ======       =====
>    FreeBSD      lt_LN.ISO_8859-1
>    HP-UX  9.X   american.iso88591
>    HP-UX 10.X   en_US.iso88591
>    SunOS  4.X   iso_8859_1
>    SunOS  5.X   iso_8859_1
> 
>    If there's no other solution, you can use the print and noprint edit
>    options of vi to specify that a specific character is printable or not
>    printable.

Well, the fact is that vi does not consider international characters
as printable, so I turned to test the isprint() library function:
I set the environment variable LANG=es_ES.ISO_8859-1, and run
the following little program:

> #include <stdio.h>
> #include <ctype.h>
> #include <locale.h>
> 
> main()
> {
>         char c;
> 
>         if (setlocale(LC_CTYPE, "") == NULL)
>         {
>                 fprintf(stderr, "Cascote el setlocale()\n");
>                 exit(1);
>         }
> 
>         while ((c = getchar()) != '\n')
>                 printf("%c: %s\n", c, isprint(c) ? "PRINTABLE" : "UNPRINTABLE");
> 
>         exit(0);
> }

This tiny program sets the locale from LANG, and then uses isprint()
to test the "printability" of characters entered from the keyboard.
This is the result:

> jose@tiburon[~]$ ./isprinttst
> nñ?¿ 
> n: PRINTABLE
> ñ: UNPRINTABLE
> ?: PRINTABLE
> ¿: UNPRINTABLE

Simply speaking, isprint() does not recognize as printable the
characters "ñ" and "¿", which are legal ISO-8859-1 characters.
Therefore, I think that something is broken in the ctype
macros/functions.

-- JM
-----------------------------------------------------------------------
Jose M. Alcaide                         | mailto:jose@we.lc.ehu.es
Universidad del Pais Vasco              | http://www.we.lc.ehu.es/~jose
Dpto. de Electricidad y Electronica     |
Facultad de Ciencias - Campus de Lejona | Tel.:  +34-4-4647700 x2624
48940 Lejona (Vizcaya) - SPAIN          | Fax:   +34-4-4858139
-----------------------------------------------------------------------
               "Go ahead... make my day." - H. Callahan



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?349803BA.9616530>