1 /* @(#)vocab.c 8.1 (Berkeley) 5/31/93 */
2 /* $NetBSD: vocab.c,v 1.15 2009/08/25 06:56:52 dholland Exp $ */
5 * Copyright (c) 1991, 1993
6 * The Regents of the University of California. All rights reserved.
8 * The game adventure was originally written in Fortran by Will Crowther
9 * and Don Woods. It was later translated to C and enhanced by Jim
10 * Gillogly. This code is derived from software contributed to Berkeley
11 * by Jim Gillogly at The Rand Corporation.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 /* Re-coding of advent in C: data structure routines */
60 move(object + 100, j);
64 move(int object, int where)
71 from = fixed[object - 100];
72 if (from > 0 && from <= 300)
78 put(int object, int where, int pval)
85 carry(int object, int where)
90 if (place[object] == -1)
95 if (atloc[where] == object) {
96 atloc[where] = links[object];
99 for (temp = atloc[where]; links[temp] != object; temp = links[temp]);
100 links[temp] = links[object];
105 drop(int object, int where)
108 fixed[object - 100] = where;
110 if (place[object] == -1)
112 place[object] = where;
116 links[object] = atloc[where];
117 atloc[where] = object;
120 /* look up or store a word */
121 /* -2 for store, -1 for user word, >=0 for canned lookup */
122 /* used for storing only */
124 vocab(const char *word, int type, int value)
132 for (hash = 0, s = word, i = 0; i < 5 && *s; i++) /* some kind of hash*/
133 hash += *s++; /* add all chars in the word */
134 hash = (hash * 3719) & 077777; /* pulled that one out of a hat */
135 hash %= HTSIZE; /* put it into range of table */
137 for (adr = hash;; adr++) { /* look for entry in table */
139 adr = 0;/* wrap around */
140 h = &voc[adr]; /* point at the entry */
142 case -2: /* fill in entry */
143 if (h->val) /* already got an entry? */
146 h->atab = malloc(length(word));
149 for (s = word, t = h->atab; *s;)
152 /* encrypt slightly to thwart core reader */
153 /* printf("Stored \"%s\" (%d ch) as entry %d\n", */
154 /* word, length(word), adr); */
155 return (0); /* entry unused */
156 case -1: /* looking up user word */
158 return (-1); /* not found */
159 for (s = word, t = h->atab; *t ^ '=';)
160 if ((*s++ ^ '=') != *t++)
162 if ((*s ^ '=') != *t && s - word < 5)
164 /* the word matched o.k. */
166 default: /* looking up known word */
168 errx(1,"Unable to find %s in vocab", word);
169 for (s = word, t = h->atab; *t ^ '=';)
170 if ((*s++ ^ '=') != *t++)
172 /* the word matched o.k. */
173 if (h->val / 1000 != type)
175 return (h->val % 1000);
178 exitloop2: /* hashed entry does not match */
179 if (adr + 1 == hash || hash == 0)
180 errx(1,"Hash table overflow");
184 /* print hash table (for debugging) */
191 for (i = 0; i < HTSIZE / 10 + 1; i++) {
192 printf("%4d", i * 10);
193 for (j = 0; j < 10; j++) {
194 if (i * 10 + j >= HTSIZE)
196 h = &voc[i * 10 + j];
202 for (l = 0, c = h->atab; l < 5; l++)