Changes to common code for non latin unicode
authorBill Lash <william.lash@gmail.com>
Mon, 20 May 2019 04:35:36 +0000 (23:35 -0500)
committerBill Lash <william.lash@gmail.com>
Mon, 20 May 2019 04:35:36 +0000 (23:35 -0500)
Note that this changes signatures for several os_ functions which
means nothing  outside of common will compile.

Also added changes for 2 of the 3 needed curses files that I feel
fairly confident in.  The ux_input.c is left out of this commit
because it is much more problematic.

src/common/buffer.c
src/common/files.c
src/common/frotz.h
src/common/input.c
src/common/redirect.c
src/common/screen.c
src/common/text.c
src/curses/ux_init.c
src/curses/ux_text.c

index 12508d8c5b0c66831e998eebc8fb93a8f199bf6c..eb31cf5d1a0c6f9431847e3ce4091c25e2ff5b78 100644 (file)
 #include <string.h>
 #include "frotz.h"
 
-extern void stream_char (zchar);
-extern void stream_word (const zchar *);
+extern void stream_char (zword);
+extern void stream_word (const zword *);
 extern void stream_new_line (void);
 
-static zchar buffer[TEXT_BUFFER_SIZE];
+static zword buffer[TEXT_BUFFER_SIZE];
 static int bufpos = 0;
 
-static zchar prev_c = 0;
+static zword prev_c = 0;
 
 /*
  * flush_buffer
@@ -72,7 +72,8 @@ void flush_buffer (void)
  * High level output function.
  *
  */
