tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: curses vs non-ASCII

>> At a guess I would say that you have stumbled across a character
>> sequence that happens to be valid multibyte character but I haven't
>> looked closely.  What does mbrtowc(3) do with that sequence?

It currently appears it's not a multibyte issue.  On my morning
commute I wrote a small test program (below) and it makes me think
mbrtowc is not at fault here.  Its output on my test system is

offset 0: byte count 1, wc 0xb7
offset 1: byte count 1, wc 0x20
offset 2: byte count 1, wc 0x20
offset 3: byte count 1, wc 0x41
offset 4: byte count 1, wc 0x62
offset 5: byte count 1, wc 0x62
offset 6: byte count 1, wc 0x61
offset 7: byte count 1, wc 0x3a
offset 8: byte count 1, wc 0x20
offset 9: byte count 1, wc 0x54

This then forces me to wonder what is.  It seems to me that, regardless
of whether it's considered printable, curses should not misbehave: if
it's printable, it should have been printed; if not, it should have
been dropped.  This leads me to suspect this is actually a curses bug.
This might also explain why Martin Husemann did not see any
misbehaviour under current - current may well have a curses without
that (putative) bug.

I'm going to take the misbehaving test program, the one I posted
earlier, and add a bunch of move()/inch() pairs (there seems to be no
mvinch, oddly) to see what curses thinks is supposed to be displayed.

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

#include <wchar.h>
#include <errno.h>
#include <strings.h>

int main(void);
int main(void)
 size_t rv;
 wchar_t wc;
 mbstate_t s;
 const char *str;
 int so;
 int i;

 str = "\267  Abba: Thank You For The Music (Disc 3)";
 so = 0;
 for (i=10;i>0;i--)
  { printf("offset %d: ",so);
    rv = mbrtowc(&wc,str+so,41-so,&s);
    if (rv == 0)
     { printf("nul\n");
       /* XXX No way to tell how many bytes of s this consumes,
	  so all we can do is bail now */
    else if (rv > 0)
     { printf("byte count %d, wc %#x\n",(int)rv,(int)wc);
       so += rv;
    else if (rv == (size_t)-2)
     { printf("partial\n");
    else if (rv == (size_t)-1)
     { printf("illegal [%s]\n",strerror(errno));
     { printf("undocumented return %d\n",(int)rv);

Home | Main Index | Thread Index | Old Index