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