8000 minix/games/adventure/io.c at master · gotoweb/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
610 lines (567 loc) · 15 KB

io.c

File metadata and controls

610 lines (567 loc) · 15 KB
t = travel[locc] = calloc(1, sizeof(*t));
if (t == NULL)
err(1, NULL);
/* printf("New travel list for %d\n",locc); */
entries = 0;
oldloc = locc;
}
for (s = buf;; s++) /* get the newloc number /ASCII */
if ((*s = next()) == TAB || *s == LF)
break;
*s = 0;
len = length(buf) - 1; /* quad long number handling */
/* printf("Newloc: %s (%d chars)\n",buf,len); */
if (len < 4) { /* no "m" conditions */
m = 0;
n = atoi(buf); /* newloc mod 1000 = newloc */
} else { /* a long integer */
n = atoi(buf + len - 3);
buf[len - 3] = 0; /* terminate newloc/1000 */
m = atoi(buf);
}
while (breakch != LF) { /* only do one line at a time */
if (t == NULL)
abort();
if (entries++) {
t->next = calloc(1, sizeof(*t));
if (t->next == NULL)
err(1, NULL);
t = t->next;
}
t->tverb = rnum(); /* get verb from the file */
t->tloc = n; /* table entry mod 1000 */
t->conditions = m; /* table entry / 1000 */
/* printf("entry %d for %d\n",entries,locc); */
}
}
}
#ifdef DEBUG
/* travel options from this loc */
void
twrite(int loq)
{
struct travlist *t;
printf("If");
speak(&ltext[loq]);
printf("then\n");
for (t = travel[loq]; t != 0; t = t->next) {
printf("verb %d takes you to ", t->tverb);
if (t->tloc <= 300)
speak(&ltext[t->tloc]);
else
if (t->tloc <= 500)
printf("special code %d\n", t->tloc - 300);
else
rspeak(t->tloc - 500);
printf("under conditions %d\n", t->conditions);
}
}
#endif /* DEBUG */
/* read the vocabulary */
static void
rvoc(void)
{
char *s;
int idx;
char buf[6];
for (;;) {
idx = rnum();
if (idx < 0)
break;
for (s = buf, *s = 0;; s++) /* get the word */
if ((*s = next()) == TAB || *s == '\n' || *s == LF
|| *s == ' ')
break;
/* terminate word with newline, LF, tab, blank */
if (*s != '\n' && *s != LF)
FLUSHLF;/* can be comments */
*s = 0;
/* printf("\"%s\"=%d\n",buf,idx); */
vocab(buf, -2, idx);
}
/* prht(); */
}
/* initial object locations */
static void
rlocs(void)
{
for (;;) {
if ((obj = rnum()) < 0)
break;
plac[obj] = rnum(); /* initial loc for this obj */
if (breakch == TAB) /* there's another entry */
fixd[obj] = rnum();
else
fixd[obj] = 0;
}
}
/* default verb messages */
static void
rdefault(void)
{
for (;;) {
if ((verb = rnum()) < 0)
break;
actspeak[verb] = rnum();
}
}
/* liquid assets &c: cond bits */
static void
rliq(void)
{
int bitnum;
for (;;) { /* read new bit list */
if ((bitnum = rnum()) < 0)
break;
for (;;) { /* read locs for bits */
int n = rnum();
if (n < 0)
break;
cond[n] |= setbit[bitnum];
if (breakch == LF)
break;
}
}
}
static void
rhints(void)
{
int hintnum, i;
hintmax = 0;
for (;;) {
if ((hintnum = rnum()) < 0)
break;
for (i = 1; i < 5; i++)
hints[hintnum][i] = rnum();
if (hintnum > hintmax)
hintmax = hintnum;
}
}
void
rspeak(int msg)
{
if (msg != 0)
speak(&rtext[msg]);
}
void
mspeak(int msg)
{
if (msg != 0)
speak(&mtext[msg]);
}
/* read, decrypt, and print a message (not ptext) */
/* msg is a pointer to seek address and length of mess */
void
speak(const struct text *msg)
{
char *s, nonfirst;
s = msg->seekadr;
nonfirst = 0;
while (s - msg->seekadr < msg->txtlen) { /* read a line at a time */
tape = iotape; /* restart decryption tape */
while ((*s++ ^ *tape++) != TAB); /* read past loc num */
/* assume tape is longer than location number */
/* plus the lookahead put together */
if ((*s ^ *tape) == '>' &&
(*(s + 1) ^ *(tape + 1)) == '$' &&
(*(s + 2) ^ *(tape + 2)) == '<')
break;
if (blklin && !nonfirst++)
putchar('\n');
do {
if (*tape == 0)
tape = iotape; /* rewind decryp tape */
putchar(*s ^ *tape);
} while ((*s++ ^ *tape++) != LF); /* better end with LF */
}
}
/* read, decrypt and print a ptext message */
/* msg is the number of all the p msgs for this place */
/* assumes object 1 doesn't have prop 1, obj 2 no prop 2 &c */
void
pspeak(int m, int skip)
{
char *s, nonfirst;
char *numst;
struct text *msg;
char *tbuf;
msg = &ptext[m];
if ((tbuf = (char *) malloc(msg->txtlen + 1)) == NULL)
err(1, NULL);
memcpy(tbuf, msg->seekadr, msg->txtlen + 1); /* Room to null */
s = tbuf;
nonfirst = 0;
while (s - tbuf < msg->txtlen) { /* read line at a time */
tape = iotape; /* restart decryption tape */
for (numst = s; (*s ^= *tape++) != TAB; s++); /* get number */
/* Temporarily trash the string (cringe) */
*s++ = 0; /* decrypting number within the string */
if (atoi(numst) != 100 * skip && skip >= 0) {
while ((*s++ ^ *tape++) != LF) /* flush the line */
if (*tape == 0)
tape = iotape;
continue;
}
if ((*s ^ *tape) == '>' && (*(s + 1) ^ *(tape + 1)) == '$' &&
(*(s + 2) ^ *(tape + 2)) == '<')
break;
if (blklin && !nonfirst++)
putchar('\n');
do {
if (*tape == 0)
tape = iotape;
putchar(*s ^ *tape);
} while ((*s++ ^ *tape++) != LF); /* better end with LF */
if (skip < 0)
break;
}
free(tbuf);
}
0