-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.c
356 lines (265 loc) · 6.08 KB
/
stream.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/* stream.c - IO stream implementation
* Copyright (c) 1995-1997 Stefan Jokisch
*
* This file is part of Frotz.
*
* Frotz is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Frotz is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "frotz.h"
extern bool A00271 (zchar);
extern bool A00272 (void);
extern void A00251 (void);
extern void A00252 (void);
extern void A00273 (zword, zword, bool);
extern void A00274 (void);
extern void A00253 (void);
extern void A00254 (void);
extern void A00026 (void);
extern void A00027 (void);
extern void A00275 (const zchar *);
extern void A00276 (void);
extern void A00277 (zchar);
extern void A00278 (const zchar *, zchar);
extern void A00279 (zchar);
extern void A00280 (const zchar *);
extern void A00281 (void);
extern void A00282 (const zchar *, zchar);
extern void A00283 (const zchar *);
extern void A00284 (void);
extern void A00285 (void);
extern void A00286 (zchar);
extern void A00287 (const zchar *);
extern void A00208 (void);
extern void A00288 (const zchar *, zchar);
extern void A00289 (const zchar *);
extern void A00290 (void);
extern void A00291 (void);
extern zchar A00292 (void);
extern zchar A00293 (zchar *);
extern zchar A00294 (zword);
extern zchar A00295 (int, zchar *, zword, bool);
extern int A00269 (zword);
/*
* A00200
*
* Start printing a "debugging" A00084.
*
*/
void A00200 (void)
{
A00194 ();
if (A00079)
A00290 ();
if (A00080 && A00090)
A00284 ();
A00084 = TRUE;
}/* A00200 */
/*
* A00201
*
* Stop printing a "debugging" A00084.
*
*/
void A00201 (void)
{
A00194 ();
if (A00079)
A00291 ();
if (A00080 && A00090)
A00285 ();
A00084 = FALSE;
}/* A00201 */
/*
* A00131, open or close an output stream.
*
* zargs[0] = stream to open (positive) or close (negative)
* zargs[1] = address to redirect output to (stream 3 only)
* zargs[2] = width of redirected output (stream 3 only, optional)
*
*/
void A00131 (void)
{
A00194 ();
switch (A00247( zargs[0]) ) {
case 1: A00079 = TRUE;
break;
case -1: A00079 = FALSE;
break;
case 2: if (!A00080) A00026 ();
break;
case -2: if (A00080) A00027 ();
break;
case 3: A00273 (zargs[1], zargs[2], zargc >= 3);
break;
case -3: A00274 ();
break;
case 4: if (!A00082) A00253 ();
break;
case -4: if (A00082) A00254 ();
break;
}
}/* A00131 */
/*
* A00000
*
* Send a single character to the output stream.
*
*/
void A00000 (zchar c)
{
if (A00079)
A00286 (c);
if (A00080 && A00090)
A00279 (c);
}/* A00000 */
/*
* A00001
*
* Send a string of characters to the output streams.
*
*/
void A00001 (const zchar *s)
{
if (A00081 && !A00084)
A00275 (s);
else {
if (A00079)
A00287 (s);
if (A00080 && A00090)
A00280 (s);
}
}/* A00001 */
/*
* A00002
*
* Send a newline to the output streams.
*
*/
void A00002 (void)
{
if (A00081 && !A00084)
A00276 ();
else {
if (A00079)
A00208 ();
if (A00080 && A00090)
A00281 ();
}
}/* A00002 */
/*
* A00120, select an input stream.
*
* zargs[0] = input stream to be selected
*
*/
void A00120 (void)
{
A00194 ();
if (zargs[0] == 0 && A00083)
A00252 ();
if (zargs[0] == 1 && !A00083)
A00251 ();
}/* A00120 */
/*
* A00256
*
* Read a single keystroke from the current input stream.
*
*/
zchar A00256 ( zword timeout, zword routine, bool hot_keys )
{
zchar key = ZC_BAD;
A00194 ();
/* Read key from current input stream */
continue_input:
do {
if (A00083)
key = A00292 ();
else
key = A00294 (timeout);
} while (key == ZC_BAD);
/* Verify mouse clicks */
if (key == ZC_SINGLE_CLICK || key == ZC_DOUBLE_CLICK)
if (!A00272 ())
goto continue_input;
/* Copy key to the command file */
if (A00082 && !A00083)
A00277 (key);
/* Handle timeouts */
if (key == ZC_TIME_OUT)
if (A00269 (routine) == 0)
goto continue_input;
/* Handle hot keys */
if (hot_keys && key >= ZC_HKEY_MIN && key <= ZC_HKEY_MAX) {
if (A00035 == V4 && key == ZC_HKEY_UNDO)
goto continue_input;
if (!A00271 (key))
goto continue_input;
return ZC_BAD;
}
/* Return key */
return key;
}/* A00256 */
/*
* A00257
*
* Read a line of input from the current input stream.
*
*/
zchar A00257 ( int max, zchar *buf,
zword timeout, zword routine,
bool hot_keys,
bool no_scripting )
{
zchar key = ZC_BAD;
A00194 ();
/* Remove initial input from the transcript file or from the screen */
if (A00080 && A00090 && !no_scripting)
A00283 (buf);
if (A00083)
A00289 (buf);
/* Read input line from current input stream */
continue_input:
do {
if (A00083)
key = A00293 (buf);
else
key = A00295 (max, buf, timeout, key != ZC_BAD);
} while (key == ZC_BAD);
/* Verify mouse clicks */
if (key == ZC_SINGLE_CLICK || key == ZC_DOUBLE_CLICK)
if (!A00272 ())
goto continue_input;
/* Copy input line to the command file */
if (A00082 && !A00083)
A00278 (buf, key);
/* Handle timeouts */
if (key == ZC_TIME_OUT)
if (A00269 (routine) == 0)
goto continue_input;
/* Handle hot keys */
if (hot_keys && key >= ZC_HKEY_MIN && key <= ZC_HKEY_MAX) {
if (!A00271 (key))
goto continue_input;
return ZC_BAD;
}
/* Copy input line to transcript file or to the screen */
if (A00080 && A00090 && !no_scripting)
A00282 (buf, key);
if (A00083)
A00288 (buf, key);
/* Return terminating key */
return key;
}/* A00257 */