io.c revision 1.4 1 1.4 christos /* $NetBSD: io.c,v 1.4 1997/08/11 14:06:15 christos Exp $ */
2 1.2 cgd
3 1.1 jtc /*-
4 1.1 jtc * Copyright (c) 1991, 1993
5 1.1 jtc * The Regents of the University of California. All rights reserved.
6 1.1 jtc *
7 1.1 jtc * The game adventure was originally written in Fortran by Will Crowther
8 1.1 jtc * and Don Woods. It was later translated to C and enhanced by Jim
9 1.1 jtc * Gillogly. This code is derived from software contributed to Berkeley
10 1.1 jtc * by Jim Gillogly at The Rand Corporation.
11 1.1 jtc *
12 1.1 jtc * Redistribution and use in source and binary forms, with or without
13 1.1 jtc * modification, are permitted provided that the following conditions
14 1.1 jtc * are met:
15 1.1 jtc * 1. Redistributions of source code must retain the above copyright
16 1.1 jtc * notice, this list of conditions and the following disclaimer.
17 1.1 jtc * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 jtc * notice, this list of conditions and the following disclaimer in the
19 1.1 jtc * documentation and/or other materials provided with the distribution.
20 1.1 jtc * 3. All advertising materials mentioning features or use of this software
21 1.1 jtc * must display the following acknowledgement:
22 1.1 jtc * This product includes software developed by the University of
23 1.1 jtc * California, Berkeley and its contributors.
24 1.1 jtc * 4. Neither the name of the University nor the names of its contributors
25 1.1 jtc * may be used to endorse or promote products derived from this software
26 1.1 jtc * without specific prior written permission.
27 1.1 jtc *
28 1.1 jtc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.1 jtc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.1 jtc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.1 jtc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.1 jtc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.1 jtc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.1 jtc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.1 jtc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.1 jtc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.1 jtc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.1 jtc * SUCH DAMAGE.
39 1.1 jtc */
40 1.1 jtc
41 1.4 christos #include <sys/cdefs.h>
42 1.1 jtc #ifndef lint
43 1.2 cgd #if 0
44 1.1 jtc static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
45 1.2 cgd #else
46 1.4 christos __RCSID("$NetBSD: io.c,v 1.4 1997/08/11 14:06:15 christos Exp $");
47 1.2 cgd #endif
48 1.1 jtc #endif /* not lint */
49 1.1 jtc
50 1.1 jtc /* Re-coding of advent in C: file i/o and user i/o */
51 1.1 jtc
52 1.1 jtc #include <stdio.h>
53 1.3 cgd #include <string.h>
54 1.4 christos #include <stdlib.h>
55 1.4 christos #include "hdr.h"
56 1.4 christos #include "extern.h"
57 1.1 jtc
58 1.1 jtc
59 1.4 christos void
60 1.1 jtc getin(wrd1,wrd2) /* get command from user */
61 1.1 jtc char **wrd1,**wrd2; /* no prompt, usually */
62 1.1 jtc { register char *s;
63 1.1 jtc static char wd1buf[MAXSTR],wd2buf[MAXSTR];
64 1.1 jtc int first, numch;
65 1.1 jtc
66 1.1 jtc *wrd1=wd1buf; /* return ptr to internal string*/
67 1.1 jtc *wrd2=wd2buf;
68 1.1 jtc wd2buf[0]=0; /* in case it isn't set here */
69 1.1 jtc for (s=wd1buf, first=1, numch=0;;)
70 1.1 jtc { if ((*s=getchar())>='A' && *s <='Z') *s = *s - ('A' -'a');
71 1.1 jtc /* convert to upper case */
72 1.1 jtc switch(*s) /* start reading from user */
73 1.1 jtc { case '\n':
74 1.1 jtc *s=0;
75 1.1 jtc return;
76 1.1 jtc case ' ':
77 1.1 jtc if (s==wd1buf||s==wd2buf) /* initial blank */
78 1.1 jtc continue;
79 1.1 jtc *s=0;
80 1.1 jtc if (first) /* finished 1st wd; start 2nd */
81 1.1 jtc { first=numch=0;
82 1.1 jtc s=wd2buf;
83 1.1 jtc break;
84 1.1 jtc }
85 1.1 jtc else /* finished 2nd word */
86 1.1 jtc { FLUSHLINE;
87 1.1 jtc *s=0;
88 1.1 jtc return;
89 1.1 jtc }
90 1.1 jtc default:
91 1.1 jtc if (++numch>=MAXSTR) /* string too long */
92 1.1 jtc { printf("Give me a break!!\n");
93 1.1 jtc wd1buf[0]=wd2buf[0]=0;
94 1.1 jtc FLUSHLINE;
95 1.1 jtc return;
96 1.1 jtc }
97 1.1 jtc s++;
98 1.1 jtc }
99 1.1 jtc }
100 1.1 jtc }
101 1.1 jtc
102 1.4 christos int
103 1.1 jtc confirm(mesg) /* confirm irreversible action */
104 1.1 jtc char *mesg;
105 1.1 jtc { register int result;
106 1.1 jtc printf("%s",mesg); /* tell him what he did */
107 1.1 jtc if (getchar()=='y') /* was his first letter a 'y'? */
108 1.1 jtc result=1;
109 1.1 jtc else result=0;
110 1.1 jtc FLUSHLINE;
111 1.1 jtc return(result);
112 1.1 jtc }
113 1.1 jtc
114 1.4 christos int
115 1.1 jtc yes(x,y,z) /* confirm with rspeak */
116 1.1 jtc int x,y,z;
117 1.4 christos { register int result = TRUE; /* pacify gcc */
118 1.1 jtc register char ch;
119 1.1 jtc for (;;)
120 1.1 jtc { rspeak(x); /* tell him what we want*/
121 1.1 jtc if ((ch=getchar())=='y')
122 1.1 jtc result=TRUE;
123 1.1 jtc else if (ch=='n') result=FALSE;
124 1.1 jtc FLUSHLINE;
125 1.1 jtc if (ch=='y'|| ch=='n') break;
126 1.1 jtc printf("Please answer the question.\n");
127 1.1 jtc }
128 1.1 jtc if (result==TRUE) rspeak(y);
129 1.1 jtc if (result==FALSE) rspeak(z);
130 1.1 jtc return(result);
131 1.1 jtc }
132 1.1 jtc
133 1.4 christos int
134 1.1 jtc yesm(x,y,z) /* confirm with mspeak */
135 1.1 jtc int x,y,z;
136 1.4 christos { register int result = TRUE; /* pacify gcc */
137 1.1 jtc register char ch;
138 1.1 jtc for (;;)
139 1.1 jtc { mspeak(x); /* tell him what we want*/
140 1.1 jtc if ((ch=getchar())=='y')
141 1.1 jtc result=TRUE;
142 1.1 jtc else if (ch=='n') result=FALSE;
143 1.1 jtc FLUSHLINE;
144 1.1 jtc if (ch=='y'|| ch=='n') break;
145 1.1 jtc printf("Please answer the question.\n");
146 1.1 jtc }
147 1.1 jtc if (result==TRUE) mspeak(y);
148 1.1 jtc if (result==FALSE) mspeak(z);
149 1.1 jtc return(result);
150 1.1 jtc }
151 1.1 jtc
152 1.1 jtc /* FILE *inbuf,*outbuf; */
153 1.1 jtc
154 1.1 jtc char *inptr; /* Pointer into virtual disk */
155 1.1 jtc
156 1.1 jtc int outsw = 0; /* putting stuff to data file? */
157 1.1 jtc
158 1.1 jtc char iotape[] = "Ax3F'\003tt$8h\315qer*h\017nGKrX\207:!l";
159 1.1 jtc char *tape = iotape; /* pointer to encryption tape */
160 1.1 jtc
161 1.4 christos int
162 1.1 jtc next() /* next virtual char, bump adr */
163 1.1 jtc {
164 1.1 jtc int ch;
165 1.1 jtc
166 1.1 jtc ch=(*inptr ^ random()) & 0xFF; /* Decrypt input data */
167 1.1 jtc if (outsw) /* putting data in tmp file */
168 1.1 jtc { if (*tape==0) tape=iotape; /* rewind encryption tape */
169 1.1 jtc *inptr = ch ^ *tape++; /* re-encrypt and replace value */
170 1.1 jtc }
171 1.1 jtc inptr++;
172 1.1 jtc return(ch);
173 1.1 jtc }
174 1.1 jtc
175 1.1 jtc char breakch; /* tell which char ended rnum */
176 1.1 jtc
177 1.4 christos void
178 1.1 jtc rdata() /* "read" data from virtual file*/
179 1.1 jtc { register int sect;
180 1.1 jtc register char ch;
181 1.1 jtc
182 1.1 jtc inptr = data_file; /* Pointer to virtual data file */
183 1.1 jtc srandom(SEED); /* which is lightly encrypted. */
184 1.1 jtc
185 1.1 jtc clsses=1;
186 1.1 jtc for (;;) /* read data sections */
187 1.1 jtc { sect=next()-'0'; /* 1st digit of section number */
188 1.1 jtc #ifdef VERBOSE
189 1.1 jtc printf("Section %c",sect+'0');
190 1.1 jtc #endif
191 1.1 jtc if ((ch=next())!=LF) /* is there a second digit? */
192 1.1 jtc {
193 1.1 jtc FLUSHLF;
194 1.1 jtc #ifdef VERBOSE
195 1.1 jtc putchar(ch);
196 1.1 jtc #endif
197 1.1 jtc sect=10*sect+ch-'0';
198 1.1 jtc }
199 1.1 jtc #ifdef VERBOSE
200 1.1 jtc putchar('\n');
201 1.1 jtc #endif
202 1.1 jtc switch(sect)
203 1.1 jtc { case 0: /* finished reading database */
204 1.1 jtc return;
205 1.1 jtc case 1: /* long form descriptions */
206 1.1 jtc rdesc(1);
207 1.1 jtc break;
208 1.1 jtc case 2: /* short form descriptions */
209 1.1 jtc rdesc(2);
210 1.1 jtc break;
211 1.1 jtc case 3: /* travel table */
212 1.1 jtc rtrav(); break;
213 1.1 jtc case 4: /* vocabulary */
214 1.1 jtc rvoc();
215 1.1 jtc break;
216 1.1 jtc case 5: /* object descriptions */
217 1.1 jtc rdesc(5);
218 1.1 jtc break;
219 1.1 jtc case 6: /* arbitrary messages */
220 1.1 jtc rdesc(6);
221 1.1 jtc break;
222 1.1 jtc case 7: /* object locations */
223 1.1 jtc rlocs(); break;
224 1.1 jtc case 8: /* action defaults */
225 1.1 jtc rdflt(); break;
226 1.1 jtc case 9: /* liquid assets */
227 1.1 jtc rliq(); break;
228 1.1 jtc case 10: /* class messages */
229 1.1 jtc rdesc(10);
230 1.1 jtc break;
231 1.1 jtc case 11: /* hints */
232 1.1 jtc rhints(); break;
233 1.1 jtc case 12: /* magic messages */
234 1.1 jtc rdesc(12);
235 1.1 jtc break;
236 1.1 jtc default:
237 1.1 jtc printf("Invalid data section number: %d\n",sect);
238 1.1 jtc for (;;) putchar(next());
239 1.1 jtc }
240 1.1 jtc if (breakch!=LF) /* routines return after "-1" */
241 1.1 jtc FLUSHLF;
242 1.1 jtc }
243 1.1 jtc }
244 1.1 jtc
245 1.1 jtc char nbf[12];
246 1.1 jtc
247 1.1 jtc
248 1.4 christos int
249 1.1 jtc rnum() /* read initial location num */
250 1.1 jtc { register char *s;
251 1.1 jtc tape = iotape; /* restart encryption tape */
252 1.1 jtc for (s=nbf,*s=0;; s++)
253 1.1 jtc if ((*s=next())==TAB || *s=='\n' || *s==LF)
254 1.1 jtc break;
255 1.1 jtc breakch= *s; /* save char for rtrav() */
256 1.1 jtc *s=0; /* got the number as ascii */
257 1.1 jtc if (nbf[0]=='-') return(-1); /* end of data */
258 1.1 jtc return(atoi(nbf)); /* convert it to integer */
259 1.1 jtc }
260 1.1 jtc
261 1.1 jtc char *seekhere;
262 1.1 jtc
263 1.4 christos void
264 1.1 jtc rdesc(sect) /* read description-format msgs */
265 1.1 jtc int sect;
266 1.4 christos { register int locc;
267 1.4 christos char *seekstart, *maystart;
268 1.1 jtc
269 1.1 jtc seekhere = inptr; /* Where are we in virtual file?*/
270 1.1 jtc outsw=1; /* these msgs go into tmp file */
271 1.1 jtc for (oldloc= -1, seekstart=seekhere;;)
272 1.1 jtc { maystart=inptr; /* maybe starting new entry */
273 1.1 jtc if ((locc=rnum())!=oldloc && oldloc>=0 /* finished msg */
274 1.1 jtc && ! (sect==5 && (locc==0 || locc>=100)))/* unless sect 5*/
275 1.1 jtc { switch(sect) /* now put it into right table */
276 1.1 jtc { case 1: /* long descriptions */
277 1.1 jtc ltext[oldloc].seekadr=seekhere;
278 1.1 jtc ltext[oldloc].txtlen=maystart-seekstart;
279 1.1 jtc break;
280 1.1 jtc case 2: /* short descriptions */
281 1.1 jtc stext[oldloc].seekadr=seekhere;
282 1.1 jtc stext[oldloc].txtlen=maystart-seekstart;
283 1.1 jtc break;
284 1.1 jtc case 5: /* object descriptions */
285 1.1 jtc ptext[oldloc].seekadr=seekhere;
286 1.1 jtc ptext[oldloc].txtlen=maystart-seekstart;
287 1.1 jtc break;
288 1.1 jtc case 6: /* random messages */
289 1.1 jtc if (oldloc>RTXSIZ)
290 1.1 jtc { printf("Too many random msgs\n");
291 1.1 jtc exit(0);
292 1.1 jtc }
293 1.1 jtc rtext[oldloc].seekadr=seekhere;
294 1.1 jtc rtext[oldloc].txtlen=maystart-seekstart;
295 1.1 jtc break;
296 1.1 jtc case 10: /* class messages */
297 1.1 jtc ctext[clsses].seekadr=seekhere;
298 1.1 jtc ctext[clsses].txtlen=maystart-seekstart;
299 1.1 jtc cval[clsses++]=oldloc;
300 1.1 jtc break;
301 1.1 jtc case 12: /* magic messages */
302 1.1 jtc if (oldloc>MAGSIZ)
303 1.1 jtc { printf("Too many magic msgs\n");
304 1.1 jtc exit(0);
305 1.1 jtc }
306 1.1 jtc mtext[oldloc].seekadr=seekhere;
307 1.1 jtc mtext[oldloc].txtlen=maystart-seekstart;
308 1.1 jtc break;
309 1.1 jtc default:
310 1.1 jtc printf("rdesc called with bad section\n");
311 1.1 jtc exit(0);
312 1.1 jtc }
313 1.1 jtc seekhere += maystart-seekstart;
314 1.1 jtc }
315 1.1 jtc if (locc<0)
316 1.1 jtc { outsw=0; /* turn off output */
317 1.1 jtc seekhere += 3; /* -1<delimiter> */
318 1.1 jtc return;
319 1.1 jtc }
320 1.1 jtc if (sect!=5 || (locc>0 && locc<100))
321 1.1 jtc { if (oldloc!=locc)/* starting a new message */
322 1.1 jtc seekstart=maystart;
323 1.1 jtc oldloc=locc;
324 1.1 jtc }
325 1.1 jtc FLUSHLF; /* scan the line */
326 1.1 jtc }
327 1.1 jtc }
328 1.1 jtc
329 1.4 christos void
330 1.1 jtc rtrav() /* read travel table */
331 1.1 jtc { register int locc;
332 1.4 christos register struct travlist *t = NULL;
333 1.1 jtc register char *s;
334 1.1 jtc char buf[12];
335 1.4 christos int len,m,n,entries = 0;
336 1.4 christos
337 1.1 jtc for (oldloc= -1;;) /* get another line */
338 1.1 jtc { if ((locc=rnum())!=oldloc && oldloc>=0) /* end of entry */
339 1.1 jtc {
340 1.1 jtc t->next = 0; /* terminate the old entry */
341 1.1 jtc /* printf("%d:%d entries\n",oldloc,entries); */
342 1.1 jtc /* twrite(oldloc); */
343 1.1 jtc }
344 1.1 jtc if (locc== -1) return;
345 1.1 jtc if (locc!=oldloc) /* getting a new entry */
346 1.1 jtc { t=travel[locc]=(struct travlist *) malloc(sizeof (struct travlist));
347 1.1 jtc /* printf("New travel list for %d\n",locc); */
348 1.1 jtc entries=0;
349 1.1 jtc oldloc=locc;
350 1.1 jtc }
351 1.4 christos for (s=buf;; s++) /* get the newloc number /ASCII */
352 1.1 jtc if ((*s=next())==TAB || *s==LF) break;
353 1.1 jtc *s=0;
354 1.1 jtc len=length(buf)-1; /* quad long number handling */
355 1.1 jtc /* printf("Newloc: %s (%d chars)\n",buf,len); */
356 1.1 jtc if (len<4) /* no "m" conditions */
357 1.1 jtc { m=0;
358 1.1 jtc n=atoi(buf); /* newloc mod 1000 = newloc */
359 1.1 jtc }
360 1.1 jtc else /* a long integer */
361 1.1 jtc { n=atoi(buf+len-3);
362 1.1 jtc buf[len-3]=0; /* terminate newloc/1000 */
363 1.1 jtc m=atoi(buf);
364 1.1 jtc }
365 1.1 jtc while (breakch!=LF) /* only do one line at a time */
366 1.1 jtc { if (entries++) t=t->next=(struct travlist *) malloc(sizeof (struct travlist));
367 1.1 jtc t->tverb=rnum();/* get verb from the file */
368 1.1 jtc t->tloc=n; /* table entry mod 1000 */
369 1.1 jtc t->conditions=m;/* table entry / 1000 */
370 1.1 jtc /* printf("entry %d for %d\n",entries,locc); */
371 1.1 jtc }
372 1.1 jtc }
373 1.1 jtc }
374 1.1 jtc
375 1.1 jtc #ifdef DEBUG
376 1.1 jtc
377 1.4 christos void
378 1.1 jtc twrite(loq) /* travel options from this loc */
379 1.1 jtc int loq;
380 1.1 jtc { register struct travlist *t;
381 1.1 jtc printf("If");
382 1.1 jtc speak(<ext[loq]);
383 1.1 jtc printf("then\n");
384 1.1 jtc for (t=travel[loq]; t!=0; t=t->next)
385 1.1 jtc { printf("verb %d takes you to ",t->tverb);
386 1.1 jtc if (t->tloc<=300)
387 1.1 jtc speak(<ext[t->tloc]);
388 1.1 jtc else if (t->tloc<=500)
389 1.1 jtc printf("special code %d\n",t->tloc-300);
390 1.1 jtc else
391 1.1 jtc rspeak(t->tloc-500);
392 1.1 jtc printf("under conditions %d\n",t->conditions);
393 1.1 jtc }
394 1.1 jtc }
395 1.1 jtc
396 1.4 christos #endif /* DEBUG */
397 1.1 jtc
398 1.4 christos void
399 1.1 jtc rvoc()
400 1.1 jtc { register char *s; /* read the vocabulary */
401 1.1 jtc register int index;
402 1.1 jtc char buf[6];
403 1.1 jtc for (;;)
404 1.1 jtc { index=rnum();
405 1.1 jtc if (index<0) break;
406 1.1 jtc for (s=buf,*s=0;; s++) /* get the word */
407 1.1 jtc if ((*s=next())==TAB || *s=='\n' || *s==LF
408 1.1 jtc || *s==' ') break;
409 1.1 jtc /* terminate word with newline, LF, tab, blank */
410 1.1 jtc if (*s!='\n' && *s!=LF) FLUSHLF; /* can be comments */
411 1.1 jtc *s=0;
412 1.1 jtc /* printf("\"%s\"=%d\n",buf,index);*/
413 1.1 jtc vocab(buf,-2,index);
414 1.1 jtc }
415 1.1 jtc /* prht(); */
416 1.1 jtc }
417 1.1 jtc
418 1.1 jtc
419 1.4 christos void
420 1.1 jtc rlocs() /* initial object locations */
421 1.1 jtc { for (;;)
422 1.1 jtc { if ((obj=rnum())<0) break;
423 1.1 jtc plac[obj]=rnum(); /* initial loc for this obj */
424 1.1 jtc if (breakch==TAB) /* there's another entry */
425 1.1 jtc fixd[obj]=rnum();
426 1.1 jtc else fixd[obj]=0;
427 1.1 jtc }
428 1.1 jtc }
429 1.1 jtc
430 1.4 christos void
431 1.1 jtc rdflt() /* default verb messages */
432 1.1 jtc { for (;;)
433 1.1 jtc { if ((verb=rnum())<0) break;
434 1.1 jtc actspk[verb]=rnum();
435 1.1 jtc }
436 1.1 jtc }
437 1.1 jtc
438 1.4 christos void
439 1.1 jtc rliq() /* liquid assets &c: cond bits */
440 1.1 jtc { register int bitnum;
441 1.1 jtc for (;;) /* read new bit list */
442 1.1 jtc { if ((bitnum=rnum())<0) break;
443 1.1 jtc for (;;) /* read locs for bits */
444 1.1 jtc { cond[rnum()] |= setbit[bitnum];
445 1.1 jtc if (breakch==LF) break;
446 1.1 jtc }
447 1.1 jtc }
448 1.1 jtc }
449 1.1 jtc
450 1.4 christos void
451 1.1 jtc rhints()
452 1.1 jtc { register int hintnum,i;
453 1.1 jtc hntmax=0;
454 1.1 jtc for (;;)
455 1.1 jtc { if ((hintnum=rnum())<0) break;
456 1.1 jtc for (i=1; i<5; i++)
457 1.1 jtc hints[hintnum][i]=rnum();
458 1.1 jtc if (hintnum>hntmax) hntmax=hintnum;
459 1.1 jtc }
460 1.1 jtc }
461 1.1 jtc
462 1.1 jtc
463 1.4 christos void
464 1.1 jtc rspeak(msg)
465 1.1 jtc int msg;
466 1.1 jtc { if (msg!=0) speak(&rtext[msg]);
467 1.1 jtc }
468 1.1 jtc
469 1.1 jtc
470 1.4 christos void
471 1.1 jtc mspeak(msg)
472 1.1 jtc int msg;
473 1.1 jtc { if (msg!=0) speak(&mtext[msg]);
474 1.1 jtc }
475 1.1 jtc
476 1.1 jtc
477 1.4 christos void
478 1.1 jtc speak(msg) /* read, decrypt, and print a message (not ptext) */
479 1.1 jtc struct text *msg;/* msg is a pointer to seek address and length of mess */
480 1.1 jtc {
481 1.1 jtc register char *s, nonfirst;
482 1.1 jtc
483 1.1 jtc s = msg->seekadr;
484 1.1 jtc nonfirst=0;
485 1.1 jtc while (s - msg->seekadr < msg->txtlen) /* read a line at a time */
486 1.1 jtc { tape=iotape; /* restart decryption tape */
487 1.1 jtc while ((*s++ ^ *tape++) != TAB); /* read past loc num */
488 1.1 jtc /* assume tape is longer than location number */
489 1.1 jtc /* plus the lookahead put together */
490 1.1 jtc if ((*s ^ *tape) == '>' &&
491 1.1 jtc (*(s+1) ^ *(tape+1)) == '$' &&
492 1.1 jtc (*(s+2) ^ *(tape+2)) == '<') break;
493 1.1 jtc if (blklin && !nonfirst++) putchar('\n');
494 1.1 jtc do
495 1.1 jtc { if (*tape == 0) tape = iotape;/* rewind decryp tape */
496 1.1 jtc putchar(*s ^ *tape);
497 1.1 jtc } while ((*s++ ^ *tape++) != LF); /* better end with LF */
498 1.1 jtc }
499 1.1 jtc }
500 1.1 jtc
501 1.1 jtc
502 1.4 christos void
503 1.1 jtc pspeak(m,skip) /* read, decrypt an print a ptext message */
504 1.1 jtc int m; /* msg is the number of all the p msgs for this place */
505 1.1 jtc int skip; /* assumes object 1 doesn't have prop 1, obj 2 no prop 2 &c*/
506 1.1 jtc {
507 1.1 jtc register char *s,nonfirst;
508 1.1 jtc char *numst, save;
509 1.1 jtc struct text *msg;
510 1.1 jtc char *tbuf;
511 1.1 jtc
512 1.1 jtc msg = &ptext[m];
513 1.1 jtc if ((tbuf=(char *) malloc(msg->txtlen + 1)) == 0) bug(108);
514 1.1 jtc memcpy(tbuf, msg->seekadr, msg->txtlen + 1); /* Room to null */
515 1.1 jtc s = tbuf;
516 1.1 jtc
517 1.1 jtc nonfirst=0;
518 1.1 jtc while (s - tbuf < msg->txtlen) /* read line at a time */
519 1.1 jtc { tape=iotape; /* restart decryption tape */
520 1.1 jtc for (numst=s; (*s^= *tape++)!=TAB; s++); /* get number */
521 1.1 jtc
522 1.1 jtc save = *s; /* Temporarily trash the string (cringe) */
523 1.1 jtc *s++ = 0; /* decrypting number within the string */
524 1.1 jtc
525 1.1 jtc if (atoi(numst) != 100 * skip && skip >= 0)
526 1.1 jtc { while ((*s++^*tape++)!=LF) /* flush the line */
527 1.1 jtc if (*tape==0) tape=iotape;
528 1.1 jtc continue;
529 1.1 jtc }
530 1.1 jtc if ((*s^*tape)=='>' && (*(s+1)^*(tape+1))=='$' &&
531 1.1 jtc (*(s+2)^*(tape+2))=='<') break;
532 1.1 jtc if (blklin && ! nonfirst++) putchar('\n');
533 1.1 jtc do
534 1.1 jtc { if (*tape==0) tape=iotape;
535 1.1 jtc putchar(*s^*tape);
536 1.1 jtc } while ((*s++^*tape++)!=LF); /* better end with LF */
537 1.1 jtc if (skip<0) break;
538 1.1 jtc }
539 1.1 jtc free(tbuf);
540 1.1 jtc }
541