-void print_char (zchar c)
+
+void print_char (zword c)
 {
     static bool flag = FALSE;
     need_newline_at_exit = TRUE;
@@ -137,7 +138,7 @@ void new_line (void)
  */
 void init_buffer(void)
 {
-    memset(buffer, 0, sizeof (zchar) * TEXT_BUFFER_SIZE);
+    memset(buffer, 0, sizeof (zword) * TEXT_BUFFER_SIZE);
     bufpos = 0;
     prev_c = 0;
 }
index ff8cb4dd3d3a6afd8034b6171342b35fe0b282af..3a241927a726e8d019e93249ea6d87e7a1aa184c 100644 (file)
@@ -31,7 +31,7 @@
 
 extern void set_more_prompts (bool);
 
-extern bool is_terminator (zchar);
+extern bool is_terminator (zword);
 
 extern bool read_yes_or_no (const char *);
 
@@ -143,7 +143,7 @@ void script_new_line (void)
  *
  */
 
-void script_char (zchar c)
+void script_char (zword c)
 {
 
     if (c == ZC_INDENT && script_width != 0)
@@ -155,38 +155,38 @@ void script_char (zchar c)
        { script_char (' '); script_char (' '); return; }
 
 #ifdef __MSDOS__
+    if (c > 0xff)
+       c = '?';
     if (c >= ZC_LATIN1_MIN)
        c = latin1_to_ibm[c - ZC_LATIN1_MIN];
-#endif
 
-#ifdef USE_UTF8
-    if (c >= ZC_LATIN1_MIN)
-    {
-      if ( c < 0xc0) {
-       fputc (0xc2, sfp); 
-       fputc (c, sfp);
-#ifdef HANDLE_OE_DIPTHONG
-      } else if (c == 0xd6) {
-       fputc (0xc5, sfp);
-       fputc (0x92, sfp);
-      } else if (c == 0xf6) {
-       fputc (0xc5, sfp);
-       fputc (0x93, sfp);
-#endif /* HANDLE_OE_DIPTHONG */
-      } else {
-       fputc (0xc3, sfp);
-       fputc (c - 0x40, sfp);
-      }
+    fputc (c, sfp);
+    script_width++;
+
+#else
+
+    /* Encode as UTF-8 */
+
+    if (c > 0x7ff) {
+
+       fputc (0xe0 | ((c >> 12) & 0xf), sfp);
+       fputc (0x80 | ((c >> 6) & 0x3f), sfp);
+       fputc (0x80 | (c & 0x3f), sfp);
+
+    }
+    else if (c > 0x7f) {
+
+       fputc (0xc0 | ((c >> 6) & 0x1f), sfp);
+       fputc (0x80 | (c & 0x3f), sfp);
+
     }
     else
-    {
+
        fputc (c, sfp);
-    }
-#else
-    fputc (c, sfp);
-#endif
+
     script_width++;
 
+#endif
 }/* script_char */
 
 /*
@@ -196,7 +196,7 @@ void script_char (zchar c)
  *
  */
 
-void script_word (const zchar *s)
+void script_word (const zword *s)
 {
     int width;
     int i;
@@ -240,7 +240,7 @@ void script_word (const zchar *s)
  *
  */
 
-void script_write_input (const zchar *buf, zchar key)
+void script_write_input (const zword *buf, zword key)
 {
     int width;
     int i;
@@ -266,7 +266,7 @@ void script_write_input (const zchar *buf, zchar key)
  *
  */
 
-void script_erase_input (const zchar *buf)
+void script_erase_input (const zword *buf)
 {
     int width;
     int i;
@@ -382,7 +382,7 @@ static void record_code (int c, bool force_encoding)
  *
  */
 
-static void record_char (zchar c)
+static void record_char (zword c)
 {
 
     if (c != ZC_RETURN) {
@@ -404,7 +404,7 @@ static void record_char (zchar c)
  *
  */
 
-void record_write_key (zchar key)
+void record_write_key (zword key)
 {
 
     record_char (key);
@@ -421,9 +421,9 @@ void record_write_key (zchar key)
  *
  */
 
-void record_write_input (const zchar *buf, zchar key)
+void record_write_input (const zword *buf, zword key)
 {
-    zchar c;
+    zword c;
 
     while ((c = *buf++) != 0)
        record_char (c);
@@ -513,7 +513,7 @@ static int replay_code (void)
  *
  */
 
-static zchar replay_char (void)
+static zword replay_char (void)
 {
     int c;
 
@@ -550,9 +550,9 @@ static zchar replay_char (void)
  *
  */
 
-zchar replay_read_key (void)
+zword replay_read_key (void)
 {
-    zchar key;
+    zword key;
 
     key = replay_char ();
 
@@ -572,9 +572,9 @@ zchar replay_read_key (void)
  *
  */
 
-zchar replay_read_input (zchar *buf)
+zword replay_read_input (zword *buf)
 {
-    zchar c;
+    zword c;
 
     for (;;) {
 
index 395816e90585c53eb998e35d16606373b0b53ac5..7c78df6f57d347df46e212b06615112b3df8ea24 100644 (file)
@@ -759,12 +759,12 @@ void   init_sound (void);
 
 /*** Various global functions ***/
 
-zchar  translate_from_zscii (zbyte);
-zbyte  translate_to_zscii (zchar);
+zword  translate_from_zscii (zbyte);
+zbyte  translate_to_zscii (zword);
 
 void   flush_buffer (void);
 void   new_line (void);
-void   print_char (zchar);
+void   print_char (zword);
 void   print_num (zword);
 void   print_object (zword);
 void   print_string (const char *);
@@ -781,10 +781,10 @@ void      storew (zword, zword);
 
 void end_of_sound (void);
 
-int completion (const zchar *buffer, zchar *result);
+int completion (const zword *buffer, zword *result);
 
-bool is_terminator (zchar);
-void read_string (int max, zchar *buffer);
+bool is_terminator (zword);
+void read_string (int max, zword *buffer);
 bool read_yes_or_no (const char *);
 
 void screen_new_line (void);
@@ -796,9 +796,9 @@ Zwindow * curwinrec( void);
 /*** Interface functions ***/
 
 void   os_beep (int);
-int    os_char_width (zchar);
-void   os_display_char (zchar);
-void   os_display_string (const zchar *);
+int    os_char_width (zword);
+void   os_display_char (zword);
+void   os_display_string (const zword *);
 void   os_draw_picture (int, int, int);
 void   os_erase_area (int, int, int, int, int);
 void   os_fatal (const char *, ...);
@@ -814,8 +814,8 @@ void        os_prepare_sample (int);
 void   os_process_arguments (int, char *[]);
 int    os_random_seed (void);
 char   *os_read_file_name (const char *, int);
-zchar  os_read_key (int, int);
-zchar  os_read_line (int, zchar *, int, int, int);
+zword  os_read_key (int, int);
+zword  os_read_line (int, zword *, int, int, int);
 void   os_reset_screen (void);
 void   os_restart_game (int);
 void   os_scroll_area (int, int, int, int, int);
@@ -827,7 +827,7 @@ void        os_start_sample (int, int, int, zword);
 void   os_stop_sample ();
 int    os_storyfile_seek (FILE *, long, int);
 int    os_storyfile_tell (FILE *);
-int    os_string_width (const zchar *);
+int    os_string_width (const zword *);
 void   os_init_setup (void);
 void   os_warn (const char *, ...);
 void   os_quit (void);
index 52adfa111fbdac5442297a3e7bfbd409cce6e191..ad9bf55b86cd2f8ae07c1845bf771e696d9ec462 100644 (file)
 
 extern int save_undo (void);
 
-extern zchar stream_read_key (zword, zword, bool);
-extern zchar stream_read_input (int, zchar *, zword, zword, bool, bool);
+extern zword stream_read_key (zword, zword, bool);
+extern zword stream_read_input (int, zword *, zword, zword, bool, bool);
 
 extern void tokenise_line (zword, zword, zword, bool);
-
+zword unicode_tolower (zword);
 static bool truncate_question_mark(void);
 
 /*
@@ -36,7 +36,7 @@ static bool truncate_question_mark(void);
  *
  */
 
-bool is_terminator (zchar key)
+bool is_terminator (zword key)
 {
 
     if (key == ZC_TIME_OUT)
@@ -94,7 +94,7 @@ void z_make_menu (void)
 
 bool read_yes_or_no (const char *s)
 {
-    zchar key;
+    zword key;
 
     print_string (s);
     print_string ("? (y/n) >");
@@ -118,9 +118,9 @@ bool read_yes_or_no (const char *s)
  *
  */
 
-void read_string (int max, zchar *buffer)
+void read_string (int max, zword *buffer)
 {
-    zchar key;
+    zword key;
 
     buffer[0] = 0;
 
@@ -141,7 +141,7 @@ void read_string (int max, zchar *buffer)
 
 int read_number (void)
 {
-    zchar buffer[6];
+    zword buffer[6];
     int value = 0;
     int i;
 
@@ -167,9 +167,9 @@ int read_number (void)
 
 void z_read (void)
 {
-    zchar buffer[INPUT_BUFFER_SIZE];
+    zword buffer[INPUT_BUFFER_SIZE];
     zword addr;
-    zchar key;
+    zword key;
     zbyte max, size;
     zbyte c;
     int i;
@@ -235,10 +235,8 @@ void z_read (void)
     for (i = 0; buffer[i] != 0; i++) {
 
        if (key == ZC_RETURN) {
-           if (buffer[i] >= 'A' && buffer[i] <= 'Z')
-               buffer[i] += 'a' - 'A';
-           if (buffer[i] >= 0xc0 && buffer[i] <= 0xde && buffer[i] != 0xd7)
-               buffer[i] += 0x20;
+
+           buffer[i] = unicode_tolower (buffer[i]);
 
        }
 
@@ -278,7 +276,7 @@ void z_read (void)
 
 void z_read_char (void)
 {
-    zchar key;
+    zword key;
 
     /* Supply default arguments */
 
index 19ccc967f46d3f8e8e5ce264ef57e0b279de118e..7ade3b4db18e25d7965fcf4825e939a5515b78e5 100644 (file)
@@ -104,11 +104,12 @@ void memory_new_line (void)
  * Redirect a string of characters to the memory of the Z-machine.
  *
  */
-void memory_word (const zchar *s)
+
+void memory_word (const zword *s)
 {
     zword size;
     zword addr;
-    zchar c;
+    zword c;
 
     if (h_version == V6) {
 
index 0e1e1188afe62da9b25f43f40354d90d000fc020..16d71bb3da874a12c48232b50c76b50c395d879a 100644 (file)
@@ -295,7 +295,7 @@ void screen_new_line (void)
  *
  */
 
-void screen_char (zchar c)
+void screen_char (zword c)
 {
     int width;
 
@@ -326,7 +326,8 @@ void screen_char (zchar c)
  * enable_wrapping flag.
  *
  */
-void screen_word (const zchar *s)
+
+void screen_word (const zword *s)
 {
     int width;
 
@@ -339,7 +340,7 @@ void screen_word (const zchar *s)
 
        if (!enable_wrapping) {
 
-           zchar c;
+           zword c;
 
            while ((c = *s++) != 0)
 
@@ -380,7 +381,8 @@ void screen_word (const zchar *s)
  * Display an input line on the screen. This is required during playback.
  *
  */
-void screen_write_input (const zchar *buf, zchar key)
+
+void screen_write_input (const zword *buf, zword key)
 {
     int width;
 
@@ -403,7 +405,8 @@ void screen_write_input (const zchar *buf, zchar key)
  * playback.
  *
  */
-void screen_erase_input (const zchar *buf)
+
+void screen_erase_input (const zword *buf)
 {
     if (buf[0] != 0) {
 
@@ -432,9 +435,10 @@ void screen_erase_input (const zchar *buf)
  * Read an input line from the keyboard and return the terminating key.
  *
  */
-zchar console_read_input (int max, zchar *buf, zword timeout, bool continued)
+
+zword console_read_input (int max, zword *buf, zword timeout, bool continued)
 {
-    zchar key;
+    zword key;
     int i;
 
     /* Make sure there is some space for input */
@@ -476,9 +480,10 @@ zchar console_read_input (int max, zchar *buf, zword timeout, bool continued)
  * Read a single keystroke and return it.
  *
  */
-zchar console_read_key (zword timeout)
+
+zword console_read_key (zword timeout)
 {
-    zchar key;
+    zword key;
     int i;
 
     key = os_read_key (timeout, cursor);
index cdffece0aefbbad982d67f4a987fac6597b09cbc..9574b25d4989e5b2aaba3b054bb719501ea1b393 100644 (file)
@@ -26,7 +26,7 @@ enum string_type {
 
 extern zword object_name (zword);
 
-static zchar decoded[10];
+static zword decoded[10];
 static zword encoded[3];
 
 /*
@@ -34,27 +34,29 @@ static zword encoded[3];
  * 0xab and 0xbb were in each other's proper positions.
  *   Sat Apr 21, 2001
  */
-static zchar zscii_to_latin1[] = {
-    0xe4, 0xf6, 0xfc, 0xc4, 0xd6, 0xdc, 0xdf, 0xbb,
-    0xab, 0xeb, 0xef, 0xff, 0xcb, 0xcf, 0xe1, 0xe9,
-    0xed, 0xf3, 0xfa, 0xfd, 0xc1, 0xc9, 0xcd, 0xd3,
-    0xda, 0xdd, 0xe0, 0xe8, 0xec, 0xf2, 0xf9, 0xc0,
-    0xc8, 0xcc, 0xd2, 0xd9, 0xe2, 0xea, 0xee, 0xf4,
-    0xfb, 0xc2, 0xca, 0xce, 0xd4, 0xdb, 0xe5, 0xc5,
-    0xf8, 0xd8, 0xe3, 0xf1, 0xf5, 0xc3, 0xd1, 0xd5,
-    0xe6, 0xc6, 0xe7, 0xc7, 0xfe, 0xf0, 0xde, 0xd0,
-    0xa3, 0xf6, 0xd6, 0xa1, 0xbf
+static zword zscii_to_latin1[] = {
+    0x0e4, 0x0f6, 0x0fc, 0x0c4, 0x0d6, 0x0dc, 0x0df, 0x0bb,
+    0x0ab, 0x0eb, 0x0ef, 0x0ff, 0x0cb, 0x0cf, 0x0e1, 0x0e9,
+    0x0ed, 0x0f3, 0x0fa, 0x0fd, 0x0c1, 0x0c9, 0x0cd, 0x0d3,
+    0x0da, 0x0dd, 0x0e0, 0x0e8, 0x0ec, 0x0f2, 0x0f9, 0x0c0,
+    0x0c8, 0x0cc, 0x0d2, 0x0d9, 0x0e2, 0x0ea, 0x0ee, 0x0f4,
+    0x0fb, 0x0c2, 0x0ca, 0x0ce, 0x0d4, 0x0db, 0x0e5, 0x0c5,
+    0x0f8, 0x0d8, 0x0e3, 0x0f1, 0x0f5, 0x0c3, 0x0d1, 0x0d5,
+    0x0e6, 0x0c6, 0x0e7, 0x0c7, 0x0fe, 0x0f0, 0x0de, 0x0d0,
+    0x0a3, 0x153, 0x152, 0x0a1, 0x0bf
 };
 
 
 /*
  * translate_from_zscii
  *
- * Map a ZSCII character onto the ISO Latin-1 alphabet.
+ * Map a ZSCII character into Unicode.
  *
  */
-zchar translate_from_zscii (zbyte c)
+
+zword translate_from_zscii (zbyte c)
 {
+
     if (c == 0xfc)
        return ZC_MENU_CLICK;
     if (c == 0xfd)
@@ -77,7 +79,10 @@ zchar translate_from_zscii (zbyte c)
 
                LOW_WORD (addr, unicode)
 
-               return (unicode < 0x100) ? (zchar) unicode : '?';
+               if (unicode < 0x20)
+                       return '?';
+
+               return unicode;
 
            } else return '?';
 
@@ -85,38 +90,26 @@ zchar translate_from_zscii (zbyte c)
 
            if (c <= 0xdf) {
 
-#ifndef HANDLE_OE_DIPTHONG
-               if (c == 0xdc || c == 0xdd)     /* Oe and oe ligatures */
-                   return '?';                 /* are not ISO-Latin 1 */
-#endif /* HANDLE_OE_DIPTHONG */
-
                return zscii_to_latin1[c - 0x9b];
 
            } else return '?';
     }
 
-    return c;
+    return (zword) c;
 
 }/* translate_from_zscii */
 
-
 /*
- * translate_to_zscii
+ * unicode_to_zscii
  *
- * Map an ISO Latin-1 character onto the ZSCII alphabet.
+ * Convert a Unicode character to ZSCII, returning 0 on failure.
  *
  */
-zbyte translate_to_zscii (zchar c)
+
+zbyte unicode_to_zscii (zword c)
 {
     int i;
 
-    if (c == ZC_SINGLE_CLICK)
-       return 0xfe;
-    if (c == ZC_DOUBLE_CLICK)
-       return 0xfd;
-    if (c == ZC_MENU_CLICK)
-       return 0xfc;
-
     if (c >= ZC_LATIN1_MIN) {
 
        if (hx_unicode_table != 0) {    /* game has its own Unicode table */
@@ -138,7 +131,7 @@ zbyte translate_to_zscii (zchar c)
 
            }
 
-           return '?';
+           return 0;
 
        } else {                        /* game uses standard set */
 
@@ -146,19 +139,41 @@ zbyte translate_to_zscii (zchar c)
                if (c == zscii_to_latin1[i - 0x9b])
                    return (zbyte) i;
 
-           return '?';
+           return 0;
 
        }
     }
 
-    if (c == 0)                /* Safety thing from David Kinder */
-       c = '?';        /* regarding his Unicode patches */
-                       /* Sept 15, 2002 */
+    return (zbyte) c;
 
-    return c;
+}/* unicode_to_zscii */
 
-}/* translate_to_zscii */
+/*
+ * translate_to_zscii
+ *
+ * Map a Unicode character onto the ZSCII alphabet.
+ *
+ */
+
+zbyte translate_to_zscii (zword c)
+{
+
+    if (c == ZC_SINGLE_CLICK)
+       return 0xfe;
+    if (c == ZC_DOUBLE_CLICK)
+       return 0xfd;
+    if (c == ZC_MENU_CLICK)
+       return 0xfc;
+    if (c == 0)
+       return 0;
 
+    c = unicode_to_zscii (c);
+    if (c == 0)
+       c = '?';
+
+    return (zbyte) c;
+
+}/* translate_to_zscii */
 
 /*
  * alphabet
@@ -166,7 +181,8 @@ zbyte translate_to_zscii (zchar c)
  * Return a character from one of the three character sets.
  *
  */
-static zchar alphabet (int set, int index)
+
+static zword alphabet (int set, int index)
 {
     if (h_alphabet != 0) {     /* game uses its own alphabet */
 
@@ -233,13 +249,13 @@ static void load_string (zword addr, zword length)
  */
 static void encode_text (int padding)
 {
-    static zchar again[] = { 'a', 'g', 'a', 'i', 'n', 0 };
-    static zchar examine[] = { 'e', 'x', 'a', 'm', 'i', 'n', 'e', 0 };
-    static zchar wait[] = { 'w', 'a', 'i', 't', 0 };
+    static zword again[] = { 'a', 'g', 'a', 'i', 'n', 0, 0, 0, 0 };
+    static zword examine[] = { 'e', 'x', 'a', 'm', 'i', 'n', 'e', 0, 0 };
+    static zword wait[] = { 'w', 'a', 'i', 't', 0, 0, 0, 0, 0 };
 
     zbyte zchars[12];
-    const zchar *ptr = decoded;
-    zchar c;
+    const zword *ptr = decoded;
+    zword c;
     int resolution = (h_version <= V3) ? 2 : 3;
     int i = 0;
 
@@ -321,7 +337,10 @@ void z_check_unicode (void)
        store (3);
     else if (c == 0xa0)
        store (1);
-    else if (c >= 0xa1 && c <= 0xff)
+    else if (c >= 0xa1) 
+       /* being optimistic, we can print and input 
+        * all unicode characters 
+        */
        store (3);
     else
        store (0);
@@ -378,9 +397,9 @@ void z_encode_text (void)
 #define outchar(c)     if (st==VOCABULARY) *ptr++=c; else print_char(c)
 static void decode_text (enum string_type st, zword addr)
 {
-    zchar *ptr;
+    zword *ptr;
     long byte_addr;
-    zchar c2;
+    zword c2;
     zword code;
     zbyte c, prev_c = 0;
     int shift_state = 0;
@@ -749,10 +768,13 @@ void print_string (const char *s)
  */
 void z_print_unicode (void)
 {
-    print_char ((zargs[0] <= 0xff) ? zargs[0] : '?');
 
-}/* z_print_unicode */
+    if (zargs[0] < 0x20)
+       print_char ('?');
+    else
+       print_char (zargs[0]);
 
+}/* z_print_unicode */
 
 /*
  * lookup_text
@@ -1038,12 +1060,13 @@ void z_tokenise (void)
  * to the last word that results in the only possible completion.
  *
  */
-int completion (const zchar *buffer, zchar *result)
+
+int completion (const zword *buffer, zword *result)
 {
     zword minaddr;
     zword maxaddr;
-    zchar *ptr;
-    zchar c;
+    zword *ptr;
+    zword c;
     int len;
     int i;
 
@@ -1095,3 +1118,74 @@ int completion (const zchar *buffer, zchar *result)
     return (minaddr == maxaddr) ? 0 : 1;
 
 }/* completion */
+
+/*
+ * unicode_tolower
+ *
+ * Convert a Unicode character to lowercase.
+ * Taken from Zip2000 by Kevin Bracey.
+ *
+ */
+
+zword unicode_tolower (zword c)
+{
+    const static unsigned char tolower_basic_latin[0x100] = {
+       0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
+       0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
+       0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
+       0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
+       0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
+       0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x5B,0x5C,0x5D,0x5E,0x5F,
+       0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
+       0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
+       0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
+       0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,
+       0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,
+       0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
+       0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,
+       0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xD7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xDF,
+       0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,
+       0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF
+    };
+    const static unsigned char tolower_latin_extended_a[0x80] = {
+       0x01,0x01,0x03,0x03,0x05,0x05,0x07,0x07,0x09,0x09,0x0B,0x0B,0x0D,0x0D,0x0F,0x0F,
+       0x11,0x11,0x13,0x13,0x15,0x15,0x17,0x17,0x19,0x19,0x1B,0x1B,0x1D,0x1D,0x1F,0x1F,
+       0x21,0x21,0x23,0x23,0x25,0x25,0x27,0x27,0x29,0x29,0x2B,0x2B,0x2D,0x2D,0x2F,0x2F,
+       0x00,0x31,0x33,0x33,0x35,0x35,0x37,0x37,0x38,0x3A,0x3A,0x3C,0x3C,0x3E,0x3E,0x40,
+       0x40,0x42,0x42,0x44,0x44,0x46,0x46,0x48,0x48,0x49,0x4B,0x4B,0x4D,0x4D,0x4F,0x4F,
+       0x51,0x51,0x53,0x53,0x55,0x55,0x57,0x57,0x59,0x59,0x5B,0x5B,0x5D,0x5D,0x5F,0x5F,
+       0x61,0x61,0x63,0x63,0x65,0x65,0x67,0x67,0x69,0x69,0x6B,0x6B,0x6D,0x6D,0x6F,0x6F,
+       0x71,0x71,0x73,0x73,0x75,0x75,0x77,0x77,0x00,0x7A,0x7A,0x7C,0x7C,0x7E,0x7E,0x7F
+    };
+    const static unsigned char tolower_greek[0x50] = {
+       0x80,0x81,0x82,0x83,0x84,0x85,0xAC,0x87,0xAD,0xAE,0xAF,0x8B,0xCC,0x8D,0xCD,0xCE,
+       0x90,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
+       0xC0,0xC1,0xA2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xAC,0xAD,0xAE,0xAF,
+       0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
+       0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF
+    };
+    const static unsigned char tolower_cyrillic[0x60] = {
+       0x00,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
+       0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
+       0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
+       0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
+       0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
+       0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F
+    };
+
+    if (c < 0x0100)
+       c = tolower_basic_latin[c];
+    else if (c == 0x0130)
+       c = 0x0069;     /* Capital I with dot -> lower case i */
+    else if (c == 0x0178)
+       c = 0x00FF;     /* Capital Y diaeresis -> lower case y diaeresis */
+    else if (c < 0x0180)
+       c = tolower_latin_extended_a[c-0x100] + 0x100;
+    else if (c >= 0x380 && c < 0x3D0)
+       c = tolower_greek[c-0x380] + 0x300;
+    else if (c >= 0x400 && c < 0x460)
+       c = tolower_cyrillic[c-0x400] + 0x400;
+
+    return c;
+}
+
index 6a749b81350705ae2c8228a1d9f08f104197938f..3b3eff56617c2d95c525a005e388d62460f38642 100644 (file)
@@ -111,13 +111,13 @@ void os_warn (const char *s, ...)
 {
     if (u_setup.curses_active) {
        /* Solaris 2.6's cc complains if the below cast is missing */
-       os_display_string((zchar *)"\n\n");
+       os_display_string((zword *)"\n\n");
        os_beep(BEEP_HIGH);
        os_set_text_style(BOLDFACE_STYLE);
-       os_display_string((zchar *)"Warning: ");
+       os_display_string((zword *)"Warning: ");
        os_set_text_style(0);
-       os_display_string((zchar *)s);
-       os_display_string((zchar *)"\n");
+       os_display_string((zword *)s);
+       os_display_string((zword *)"\n");
        new_line();
     }
 }/* os_warn */
@@ -132,16 +132,16 @@ void os_fatal (const char *s, ...)
 {
     if (u_setup.curses_active) {
        /* Solaris 2.6's cc complains if the below cast is missing */
-       os_display_string((zchar *)"\n\n");
+       os_display_string((zword *)"\n\n");
        os_beep(BEEP_HIGH);
        os_set_text_style(BOLDFACE_STYLE);
-       os_display_string((zchar *)"Fatal error: ");
+       os_display_string((zword *)"Fatal error: ");
        os_set_text_style(0);
-       os_display_string((zchar *)s);
-       os_display_string((zchar *)"\n");
+       os_display_string((zword *)s);
+       os_display_string((zword *)"\n");
        new_line();
        if (f_setup.ignore_errors) {
-           os_display_string((zchar *)"Continuing anyway...");
+           os_display_string((zword *)"Continuing anyway...");
            new_line();
            scrollok(stdscr, TRUE);
            scroll(stdscr);
@@ -542,7 +542,7 @@ void os_reset_screen (void)
 {
     os_stop_sample(0);
     os_set_text_style(0);
-    os_display_string((zchar *)"[Hit any key to exit.]\n");
+    os_display_string((zword *)"[Hit any key to exit.]\n");
     os_read_key(0, FALSE);
     os_quit();
 }/* os_reset_screen */
index 20a678c80f2662ab0cb004410a7af13cf7514fc4..78663009ae32cab0f921f2696ac6bee1b94bf6f7 100644 (file)
@@ -201,7 +201,7 @@ void os_set_font (int UNUSED(new_font))
  * bottom right corner.
  *
  */
-void os_display_char (zchar c)
+void os_display_char (zword c)
 {
     if (c >= ZC_LATIN1_MIN) {
         if (u_setup.plain_ascii) {
@@ -223,26 +223,14 @@ void os_display_char (zchar c)
            addch(c);
 #else
        } 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);
-#ifdef HANDLE_OE_DIPTHONG
-         } else if (c == 0xd6) {
-           addch(0xc5);
-           addch(0x92);
-         } else if (c == 0xf6) {
-           addch(0xc5);
-           addch(0x93);
-#endif /* HANDLE_OE_DIPTHONG */
-         } else {
-           addch(0xc3);
-           addch(c - 0x40);
-         }
+          if(c > 0x7ff) {
+               addch(0xe0 | ((c >> 12) & 0xf));
+                addch(0x80 | ((c >> 6) & 0x3f));
+                addch(0x80 | (c & 0x3f));
+            } else {
+                addch(0xc0 | ((c >> 6) & 0x1f));
+                addch(0x80 | (c & 0x3f));
+            }
        }
 #endif /* USE_UTF8 */
        return;
@@ -268,11 +256,11 @@ void os_display_char (zchar c)
  * Pass a string of characters to os_display_char.
  *
  */
-void os_display_string (const zchar *s)
+void os_display_string (const zword *s)
 {
-    zchar c;
+    zword c;
 
-    while ((c = (unsigned char) *s++) != 0) {
+    while ((c =  *s++) != 0) {
 
         if (c == ZC_NEW_FONT || c == ZC_NEW_STYLE) {
 
@@ -296,7 +284,7 @@ void os_display_string (const zchar *s)
  * Return the width of the character in screen units.
  *
  */
-int os_char_width (zchar c)
+int os_char_width (zword c)
 {
     if (c >= ZC_LATIN1_MIN && u_setup.plain_ascii) {
 
@@ -329,10 +317,10 @@ int os_char_width (zchar c)
  *    NEW_FONT  - next character is a new font
  *
  */
-int os_string_width (const zchar *s)
+int os_string_width (const zword *s)
 {
     int width = 0;
-    zchar c;
+    zword c;
 
     while ((c = *s++) != 0) {