1 /* stream.c - IO stream implementation
2 * Copyright (c) 1995-1997 Stefan Jokisch
4 * This file is part of Frotz.
6 * Frotz is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Frotz is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 zchar console_read_input (int max, zchar *buf, zword timeout, bool continued)
26 return os_read_line(max, buf, timeout, max, continued);
28 zchar console_read_key (zword timeout)
30 return os_read_key(timeout, 0);
33 extern bool validate_click (void);
35 extern void replay_open (void);
36 extern void replay_close (void);
37 extern void memory_open (zword, zword, bool);
38 extern void memory_close (void);
39 extern void record_open (void);
40 extern void record_close (void);
41 extern void script_open (void);
42 extern void script_close (void);
44 extern void memory_word (const zchar *);
45 extern void memory_new_line (void);
46 extern void record_write_key (zchar);
47 extern void record_write_input (const zchar *, zchar);
48 extern void script_char (zchar);
49 extern void script_word (const zchar *);
50 extern void script_new_line (void);
51 extern void script_write_input (const zchar *, zchar);
52 extern void script_erase_input (const zchar *);
53 extern void script_mssg_on (void);
54 extern void script_mssg_off (void);
55 extern void screen_char (zchar);
56 extern void screen_word (const zchar *);
57 extern void screen_new_line (void);
58 extern void screen_write_input (const zchar *, zchar);
59 extern void screen_erase_input (const zchar *);
60 extern void screen_mssg_on (void);
61 extern void screen_mssg_off (void);
63 extern zchar replay_read_key (void);
64 extern zchar replay_read_input (zchar *);
65 extern zchar console_read_key (zword);
66 extern zchar console_read_input (int, zchar *, zword, bool);
68 extern int direct_call (zword);
73 * Start printing a "debugging" message.
77 void stream_mssg_on (void)
84 if (ostream_script && enable_scripting)
94 * Stop printing a "debugging" message.
98 void stream_mssg_off (void)
105 if (ostream_script && enable_scripting)
110 }/* stream_mssg_off */
113 * z_output_stream, open or close an output stream.
115 * zargs[0] = stream to open (positive) or close (negative)
116 * zargs[1] = address to redirect output to (stream 3 only)
117 * zargs[2] = width of redirected output (stream 3 only, optional)
121 void z_output_stream (void)
126 switch ((short) zargs[0]) {
128 case 1: ostream_screen = TRUE;
130 case -1: ostream_screen = FALSE;
132 case 2: if (!ostream_script) script_open ();
134 case -2: if (ostream_script) script_close ();
136 case 3: memory_open (zargs[1], zargs[2], zargc >= 3);
138 case -3: memory_close ();
140 case 4: if (!ostream_record) record_open ();
142 case -4: if (ostream_record) record_close ();
147 }/* z_output_stream */
152 * Send a single character to the output stream.
156 void stream_char (zchar c)
161 if (ostream_script && enable_scripting)
169 * Send a string of characters to the output streams.
173 void stream_word (const zchar *s)
176 if (ostream_memory && !message)
184 if (ostream_script && enable_scripting)
194 * Send a newline to the output streams.
198 void stream_new_line (void)
201 if (ostream_memory && !message)
209 if (ostream_script && enable_scripting)
214 }/* stream_new_line */
217 * z_input_stream, select an input stream.
219 * zargs[0] = input stream to be selected
223 void z_input_stream (void)
228 if (zargs[0] == 0 && istream_replay)
230 if (zargs[0] == 1 && !istream_replay)
233 }/* z_input_stream */
238 * Read a single keystroke from the current input stream.
242 zchar stream_read_key ( zword timeout, zword routine )
248 /* Read key from current input stream */
255 key = replay_read_key ();
257 key = console_read_key (timeout);
259 } while (key == ZC_BAD);
261 /* Verify mouse clicks */
264 if (key == ZC_SINGLE_CLICK || key == ZC_DOUBLE_CLICK)
265 if (!validate_click ())
269 /* Copy key to the command file */
271 if (ostream_record && !istream_replay)
272 record_write_key (key);
274 /* Handle timeouts */
276 if (key == ZC_TIME_OUT)
277 if (direct_call (routine) == 0)
284 }/* stream_read_key */
289 * Read a line of input from the current input stream.
293 zchar stream_read_input ( int max, zchar *buf,
294 zword timeout, zword routine,
301 /* Remove initial input from the transscript file or from the screen */
303 if (ostream_script && enable_scripting && !no_scripting)
304 script_erase_input (buf);
305 //glkify if (istream_replay)
306 //glkify screen_erase_input (buf);
308 /* Read input line from current input stream */
315 key = replay_read_input (buf);
317 key = console_read_input (max, buf, timeout, key != ZC_BAD);
319 } while (key == ZC_BAD);
321 /* Verify mouse clicks */
324 if (key == ZC_SINGLE_CLICK || key == ZC_DOUBLE_CLICK)
325 if (!validate_click ())
329 /* Copy input line to the command file */
331 if (ostream_record && !istream_replay)
332 record_write_input (buf, key);
334 /* Handle timeouts */
336 if (key == ZC_TIME_OUT)
337 if (direct_call (routine) == 0)
340 /* Copy input line to transscript file or to the screen */
342 if (ostream_script && enable_scripting && !no_scripting)
343 script_write_input (buf, key);
344 //glkify if (istream_replay)
345 //glkify screen_write_input (buf, key);
347 /* Return terminating key */
351 }/* stream_read_input */