From: David Griffith Date: Sat, 21 Sep 2019 23:22:21 +0000 (-0700) Subject: Convert input.c to K&R style. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=339e0328f0f6f3be2e301c4ba67f4d8dd4689b7f;p=liskon_frotz.git Convert input.c to K&R style. --- diff --git a/src/common/input.c b/src/common/input.c index fe4a259..303f64e 100644 --- a/src/common/input.c +++ b/src/common/input.c @@ -20,51 +20,46 @@ #include "frotz.h" -extern int save_undo (void); +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 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); +extern void tokenise_line(zword, zword, zword, bool); +zword unicode_tolower(zword); static bool truncate_question_mark(void); + /* * is_terminator * * Check if the given key is an input terminator. * */ - -bool is_terminator (zchar key) +bool is_terminator(zchar key) { - - if (key == ZC_TIME_OUT) - return TRUE; - if (key == ZC_RETURN) - return TRUE; - if (key >= ZC_HKEY_MIN && key <= ZC_HKEY_MAX) - return TRUE; - - if (h_terminating_keys != 0) - - if (key >= ZC_ARROW_MIN && key <= ZC_MENU_CLICK) { - - zword addr = h_terminating_keys; - zbyte c; - - do { - LOW_BYTE (addr, c); - if (c == 255 || key == translate_from_zscii (c)) - return TRUE; - addr++; - } while (c != 0); - + if (key == ZC_TIME_OUT) + return TRUE; + if (key == ZC_RETURN) + return TRUE; + if (key >= ZC_HKEY_MIN && key <= ZC_HKEY_MAX) + return TRUE; + + if (h_terminating_keys != 0) { + if (key >= ZC_ARROW_MIN && key <= ZC_MENU_CLICK) { + zword addr = h_terminating_keys; + zbyte c; + do { + LOW_BYTE(addr, c); + if (c == 255 || key == translate_from_zscii(c)) + return TRUE; + addr++; + } while (c != 0); + } } + return FALSE; +} /* is_terminator */ - return FALSE; - -}/* is_terminator */ /* * z_make_menu, add or remove a menu and branch if successful. @@ -73,17 +68,15 @@ bool is_terminator (zchar key) * zargs[1] = table of menu entries or 0 to remove menu * */ - -void z_make_menu (void) +void z_make_menu(void) { + /* This opcode was only used for the Macintosh version of Journey. + * It controls menus with numbers greater than 2 (menus 0, 1 and 2 + * are system menus). Frotz doesn't implement menus yet. + */ + branch(FALSE); +} /* z_make_menu */ - /* This opcode was only used for the Macintosh version of Journey. - It controls menus with numbers greater than 2 (menus 0, 1 and 2 - are system menus). Frotz doesn't implement menus yet. */ - - branch (FALSE); - -}/* z_make_menu */ /* * read_yes_or_no @@ -91,25 +84,24 @@ void z_make_menu (void) * Ask the user a question; return true if the answer is yes. * */ - -bool read_yes_or_no (const char *s) +bool read_yes_or_no(const char *s) { - zchar key; + zchar key; - print_string (s); - print_string ("? (y/n) >"); + print_string(s); + print_string("? (y/n) >"); - key = stream_read_key (0, 0, FALSE); + key = stream_read_key(0, 0, FALSE); - if (key == 'y' || key == 'Y') { - print_string ("y\n"); - return TRUE; - } else { - print_string ("n\n"); - return FALSE; - } + if (key == 'y' || key == 'Y') { + print_string("y\n"); + return TRUE; + } else { + print_string("n\n"); + return FALSE; + } +} /* read_yes_or_no */ -}/* read_yes_or_no */ /* * read_string @@ -120,17 +112,15 @@ bool read_yes_or_no (const char *s) void read_string (int max, zchar *buffer) { - zchar key; - - buffer[0] = 0; - - do { + zchar key; - key = stream_read_input (max, buffer, 0, 0, FALSE, FALSE); + buffer[0] = 0; - } while (key != ZC_RETURN); + do { + key = stream_read_input(max, buffer, 0, 0, FALSE, FALSE); + } while (key != ZC_RETURN); +} /* read_string */ -}/* read_string */ /* * read_number @@ -138,22 +128,21 @@ void read_string (int max, zchar *buffer) * Ask the user to type in a number and return it. * */ - -int read_number (void) +int read_number(void) { - zchar buffer[6]; - int value = 0; - int i; - - read_string (5, buffer); + zchar buffer[6]; + int value = 0; + int i; - for (i = 0; buffer[i] != 0; i++) - if (buffer[i] >= '0' && buffer[i] <= '9') - value = 10 * value + buffer[i] - '0'; + read_string(5, buffer); - return value; + for (i = 0; buffer[i] != 0; i++) { + if (buffer[i] >= '0' && buffer[i] <= '9') + value = 10 * value + buffer[i] - '0'; + } + return value; +} /* read_number */ -}/* read_number */ /* * z_read, read a line of input and (in V5+) store the terminating key. @@ -164,106 +153,86 @@ int read_number (void) * zargs[3] = packed address of routine to be called on timeout * */ - -void z_read (void) +void z_read(void) { - zchar buffer[INPUT_BUFFER_SIZE]; - zword addr; - zchar key; - zbyte max, size; - zbyte c; - int i; - - /* Supply default arguments */ - - if (zargc < 3) - zargs[2] = 0; - - /* Get maximum input size */ - - addr = zargs[0]; - - LOW_BYTE (addr, max); - - if (h_version <= V4) - max--; - - if (max >= INPUT_BUFFER_SIZE) - max = INPUT_BUFFER_SIZE - 1; - - /* Get initial input size */ - - if (h_version >= V5) { - addr++; - LOW_BYTE (addr, size); - } else size = 0; - - /* Copy initial input to local buffer */ - - for (i = 0; i < size; i++) { - addr++; - LOW_BYTE (addr, c); - buffer[i] = translate_from_zscii (c); - } - - buffer[i] = 0; - - /* Draw status line for V1 to V3 games */ - - if (h_version <= V3) - z_show_status (); - - /* Read input from current input stream */ - - key = stream_read_input ( - max, buffer, /* buffer and size */ - zargs[2], /* timeout value */ - zargs[3], /* timeout routine */ - TRUE, /* enable hot keys */ - h_version == V6); /* no script in V6 */ - - if (key == ZC_BAD) - return; - - /* Perform save_undo for V1 to V4 games */ - - if (h_version <= V4) - save_undo (); - - /* Copy local buffer back to dynamic memory */ - - for (i = 0; buffer[i] != 0; i++) { - - if (key == ZC_RETURN) { - - buffer[i] = unicode_tolower (buffer[i]); + zchar buffer[INPUT_BUFFER_SIZE]; + zword addr; + zchar key; + zbyte max, size; + zbyte c; + int i; + + /* Supply default arguments */ + if (zargc < 3) + zargs[2] = 0; + + /* Get maximum input size */ + addr = zargs[0]; + LOW_BYTE (addr, max); + if (h_version <= V4) + max--; + if (max >= INPUT_BUFFER_SIZE) + max = INPUT_BUFFER_SIZE - 1; + + /* Get initial input size */ + if (h_version >= V5) { + addr++; + LOW_BYTE(addr, size); + } else size = 0; + /* Copy initial input to local buffer */ + for (i = 0; i < size; i++) { + addr++; + LOW_BYTE(addr, c); + buffer[i] = translate_from_zscii(c); + } + buffer[i] = 0; + + /* Draw status line for V1 to V3 games */ + if (h_version <= V3) + z_show_status(); + + /* Read input from current input stream */ + key = stream_read_input ( + max, buffer, /* buffer and size */ + zargs[2], /* timeout value */ + zargs[3], /* timeout routine */ + TRUE, /* enable hot keys */ + h_version == V6); /* no script in V6 */ + + if (key == ZC_BAD) + return; + + /* Perform save_undo for V1 to V4 games */ + if (h_version <= V4) + save_undo(); + + /* Copy local buffer back to dynamic memory */ + for (i = 0; buffer[i] != 0; i++) { + if (key == ZC_RETURN) { + buffer[i] = unicode_tolower(buffer[i]); + } + if (truncate_question_mark() && buffer[i] == '?') + buffer[i] = ' '; + storeb((zword) (zargs[0] + ((h_version <= V4) ? 1 : 2) + i), + translate_to_zscii (buffer[i])); } - if (truncate_question_mark() && buffer[i] == '?') buffer[i] = ' '; - - storeb ((zword) (zargs[0] + ((h_version <= V4) ? 1 : 2) + i), translate_to_zscii (buffer[i])); - - } - - /* Add null character (V1-V4) or write input length into 2nd byte */ - - if (h_version <= V4) - storeb ((zword) (zargs[0] + 1 + i), 0); - else - storeb ((zword) (zargs[0] + 1), i); - - /* Tokenise line if a token buffer is present */ - - if (key == ZC_RETURN && zargs[1] != 0) - tokenise_line (zargs[0], zargs[1], 0, FALSE); + /* Add null character (V1-V4) or write input length into 2nd byte */ + if (h_version <= V4) + storeb((zword) (zargs[0] + 1 + i), 0); + else + storeb((zword) (zargs[0] + 1), i); - /* Store key */ + /* Tokenise line if a token buffer is present */ + if (key == ZC_RETURN && zargs[1] != 0) + tokenise_line (zargs[0], zargs[1], 0, FALSE); - if (h_version >= V5) - store (translate_to_zscii (key)); + /* Store key */ + if (h_version >= V5) + store(translate_to_zscii (key)); +} /* z_read */ -}/* z_read */ /* * z_read_char, read and store a key. @@ -274,36 +243,34 @@ void z_read (void) * */ -void z_read_char (void) +void z_read_char(void) { - zchar key; + zchar key; - /* Supply default arguments */ + /* Supply default arguments */ + if (zargc < 2) + zargs[1] = 0; - if (zargc < 2) - zargs[1] = 0; + /* Read input from the current input stream */ + key = stream_read_key( + zargs[1], /* timeout value */ + zargs[2], /* timeout routine */ + TRUE); /* enable hot keys */ - /* Read input from the current input stream */ + if (key == ZC_BAD) + return; - key = stream_read_key ( - zargs[1], /* timeout value */ - zargs[2], /* timeout routine */ - TRUE); /* enable hot keys */ + /* Store key */ + /* For timeouts, make sure translate_to_zscii() won't try to convert + * 0x00. We should instead return 0x00 as is. + * Thanks to Peter Seebach. + */ + if (key == 0) + store(key); + else + store(translate_to_zscii (key)); +} /* z_read_char */ - if (key == ZC_BAD) - return; - - /* Store key */ - - /* For timeouts, make sure translate_to_zscii() won't try to convert - * 0x00. We should instead return 0x00 as is. - * Thanks to Peter Seebach. - */ - if (key == 0) - store(key); - else - store (translate_to_zscii (key)); -}/* z_read_char */ /* * z_read_mouse, write the current mouse status into a table. @@ -312,25 +279,26 @@ void z_read_char (void) * */ -void z_read_mouse (void) +void z_read_mouse(void) { - zword btn; + zword btn; - btn = 1; + btn = 1; - /** I don't remember what was going on here */ - /* Read the mouse position and which buttons are down */ + /** I don't remember what was going on here */ + /* Read the mouse position and which buttons are down */ /* - btn = os_read_mouse (); - hx_mouse_y = mouse_y; - hx_mouse_x = mouse_x; + btn = os_read_mouse (); + hx_mouse_y = mouse_y; + hx_mouse_x = mouse_x; */ - storew ((zword) (zargs[0] + 0), hx_mouse_y); - storew ((zword) (zargs[0] + 2), hx_mouse_x); - storew ((zword) (zargs[0] + 4), btn); /* mouse button bits */ - storew ((zword) (zargs[0] + 6), 0); /* menu selection */ + storew((zword) (zargs[0] + 0), hx_mouse_y); + storew((zword) (zargs[0] + 2), hx_mouse_x); + storew((zword) (zargs[0] + 4), btn); /* mouse button bits */ + storew((zword) (zargs[0] + 6), 0); /* menu selection */ + +} /* z_read_mouse */ -}/* z_read_mouse */ /* * truncate_question_mark