From b2d84d524d0fa23b4a0041c54d0efcc476a43c54 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 5 May 2006 14:03:40 +0000 Subject: [PATCH] * Factored more UTF32 to UTF8 conversions using _cucul_utf32_to_utf8(). --- caca/driver_ncurses.c | 35 +++-------------------------------- caca/driver_slang.c | 29 +++-------------------------- tools/Makefile.am | 1 + tools/makefont.c | 33 ++++++--------------------------- 4 files changed, 13 insertions(+), 85 deletions(-) diff --git a/caca/driver_ncurses.c b/caca/driver_ncurses.c index e49ba67..0e016f5 100644 --- a/caca/driver_ncurses.c +++ b/caca/driver_ncurses.c @@ -487,43 +487,14 @@ static void ncurses_check_terminal(void) static void ncurses_write_utf32(uint32_t ch) { #if defined(HAVE_NCURSESW_NCURSES_H) - static const uint8_t mark[7] = - { - 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC - }; - - char buf[10], *parser; + char buf[10]; int bytes; -#endif - if(ch < 0x80) - { - addch(ch); - return; - } - -#if defined(HAVE_NCURSESW_NCURSES_H) - if(ch < 0x10000) - { - addch(ch); /* FIXME: doesn't work either */ - return; - } - - bytes = (ch < 0x800) ? 2 : (ch < 0x10000) ? 3 : 4; + bytes = _cucul_utf32_to_utf8(buf, ch); buf[bytes] = '\0'; - parser = buf + bytes; - - switch(bytes) - { - case 4: *--parser = (ch | 0x80) & 0xbf; ch >>= 6; - case 3: *--parser = (ch | 0x80) & 0xbf; ch >>= 6; - case 2: *--parser = (ch | 0x80) & 0xbf; ch >>= 6; - } - *--parser = ch | mark[bytes]; - addstr(buf); #else - addch(' '); + addch(ch < 0x80 ? ch : '?'); #endif } diff --git a/caca/driver_slang.c b/caca/driver_slang.c index 81bd00e..5d95be5 100644 --- a/caca/driver_slang.c +++ b/caca/driver_slang.c @@ -392,37 +392,14 @@ static void slang_init_palette(void) static void slang_write_utf32(uint32_t ch) { #ifdef HAVE_SLSMG_UTF8_ENABLE - static const uint8_t mark[7] = - { - 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC - }; - - char buf[10], *parser; + char buf[10]; int bytes; -#endif - - if(ch < 0x80) - { - SLsmg_write_char(ch); - return; - } -#ifdef HAVE_SLSMG_UTF8_ENABLE - bytes = (ch < 0x800) ? 2 : (ch < 0x10000) ? 3 : 4; + bytes = _cucul_utf32_to_utf8(buf, ch); buf[bytes] = '\0'; - parser = buf + bytes; - - switch(bytes) - { - case 4: *--parser = (ch | 0x80) & 0xbf; ch >>= 6; - case 3: *--parser = (ch | 0x80) & 0xbf; ch >>= 6; - case 2: *--parser = (ch | 0x80) & 0xbf; ch >>= 6; - } - *--parser = ch | mark[bytes]; - SLsmg_write_string(buf); #else - SLsmg_write_char(' '); + SLsmg_write_char(ch < 0x80 ? ch : ' '); #endif } diff --git a/tools/Makefile.am b/tools/Makefile.am index 19dd749..c56603c 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -9,6 +9,7 @@ optipal_SOURCES = optipal.c makefont_SOURCES = makefont.c makefont_CFLAGS = `pkg-config --cflags pangoft2` makefont_LDFLAGS = `pkg-config --libs pangoft2` +makefont_LDADD = ../cucul/libcucul.la if USE_PANGO pango_programs = makefont diff --git a/tools/makefont.c b/tools/makefont.c index 5db4a59..cc441bb 100644 --- a/tools/makefont.c +++ b/tools/makefont.c @@ -27,6 +27,9 @@ # include #endif +#include "cucul.h" +#include "cucul_internals.h" + #include #include @@ -199,35 +202,11 @@ int main(int argc, char *argv[]) for(i = blocklist[b]; i < blocklist[b + 1]; i++) { unsigned int ch = i; - char buf[10], *parser; + char buf[10]; int x, y, bytes; - if(ch < 0x80) - { - bytes = 1; - buf[0] = ch; - buf[1] = '\0'; - } - else - { - static const unsigned char mark[7] = - { - 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC - }; - - /* FIXME: use libcucul instead of this shit */ - bytes = (ch < 0x800) ? 2 : (ch < 0x10000) ? 3 : 4; - buf[bytes] = '\0'; - parser = buf + bytes; - - switch(bytes) - { - case 4: *--parser = (ch | 0x80) & 0xbf; ch >>= 6; - case 3: *--parser = (ch | 0x80) & 0xbf; ch >>= 6; - case 2: *--parser = (ch | 0x80) & 0xbf; ch >>= 6; - } - *--parser = ch | mark[bytes]; - } + bytes = _cucul_utf32_to_utf8(buf, ch); + buf[bytes] = '\0'; /* Print glyph value in comment */ printf("/* U+%.04X: \"", i);