This adds support for printing UTF-8 characters using ncursesw in
place of ncurses.
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,
#include "ux_frotz.h"
#include "ux_blorb.h"
+#include <locale.h>
+
volatile sig_atomic_t terminal_resized = 0;
static void sigwinch_handler(int);
{
/*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);
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) {