| | 1 | /* $Header: d:/cvsroot/tads/tads3/vmbiftad.h,v 1.2 1999/05/17 02:52:29 MJRoberts Exp $ */ |
| | 2 | |
| | 3 | /* |
| | 4 | * Copyright (c) 1998, 2002 Michael J. Roberts. All Rights Reserved. |
| | 5 | * |
| | 6 | * Please see the accompanying license file, LICENSE.TXT, for information |
| | 7 | * on using and copying this software. |
| | 8 | */ |
| | 9 | /* |
| | 10 | Name |
| | 11 | vmbiftad.h - function set definition - TADS I/O function set |
| | 12 | Function |
| | 13 | |
| | 14 | Notes |
| | 15 | |
| | 16 | Modified |
| | 17 | 12/06/98 MJRoberts - Creation |
| | 18 | */ |
| | 19 | |
| | 20 | #ifndef VMBIFTIO_H |
| | 21 | #define VMBIFTIO_H |
| | 22 | |
| | 23 | #include "os.h" |
| | 24 | #include "vmbif.h" |
| | 25 | #include "utf8.h" |
| | 26 | |
| | 27 | /* ------------------------------------------------------------------------ */ |
| | 28 | /* |
| | 29 | * TADS I/O function set built-in functions |
| | 30 | */ |
| | 31 | class CVmBifTIO: public CVmBif |
| | 32 | { |
| | 33 | public: |
| | 34 | /* |
| | 35 | * Input/output functions |
| | 36 | */ |
| | 37 | static void say(VMG_ uint argc); |
| | 38 | static void logging(VMG_ uint argc); |
| | 39 | static void clearscreen(VMG_ uint argc); |
| | 40 | static void more(VMG_ uint argc); |
| | 41 | static void input(VMG_ uint argc); |
| | 42 | static void inputkey(VMG_ uint argc); |
| | 43 | static void inputevent(VMG_ uint argc); |
| | 44 | static void inputdialog(VMG_ uint argc); |
| | 45 | static void askfile(VMG_ uint argc); |
| | 46 | static void timedelay(VMG_ uint argc); |
| | 47 | static void sysinfo(VMG_ uint argc); |
| | 48 | static void status_mode(VMG_ uint argc); |
| | 49 | static void status_right(VMG_ uint argc); |
| | 50 | static void res_exists(VMG_ uint argc); |
| | 51 | static void set_script_file(VMG_ uint argc); |
| | 52 | static void get_charset(VMG_ uint argc); |
| | 53 | static void flush_output(VMG_ uint argc); |
| | 54 | static void input_timeout(VMG_ uint argc); |
| | 55 | static void input_cancel(VMG_ uint argc); |
| | 56 | |
| | 57 | /* |
| | 58 | * banner window functions |
| | 59 | */ |
| | 60 | static void banner_create(VMG_ uint argc); |
| | 61 | static void banner_delete(VMG_ uint argc); |
| | 62 | static void banner_say(VMG_ uint argc); |
| | 63 | static void banner_clear(VMG_ uint argc); |
| | 64 | static void banner_flush(VMG_ uint argc); |
| | 65 | static void banner_size_to_contents(VMG_ uint argc); |
| | 66 | static void banner_goto(VMG_ uint argc); |
| | 67 | static void banner_set_text_color(VMG_ uint argc); |
| | 68 | static void banner_set_screen_color(VMG_ uint argc); |
| | 69 | static void banner_get_info(VMG_ uint argc); |
| | 70 | static void banner_set_size(VMG_ uint argc); |
| | 71 | |
| | 72 | /* |
| | 73 | * log console functions |
| | 74 | */ |
| | 75 | static void log_console_create(VMG_ uint argc); |
| | 76 | static void log_console_close(VMG_ uint argc); |
| | 77 | static void log_console_say(VMG_ uint argc); |
| | 78 | |
| | 79 | protected: |
| | 80 | /* |
| | 81 | * Map an "extended" keystroke from raw (os_getc_raw, os_get_event) to |
| | 82 | * portable UTF-8 representation. An extended keystroke is one of the |
| | 83 | * CMD_xxx key sequences, which the os_xxx layer represents by |
| | 84 | * returning a null (zero) byte followed by a CMD_xxx code. The caller |
| | 85 | * should simply pass the second byte of the sequence here, and we'll |
| | 86 | * provide a suitable key name. The buffer that 'buf' points to must |
| | 87 | * be at least 32 bytes long. |
| | 88 | * |
| | 89 | * - For ALT keys, we'll return a name like '[alt-x]'. |
| | 90 | * |
| | 91 | * - For CMD_xxx codes, we'll return a key name enclosed in square |
| | 92 | * brackets; for example, for a left cursor arrow key, we'll return |
| | 93 | * '[left]'. |
| | 94 | * |
| | 95 | * - For unknown CMD_xxx keys, we'll return '[?]'. |
| | 96 | */ |
| | 97 | static int map_ext_key(VMG_ char *buf, int extc); |
| | 98 | |
| | 99 | /* |
| | 100 | * Map a keystroke from raw (os_getc_raw) notation to a portable UTF-8 |
| | 101 | * representation. Takes an array of bytes giving the local character, |
| | 102 | * which might be represented as a multi-byte sequence. The caller is |
| | 103 | * responsible for calling raw_key_complete() to determine when enough |
| | 104 | * bytes have been fetched from the osifc layer to form a complete |
| | 105 | * character. |
| | 106 | * |
| | 107 | * - For backspace (ctrl-H or ASCII 127), we'll return '[bksp]'. |
| | 108 | * |
| | 109 | * - For ASCII 10 or 13, we'll return ASCII 10 ('\n') |
| | 110 | * |
| | 111 | * - For ASCII 9, we'll return ASCII 9 ('\t'). |
| | 112 | * |
| | 113 | * - For other control characters, we'll return a name like '[ctrl-z]'. |
| | 114 | * |
| | 115 | * - For Escape, we'll return '[esc]'. |
| | 116 | * |
| | 117 | * - For any non-control character that isn't a CMD_xxx command code, |
| | 118 | * we'll map the character to UTF-8 and return the resulting single |
| | 119 | * character (which might, of course, be more than one byte long). |
| | 120 | * |
| | 121 | * Returns true if we found a valid mapping for the key, false if not |
| | 122 | * (in which case the buffer will be filled in with '[?]'. The return |
| | 123 | * buffer is always null-terminated. |
| | 124 | */ |
| | 125 | static int map_raw_key(VMG_ char *buf, const char *c, size_t len); |
| | 126 | |
| | 127 | /* |
| | 128 | * Determine if the given byte sequence constitutes a complete |
| | 129 | * character in the local character set. Returns true if so, false if |
| | 130 | * not. Callers can use this to determine how many bytes must be |
| | 131 | * fetched from the keyboard to complete an entire character sequence |
| | 132 | * in the local character set, which can be important when using a |
| | 133 | * multi-byte character set. |
| | 134 | */ |
| | 135 | static int raw_key_complete(VMG_ const char *c, size_t len); |
| | 136 | |
| | 137 | /* display one or more arguments to a given console */ |
| | 138 | static void say_to_console(VMG_ class CVmConsole *console, uint argc); |
| | 139 | |
| | 140 | /* close the current script file */ |
| | 141 | static void close_script_file(VMG0_); |
| | 142 | }; |
| | 143 | |
| | 144 | |
| | 145 | #endif /* VMBIFTIO_H */ |
| | 146 | |
| | 147 | /* ------------------------------------------------------------------------ */ |
| | 148 | /* |
| | 149 | * TADS I/O function set vector. Define this only if VMBIF_DEFINE_VECTOR |
| | 150 | * has been defined, so that this file can be included for the prototypes |
| | 151 | * alone without defining the function vector. |
| | 152 | * |
| | 153 | * Note that this vector is specifically defined outside of the section of |
| | 154 | * the file protected against multiple inclusion. |
| | 155 | */ |
| | 156 | #ifdef VMBIF_DEFINE_VECTOR |
| | 157 | |
| | 158 | /* TADS input/output functions */ |
| | 159 | void (*G_bif_tadsio[])(VMG_ uint) = |
| | 160 | { |
| | 161 | &CVmBifTIO::say, |
| | 162 | &CVmBifTIO::logging, |
| | 163 | &CVmBifTIO::clearscreen, |
| | 164 | &CVmBifTIO::more, |
| | 165 | &CVmBifTIO::input, |
| | 166 | &CVmBifTIO::inputkey, |
| | 167 | &CVmBifTIO::inputevent, |
| | 168 | &CVmBifTIO::inputdialog, |
| | 169 | &CVmBifTIO::askfile, |
| | 170 | &CVmBifTIO::timedelay, |
| | 171 | &CVmBifTIO::sysinfo, |
| | 172 | &CVmBifTIO::status_mode, |
| | 173 | &CVmBifTIO::status_right, |
| | 174 | &CVmBifTIO::res_exists, |
| | 175 | &CVmBifTIO::set_script_file, |
| | 176 | &CVmBifTIO::get_charset, |
| | 177 | &CVmBifTIO::flush_output, |
| | 178 | &CVmBifTIO::input_timeout, |
| | 179 | &CVmBifTIO::input_cancel, |
| | 180 | |
| | 181 | &CVmBifTIO::banner_create, |
| | 182 | &CVmBifTIO::banner_delete, |
| | 183 | &CVmBifTIO::banner_clear, |
| | 184 | &CVmBifTIO::banner_say, |
| | 185 | &CVmBifTIO::banner_flush, |
| | 186 | &CVmBifTIO::banner_size_to_contents, |
| | 187 | &CVmBifTIO::banner_goto, |
| | 188 | &CVmBifTIO::banner_set_text_color, |
| | 189 | &CVmBifTIO::banner_set_screen_color, |
| | 190 | &CVmBifTIO::banner_get_info, |
| | 191 | &CVmBifTIO::banner_set_size, |
| | 192 | |
| | 193 | &CVmBifTIO::log_console_create, |
| | 194 | &CVmBifTIO::log_console_close, |
| | 195 | &CVmBifTIO::log_console_say |
| | 196 | }; |
| | 197 | |
| | 198 | #endif /* VMBIF_DEFINE_VECTOR */ |