Ignore:
Timestamp:
Mar 16, 2006, 1:49:20 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Use UTF-8 enable ncurses (ncursesw) if available. Doesn't seem to work.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/driver_ncurses.c

    r613 r629  
    2222#if defined(USE_NCURSES)
    2323
    24 #if defined(HAVE_NCURSES_H)
     24#if defined(HAVE_NCURSESW_NCURSES_H)
     25#   include <ncursesw/ncurses.h>
     26#elif defined(HAVE_NCURSES_NCURSES_H)
     27#   include <ncurses/ncurses.h>
     28#elif defined(HAVE_NCURSES_H)
    2529#   include <ncurses.h>
    2630#else
     
    5458static void ncurses_check_terminal(void);
    5559#endif
     60static void ncurses_write_utf32(uint32_t);
    5661
    5762struct driver_private
     
    193198        for(x = kk->qq->width; x--; )
    194199        {
    195             uint32_t c = *chars++;
    196 
    197200            attrset(kk->drv.p->attr[*attr++]);
    198             if(c > 0x00000020 && c < 0x00000080)
    199                 addch((char)c);
    200             else
    201                 addch(' ');
     201            ncurses_write_utf32(*chars++);
    202202        }
    203203    }
     
    454454#endif
    455455
     456static void ncurses_write_utf32(uint32_t c)
     457{
     458#if defined(HAVE_NCURSESW_NCURSES_H)
     459    static const uint8_t mark[7] =
     460    {
     461        0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
     462    };
     463
     464    char buf[10], *parser;
     465    int bytes;
     466#endif
     467
     468    if(c < 0x80)
     469    {
     470        addch(c);
     471        return;
     472    }
     473
     474#if defined(HAVE_NCURSESW_NCURSES_H)
     475    if(c < 0x10000)
     476    {
     477        addch(c); /* FIXME: doesn't work either */
     478        return;
     479    }
     480
     481    bytes = (c < 0x800) ? 2 : (c < 0x10000) ? 3 : 4;
     482    buf[bytes] = '\0';
     483    parser = buf + bytes;
     484
     485    switch(bytes)
     486    {
     487        case 4: *--parser = (c | 0x80) & 0xbf; c >>= 6;
     488        case 3: *--parser = (c | 0x80) & 0xbf; c >>= 6;
     489        case 2: *--parser = (c | 0x80) & 0xbf; c >>= 6;
     490    }
     491    *--parser = c | mark[bytes];
     492
     493    addstr(buf);
     494#else
     495    addch(' ');
     496#endif
     497}
     498
    456499/*
    457500 * Driver initialisation
Note: See TracChangeset for help on using the changeset viewer.