1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef GLK_TADS_TADS2_TEXT_IO 24 #define GLK_TADS_TADS2_TEXT_IO 25 26 /* 27 * Text I/O interface 28 * 29 * Formatted text input and output interface definition 30 */ 31 32 #include "glk/tads/tads.h" 33 #include "glk/tads/tads2/error_handling.h" 34 #include "glk/tads/tads2/run.h" 35 36 namespace Glk { 37 namespace TADS { 38 namespace TADS2 { 39 40 /* forward decls */ 41 struct runcxdef; 42 43 /** 44 * Text i/o context 45 */ 46 struct tiocxdef { 47 errcxdef *tiocxerr; /* error handling context */ 48 }; 49 50 /** 51 * Initialize the output formatter subsystem. This must be called once 52 * at startup. 53 */ 54 void out_init(); 55 56 57 /* redirect all tioxxx routines to TADS v1.x outxxx equivalents */ 58 #define tioflushn(ctx, nl) outflushn(nl) 59 #define tioflush(ctx) outflush() 60 #define tioblank(ctx) outblank() 61 #define tioreset(ctx) outreset() 62 #define tiogets(ctx, prompt, str, siz) getstring(prompt, str, siz) 63 #define tioputs(ctx, str) outformat(str) 64 #define tioputslen(ctx, str, len) outformatlen(str, len) 65 #define tiocaps(ctx) outcaps() 66 #define tionocaps(ctx) outnocaps() 67 #define tioshow(ctx) outshow() 68 #define tiohide(ctx) outhide() 69 #define tioscore(ctx, s1, s2) os_score(s1, s2) 70 #define tiostrsc(ctx, s) os_strsc(s) 71 72 /* set up format strings in output subsystem */ 73 void tiosetfmt(tiocxdef *ctx, runcxdef *rctx, uchar *fmtbase, 74 uint fmtlen); 75 76 /* tell tio subsystem the current actor */ 77 void tiosetactor(tiocxdef *ctx, objnum actor); 78 79 /* get the current tio subsystem actor */ 80 objnum tiogetactor(tiocxdef *ctx); 81 82 /* turn output capture on/off */ 83 void tiocapture(tiocxdef *tioctx, mcmcxdef *memctx, int flag); 84 85 /* get the capture object handle */ 86 mcmon tiogetcapture(tiocxdef *ctx); 87 88 /* get the amount of text captured */ 89 uint tiocapturesize(tiocxdef *ctx); 90 91 /* format a length-prefixed (runtime-style) string to the display */ 92 void outfmt(tiocxdef *ctx, uchar *txt); 93 94 /* format a null-terminated (C-style) string to the display */ 95 int outformat(const char *s); 96 97 /* format a counted-length string, which may not be null-terminated */ 98 int outformatlen(const char *s, uint len); 99 100 /* flush output, with specified newline mode */ 101 void outflushn(int nl); 102 103 /* flush output */ 104 void outflush(void); 105 106 /* reset output state */ 107 void outreset(void); 108 109 /* 110 * Get a string from the keyboard. Returns non-zero if an error occurs 111 * (in particular, if no more input is available from the keyboard), 112 * zero on success. 113 */ 114 int getstring(const char *prompt, char *buf, int bufl); 115 116 /* set capitalize-next-character mode on/off */ 117 void outcaps(void); 118 void outnocaps(void); 119 120 /* open/close output log file */ 121 int tiologopn(tiocxdef *ctx, char *fn); 122 int tiologcls(tiocxdef *ctx); 123 124 /* 125 * Write text explicitly to the log file. This can be used to add 126 * special text (such as prompt text) that would normally be suppressed 127 * from the log file. When more mode is turned off, we don't 128 * automatically copy text to the log file; any text that the caller 129 * knows should be in the log file during times when more mode is turned 130 * off can be explicitly added with this function. 131 * 132 * If nl is true, we'll add a newline at the end of this text. The 133 * caller should not include any newlines in the text being displayed 134 * here. 135 */ 136 void out_logfile_print(const char *txt, int nl); 137 138 139 /* 140 * Check output status. Indicate whether output is currently hidden, 141 * and whether any hidden output has occurred. 142 */ 143 void outstat(int *hidden, int *output_occurred); 144 145 /* hide/show output */ 146 void outhide(void); 147 int outshow(void); 148 149 /* set the flag to indicate that output has occurred */ 150 void outsethidden(void); 151 152 /* write a blank line */ 153 void outblank(void); 154 155 /* start/end watchpoint evaluation */ 156 void outwx(int flag); 157 158 /* Begin/end capturing */ 159 void tiocapture(tiocxdef *tioctx, mcmcxdef *memctx, int flag); 160 161 /* clear all captured output */ 162 void tioclrcapture(tiocxdef *tioctx); 163 164 /* 165 * clear captured output back to a given point -- this can be used to 166 * remove captured output in an inner capture from an enclosing capture 167 */ 168 void tiopopcapture(tiocxdef *tioctx, uint orig_size); 169 170 /* get the object handle of the captured output */ 171 mcmon tiogetcapture(tiocxdef *ctx); 172 173 /* get the amount of text captured */ 174 uint tiocapturesize(tiocxdef *ctx); 175 176 /* turn MORE mode on or off */ 177 int setmore(int state); 178 179 /* explicitly activate the "MORE" prompt */ 180 void out_more_prompt(); 181 182 /* 183 * QA controller functions 184 */ 185 int qasopn(char *scrnam, int quiet); 186 void qasclose(void); 187 char *qasgets(char *buf, int bufl); 188 189 /* 190 * Set an HTML entity expansion. This is called during initialization 191 * when we read a character mapping table that includes HTML entity 192 * expansions. The HTML run-time uses its own expansion mechanism, so 193 * it will ignore this information. The standard character-mode TADS 194 * run-time, however, uses this information to map HTML entities to the 195 * local character set. 196 */ 197 void tio_set_html_expansion(unsigned int html_char_val, 198 const char *expansion, size_t expansion_len); 199 200 /* check for HTML mode - returns true if an "\H+" sequence is active */ 201 int tio_is_html_mode(); 202 203 /* set the user output filter function */ 204 void out_set_filter(objnum filter_fn); 205 206 /* set the double-space mode */ 207 void out_set_doublespace(int dbl); 208 209 /* 210 * Ask for a filename, using a system-defined dialog (via os_askfile) if 211 * possible. Uses the same interface as os_askfile(), which we will 212 * call directly for graphical implementations. We'll use formatted 213 * text for text-only implementations. 214 */ 215 int tio_askfile(const char *prompt, char *reply, int replen, int prompt_type, os_filetype_t file_type); 216 217 /* 218 * Display a dialog, using a system-defined dialog (via os_input_dialog) 219 * if possible. Uses the same interface as os_input_dialog(), which we 220 * will call directly for graphical implementations. We'll use 221 * formatted text for text-only implementations. 222 */ 223 int tio_input_dialog(int icon_id, const char *prompt, int standard_button_set, 224 const char **buttons, int button_count, 225 int default_index, int cancel_index); 226 227 228 } // End of namespace TADS2 229 } // End of namespace TADS 230 } // End of namespace Glk 231 232 #endif 233