From: Bill Lash Date: Fri, 1 Feb 2019 05:34:31 +0000 (-0600) Subject: Add some support for UTF-8 X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=90f22790bc5beb740f18af9c3f654de17ce93498;p=liskon_frotz.git Add some support for UTF-8 This adds support for printing UTF-8 characters using ncursesw in place of ncurses. --- diff --git a/Makefile b/Makefile index ea7edab..b908f65 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,8 @@ DEFAULT_CONVERTER ?= SRC_SINC_MEDIUM_QUALITY COLOR ?= yes # If this matters, you can choose -lcurses or -lncurses -CURSES ?= -lncurses +# For UTF-8 support -lncursesw needs to be used +CURSES ?= -lncursesw # Uncomment this if you're compiling Unix Frotz on a machine that lacks # the strrchr() libc library call. If you don't know what this means, diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index 19c72fc..b529f2a 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -45,6 +45,8 @@ #include "ux_frotz.h" #include "ux_blorb.h" +#include + volatile sig_atomic_t terminal_resized = 0; static void sigwinch_handler(int); @@ -406,6 +408,8 @@ void os_init_screen (void) { /*trace(TRACE_CALLS);*/ + setlocale(LC_ALL, ""); + if (initscr() == NULL) { /* Set up curses */ os_fatal("Unable to initialize curses. Maybe your $TERM setting is bad."); exit(1); diff --git a/src/curses/ux_text.c b/src/curses/ux_text.c index 95228b3..694ca83 100644 --- a/src/curses/ux_text.c +++ b/src/curses/ux_text.c @@ -218,8 +218,20 @@ void os_display_char (zchar c) if (c3 != ' ') addch(c3); - } else - addch(c); + } else { + // Looking at the UTF-8 table at + // https://www.utf8-chartable.de/unicode-utf8-table.pl + // Shows that characters from 0xa0-0xbf are encoded as + // 0xc2 0xa0-0xbf, and characters from 0xc0-0xff are + // encoded as 0xc3 0x80-0xbf + if ( c < 0xc0) { + addch(0xc2); + addch(c); + } else { + addch(0xc3); + addch(c - 0x40); + } + } return; } if (c >= ZC_ASCII_MIN && c <= ZC_ASCII_MAX) {