zchar alternative
authorborg323 <4010067-borg323@users.noreply.gitlab.com>
Mon, 20 May 2019 14:16:19 +0000 (17:16 +0300)
committerDavid Griffith <dave@661.org>
Mon, 27 May 2019 02:32:11 +0000 (19:32 -0700)
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_input.c
src/curses/ux_text.c

index eb31cf5d1a0c6f9431847e3ce4091c25e2ff5b78..12508d8c5b0c66831e998eebc8fb93a8f199bf6c 100644 (file)
 #include <string.h>
 #include "frotz.h"
 
-extern void stream_char (zword);
-extern void stream_word (const zword *);
+extern void stream_char (zchar);
+extern void stream_word (const zchar *);
 extern void stream_new_line (void);
 
-static zword buffer[TEXT_BUFFER_SIZE];
+static zchar buffer[TEXT_BUFFER_SIZE];
 static int bufpos = 0;
 
-static zword prev_c = 0;
+static zchar prev_c = 0;
 
 /*
  * flush_buffer
@@ -72,8 +72,7 @@ void flush_buffer (void)
  * High level output function.
  *
  */
-
-void print_char (zword c)
+void print_char (zchar c)
 {
     static bool flag = FALSE;
     need_newline_at_exit = TRUE;
@@ -138,7 +137,7 @@ void new_line (void)
  */
 void init_buffer(void)
 {
-    memset(buffer, 0, sizeof (zword) * TEXT_BUFFER_SIZE);
+    memset(buffer, 0, sizeof (zchar) * TEXT_BUFFER_SIZE);
     bufpos = 0;
     prev_c = 0;
 }
index 3a241927a726e8d019e93249ea6d87e7a1aa184c..14fe4d608acf7037cde6ce3f9a4d50d077747c67 100644 (file)
@@ -31,7 +31,7 @@
 
 extern void set_more_prompts (bool);
 
-extern bool is_terminator (zword);
+extern bool is_terminator (zchar);
 
 extern bool read_yes_or_no (const char *);
 
@@ -143,7 +143,7 @@ void script_new_line (void)
  *
  */
 
-void script_char (zword c)
+void script_char (zchar c)
 {
 
     if (c == ZC_INDENT && script_width != 0)
@@ -196,7 +196,7 @@ void script_char (zword c)
  *
  */
 
-void script_word (const zword *s)
+void script_word (const zchar *s)
 {
     int width;
     int i;
@@ -240,7 +240,7 @@ void script_word (const zword *s)
  *
  */
 
-void script_write_input (const zword *buf, zword key)
+void script_write_input (const zchar *buf, zchar key)
 {
     int width;
     int i;
@@ -266,7 +266,7 @@ void script_write_input (const zword *buf, zword key)
  *
  */
 
-void script_erase_input (const zword *buf)
+void script_erase_input (const zchar *buf)
 {
     int width;
     int i;
@@ -382,7 +382,7 @@ static void record_code (int c, bool force_encoding)
  *
  */
 
-static void record_char (zword c)
+static void record_char (zchar c)
 {
 
     if (c != ZC_RETURN) {
@@ -404,7 +404,7 @@ static void record_char (zword c)
  *
  */
 
-void record_write_key (zword key)
+void record_write_key (zchar key)
 {
 
     record_char (key);
@@ -421,9 +421,9 @@ void record_write_key (zword key)
  *
  */
 
-void record_write_input (const zword *buf, zword key)
+void record_write_input (const zchar *buf, zchar key)
 {
-    zword c;
+    zchar c;
 
     while ((c = *buf++) != 0)
        record_char (c);
@@ -513,7 +513,7 @@ static int replay_code (void)
  *
  */
 
-static zword replay_char (void)
+static zchar replay_char (void)
 {
     int c;
 
@@ -550,9 +550,9 @@ static zword replay_char (void)
  *
  */
 
-zword replay_read_key (void)
+zchar replay_read_key (void)
 {
-    zword key;
+    zchar key;
 
     key = replay_char ();
 
@@ -572,9 +572,9 @@ zword replay_read_key (void)
  *
  */
 
-zword replay_read_input (zword *buf)
+zchar replay_read_input (zchar *buf)
 {
-    zword c;
+    zchar c;
 
     for (;;) {
 
index 8bc77a505d662b21648c69a537ce1da1a335ba6f..72331f6a2150dd0709010e921fe60e5d37cb1e78 100644 (file)
@@ -65,15 +65,12 @@ typedef unsigned short zword;
  * Unix side, please let me know and please test it to make sure it
  * doesn't mess with command history.
  */
-/*
+
 #ifdef MSDOS_16BIT
 typedef unsigned char zchar;
 #else
 typedef unsigned short zchar;
 #endif
-*/
-
-typedef unsigned char zchar;
 
 enum story {
     ZORK1,
@@ -762,12 +759,12 @@ void   init_sound (void);
 
 /*** Various global functions ***/
 
-zword  translate_from_zscii (zbyte);
-zbyte  translate_to_zscii (zword);
+zchar  translate_from_zscii (zbyte);
+zbyte  translate_to_zscii (zchar);
 
 void   flush_buffer (void);
 void   new_line (void);
-void   print_char (zword);
+void   print_char (zchar);
 void   print_num (zword);
 void   print_object (zword);
 void   print_string (const char *);
@@ -784,10 +781,10 @@ void      storew (zword, zword);
 
 void end_of_sound (void);
 
-int completion (const zword *buffer, zword *result);
+int completion (const zchar *buffer, zchar *result);
 
-bool is_terminator (zword);
-void read_string (int max, zword *buffer);
+bool is_terminator (zchar);
+void read_string (int max, zchar *buffer);
 bool read_yes_or_no (const char *);
 
 void screen_new_line (void);
@@ -799,9 +796,9 @@ Zwindow * curwinrec( void);
 /*** Interface functions ***/
 
 void   os_beep (int);
-int    os_char_width (zword);
-void   os_display_char (zword);
-void   os_display_string (const zword *);
+int    os_char_width (zchar);
+void   os_display_char (zchar);
+void   os_display_string (const zchar *);
 void   os_draw_picture (int, int, int);
 void   os_erase_area (int, int, int, int, int);
 void   os_fatal (const char *, ...);
@@ -817,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);
-zword  os_read_key (int, int);
-zword  os_read_line (int, zword *, int, int, int);
+zchar  os_read_key (int, int);
+zchar  os_read_line (int, zchar *, int, int, int);
 void   os_reset_screen (void);
 void   os_restart_game (int);
 void   os_scroll_area (int, int, int, int, int);
@@ -830,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 zword *);
+int    os_string_width (const zchar *);
 void   os_init_setup (void);
 void   os_warn (const char *, ...);
 void   os_quit (void);
index ad9bf55b86cd2f8ae07c1845bf771e696d9ec462..fe4a259a38625ab3ddbacd0f71dc010a6d855c6c 100644 (file)
@@ -22,8 +22,8 @@
 
 extern int save_undo (void);
 
-extern zword stream_read_key (zword, zword, bool);
-extern zword stream_read_input (int, zword *, zword, zword, bool, bool);
+extern zchar stream_read_key (zword, zword, bool);
+extern zchar stream_read_input (int, zchar *, zword, zword, bool, bool);
 
 extern void tokenise_line (zword, zword, zword, bool);
 zword unicode_tolower (zword);
@@ -36,7 +36,7 @@ static bool truncate_question_mark(void);
  *
  */
 
-bool is_terminator (zword key)
+bool is_terminator (zchar key)
 {
 
     if (key == ZC_TIME_OUT)
@@ -94,7 +94,7 @@ void z_make_menu (void)
 
 bool read_yes_or_no (const char *s)
 {
-    zword key;
+    zchar 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, zword *buffer)
+void read_string (int max, zchar *buffer)
 {
-    zword key;
+    zchar key;
 
     buffer[0] = 0;
 
@@ -141,7 +141,7 @@ void read_string (int max, zword *buffer)
 
 int read_number (void)
 {
-    zword buffer[6];
+    zchar buffer[6];
     int value = 0;
     int i;
 
@@ -167,9 +167,9 @@ int read_number (void)
 
 void z_read (void)
 {
-    zword buffer[INPUT_BUFFER_SIZE];
+    zchar buffer[INPUT_BUFFER_SIZE];
     zword addr;
-    zword key;
+    zchar key;
     zbyte max, size;
     zbyte c;
     int i;
@@ -276,7 +276,7 @@ void z_read (void)
 
 void z_read_char (void)
 {
-    zword key;
+    zchar key;
 
     /* Supply default arguments */
 
index 7ade3b4db18e25d7965fcf4825e939a5515b78e5..19ccc967f46d3f8e8e5ce264ef57e0b279de118e 100644 (file)
@@ -104,12 +104,11 @@ void memory_new_line (void)
  * Redirect a string of characters to the memory of the Z-machine.
  *
  */
-
-void memory_word (const zword *s)
+void memory_word (const zchar *s)
 {
     zword size;
     zword addr;
-    zword c;
+    zchar c;
 
     if (h_version == V6) {
 
index 16d71bb3da874a12c48232b50c76b50c395d879a..0e1e1188afe62da9b25f43f40354d90d000fc020 100644 (file)
@@ -295,7 +295,7 @@ void screen_new_line (void)
  *
  */
 
-void screen_char (zword c)
+void screen_char (zchar c)
 {
     int width;
 
@@ -326,8 +326,7 @@ void screen_char (zword c)
  * enable_wrapping flag.
  *
  */
-
-void screen_word (const zword *s)
+void screen_word (const zchar *s)
 {
     int width;
 
@@ -340,7 +339,7 @@ void screen_word (const zword *s)
 
        if (!enable_wrapping) {
 
-           zword c;
+           zchar c;
 
            while ((c = *s++) != 0)
 
@@ -381,8 +380,7 @@ void screen_word (const zword *s)
  * Display an input line on the screen. This is required during playback.
  *
  */
-
-void screen_write_input (const zword *buf, zword key)
+void screen_write_input (const zchar *buf, zchar key)
 {
     int width;
 
@@ -405,8 +403,7 @@ void screen_write_input (const zword *buf, zword key)
  * playback.
  *
  */
-
-void screen_erase_input (const zword *buf)
+void screen_erase_input (const zchar *buf)
 {
     if (buf[0] != 0) {
 
@@ -435,10 +432,9 @@ void screen_erase_input (const zword *buf)
  * Read an input line from the keyboard and return the terminating key.
  *
  */
-
-zword console_read_input (int max, zword *buf, zword timeout, bool continued)
+zchar console_read_input (int max, zchar *buf, zword timeout, bool continued)
 {
-    zword key;
+    zchar key;
     int i;
 
     /* Make sure there is some space for input */
@@ -480,10 +476,9 @@ zword console_read_input (int max, zword *buf, zword timeout, bool continued)
  * Read a single keystroke and return it.
  *
  */
-
-zword console_read_key (zword timeout)
+zchar console_read_key (zword timeout)
 {
-    zword key;
+    zchar key;
     int i;
 
     key = os_read_key (timeout, cursor);
index 9574b25d4989e5b2aaba3b054bb719501ea1b393..0e7edb38ed6e3be30eb223f58e3aa51eec907893 100644 (file)
@@ -26,7 +26,7 @@ enum string_type {
 
 extern zword object_name (zword);
 
-static zword decoded[10];
+static zchar decoded[10];
 static zword encoded[3];
 
 /*
@@ -53,8 +53,7 @@ static zword zscii_to_latin1[] = {
  * Map a ZSCII character into Unicode.
  *
  */
-
-zword translate_from_zscii (zbyte c)
+zchar translate_from_zscii (zbyte c)
 {
 
     if (c == 0xfc)
@@ -95,7 +94,7 @@ zword translate_from_zscii (zbyte c)
            } else return '?';
     }
 
-    return (zword) c;
+    return c;
 
 }/* translate_from_zscii */
 
@@ -105,8 +104,7 @@ zword translate_from_zscii (zbyte c)
  * Convert a Unicode character to ZSCII, returning 0 on failure.
  *
  */
-
-zbyte unicode_to_zscii (zword c)
+zbyte unicode_to_zscii (zchar c)
 {
     int i;
 
@@ -155,7 +153,7 @@ zbyte unicode_to_zscii (zword c)
  *
  */
 
-zbyte translate_to_zscii (zword c)
+zbyte translate_to_zscii (zchar c)
 {
 
     if (c == ZC_SINGLE_CLICK)
@@ -181,8 +179,7 @@ zbyte translate_to_zscii (zword c)
  * Return a character from one of the three character sets.
  *
  */
-
-static zword alphabet (int set, int index)
+static zchar alphabet (int set, int index)
 {
     if (h_alphabet != 0) {     /* game uses its own alphabet */
 
@@ -249,13 +246,13 @@ static void load_string (zword addr, zword length)
  */
 static void encode_text (int padding)
 {
-    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 };
+    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 };
 
     zbyte zchars[12];
-    const zword *ptr = decoded;
-    zword c;
+    const zchar *ptr = decoded;
+    zchar c;
     int resolution = (h_version <= V3) ? 2 : 3;
     int i = 0;
 
@@ -337,9 +334,9 @@ void z_check_unicode (void)
        store (3);
     else if (c == 0xa0)
        store (1);
-    else if (c >= 0xa1) 
-       /* being optimistic, we can print and input 
-        * all unicode characters 
+    else if (c >= 0xa1)
+       /* being optimistic, we can print and input
+        * all unicode characters
         */
        store (3);
     else
@@ -397,9 +394,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)
 {
-    zword *ptr;
+    zchar *ptr;
     long byte_addr;
-    zword c2;
+    zchar c2;
     zword code;
     zbyte c, prev_c = 0;
     int shift_state = 0;
@@ -1060,13 +1057,12 @@ void z_tokenise (void)
  * to the last word that results in the only possible completion.
  *
  */
-
-int completion (const zword *buffer, zword *result)
+int completion (const zchar *buffer, zchar *result)
 {
     zword minaddr;
     zword maxaddr;
-    zword *ptr;
-    zword c;
+    zchar *ptr;
+    zchar c;
     int len;
     int i;
 
index b43a7a78c68766de3996a05d4cd0e01cbefb0801..02908ffacc80903faf5c172bfef02ef819e7cd0e 100644 (file)
@@ -41,8 +41,8 @@
 
 #include "ux_frotz.h"
 
-static int start_of_prev_word(int, const zword*);
-static int end_of_next_word(int, const zword*, int);
+static int start_of_prev_word(int, const zchar*);
+static int end_of_next_word(int, const zchar*, int);
 
 static struct timeval global_timeout;
 
@@ -62,9 +62,9 @@ static zword **history_next = history_buffer; /* Next available slot. */
 static zword **history_view = history_buffer; /* What the user is looking at. */
 #define history_end (history_buffer + MAX_HISTORY - 1)
 
-extern bool is_terminator (zword);
-extern void read_string (int, zword *);
-extern int completion (const zword *, zword *);
+extern bool is_terminator (zchar);
+extern void read_string (int, zchar *);
+extern int completion (const zchar *, zchar *);
 
 #ifndef wint_t
 typedef unsigned int wint_t;
@@ -385,12 +385,12 @@ int zwordstrncmp(zword *s1, zword *s2, size_t n)
  * Add the given string to the next available history buffer slot.
  *
  */
-static void unix_add_to_history(zword *str)
+static void unix_add_to_history(zchar *str)
 {
 
     if (*history_next != NULL)
        free( *history_next);
-    *history_next = (zword *)malloc(zwordstrlen(str) + 1);
+    *history_next = (zchar *)malloc(zwordstrlen(str) + 1);
     zwordstrncpy( *history_next, str, zwordstrlen(str) + 1);
     RING_INC( history_next, history_buffer, history_end);
     history_view = history_next; /* Reset user frame after each line */
@@ -406,9 +406,9 @@ static void unix_add_to_history(zword *str)
  * Only lines of at most maxlen characters will be considered.  In addition
  * the first searchlen characters of the history entry must match those of str.
  */
-static int unix_history_back(zword *str, int searchlen, int maxlen)
+static int unix_history_back(zchar *str, int searchlen, int maxlen)
 {
-    zword **prev = history_view;
+    zchar **prev = history_view;
 
     do {
        RING_DEC( history_view, history_buffer, history_end);
@@ -431,7 +431,7 @@ static int unix_history_back(zword *str, int searchlen, int maxlen)
  *
  * Opposite of unix_history_back, and works in the same way.
  */
-static int unix_history_forward(zword *str, int searchlen, int maxlen)
+static int unix_history_forward(zchar *str, int searchlen, int maxlen)
 {
     zword **prev = history_view;
 
@@ -498,9 +498,9 @@ static void scrnset(int start, int c, int n)
 }
 
 #ifdef USE_UTF8
-static void utf8_mvaddstr(int y, int x, zword * buf)
+static void utf8_mvaddstr(int y, int x, zchar * buf)
 {
-    zword *bp = buf;
+    zchar *bp = buf;
 
     move(y,x);
     while(*bp) {
@@ -567,7 +567,7 @@ static void utf8_mvaddstr(int y, int x, zword * buf)
  * to implement word completion (similar to tcsh under Unix).
  *
  */
-zword os_read_line (int bufmax, zword *buf, int timeout, int width,
+zchar os_read_line (int bufmax, zchar *buf, int timeout, int width,
                     int continued)
 {
     int ch, y, x, len = strlen( (char *)buf);
@@ -716,7 +716,7 @@ zword os_read_line (int bufmax, zword *buf, int timeout, int width,
 #warning "Bill -- fix this for wide characters"
            {
                int status;
-               zword extension[10], saved_char;
+               zchar extension[10], saved_char;
 
                saved_char = buf[scrpos];
                buf[scrpos] = '\0';
@@ -797,15 +797,15 @@ zword os_read_line (int bufmax, zword *buf, int timeout, int width,
  * return it. Input aborts after timeout/10 seconds.
  *
  */
-zword os_read_key (int timeout, int cursor)
+zchar os_read_key (int timeout, int cursor)
 {
-    zword c;
+    zchar c;
 
     refresh();
     if (!cursor) curs_set(0);
 
     unix_set_global_timeout(timeout);
-    c = unix_read_char(0);
+    c = (zchar) unix_read_char(0);
 
     if (!cursor) curs_set(1);
     return c;
@@ -843,7 +843,7 @@ char *os_read_file_name (const char *default_name, int flag)
     char *tempname;
     zchar answer[4];
     char path_separator[2];
-    zword file_name[FILENAME_MAX + 1];
+    zchar file_name[FILENAME_MAX + 1];
 
     path_separator[0] = PATH_SEPARATOR;
     path_separator[1] = 0;
@@ -961,7 +961,7 @@ zword os_read_mouse (void)
  * param buf input buffer
  * returns new position
  */
-static int start_of_prev_word(int currpos, const zword* buf) {
+static int start_of_prev_word(int currpos, const zchar* buf) {
        int i, j;
        for (i = currpos - 1; i > 0 && buf[i] == ' '; i--) {}
        j = i;
@@ -979,7 +979,7 @@ static int start_of_prev_word(int currpos, const zword* buf) {
  * param len length of buf
  * returns new position
  */
-static int end_of_next_word(int currpos, const zword* buf, int len) {
+static int end_of_next_word(int currpos, const zchar* buf, int len) {
        int i;
        for (i = currpos; i < len && buf[i] == ' '; i++) {}
        for (; i < len && buf[i] != ' '; i++) {}
index 78663009ae32cab0f921f2696ac6bee1b94bf6f7..4973f7aa76776f0e37dcaba0ed2349fb1394dc22 100644 (file)
@@ -201,7 +201,7 @@ void os_set_font (int UNUSED(new_font))
  * bottom right corner.
  *
  */
-void os_display_char (zword c)
+void os_display_char (zchar c)
 {
     if (c >= ZC_LATIN1_MIN) {
         if (u_setup.plain_ascii) {
@@ -256,9 +256,9 @@ void os_display_char (zword c)
  * Pass a string of characters to os_display_char.
  *
  */
-void os_display_string (const zword *s)
+void os_display_string (const zchar *s)
 {
-    zword c;
+    zchar c;
 
     while ((c =  *s++) != 0) {
 
@@ -284,7 +284,7 @@ void os_display_string (const zword *s)
  * Return the width of the character in screen units.
  *
  */
-int os_char_width (zword c)
+int os_char_width (zchar c)
 {
     if (c >= ZC_LATIN1_MIN && u_setup.plain_ascii) {
 
@@ -317,10 +317,10 @@ int os_char_width (zword c)
  *    NEW_FONT  - next character is a new font
  *
  */
-int os_string_width (const zword *s)
+int os_string_width (const zchar *s)
 {
     int width = 0;
-    zword c;
+    zchar c;
 
     while ((c = *s++) != 0) {