date and time created 92/08/27 11:43:00 by bostic
[unix-history] / usr / src / games / battlestar / parse.c
CommitLineData
fdc7d56f 1/*
e95fc82a
KB
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
a6547b1d 5 * %sccs.include.redist.c%
fdc7d56f
EW
6 */
7
4560ad02 8#ifndef lint
a6547b1d 9static char sccsid[] = "@(#)parse.c 5.3 (Berkeley) %G%";
e95fc82a 10#endif /* not lint */
4560ad02
EW
11
12#include "externs.h"
13
14wordinit()
15{
16 register struct wlist *w;
17
18 for (w = wlist; w->string; w++)
19 install(w);
20}
21
22hash(s)
23 register char *s;
24{
25 register hashval = 0;
26
27 while (*s) {
28 hashval += *s++;
29 hashval *= HASHMUL;
30 hashval &= HASHMASK;
31 }
32 return hashval;
33}
34
35struct wlist *
36lookup(s)
37 char *s;
38{
39 register struct wlist *wp;
40
41 for (wp = hashtab[hash(s)]; wp != NULL; wp = wp->next)
42 if (*s == *wp->string && strcmp(s, wp->string) == 0)
43 return wp;
44 return NULL;
45}
46
47install(wp)
48 register struct wlist *wp;
49{
50 int hashval;
51
52 if (lookup(wp->string) == NULL) {
53 hashval = hash(wp->string);
54 wp->next = hashtab[hashval];
55 hashtab[hashval] = wp;
56 } else
57 printf("Multiply defined %s.\n", wp->string);
58}
59
60parse()
61{
62 register struct wlist *wp;
63 register n;
64
65 wordnumber = 0; /* for cypher */
66 for (n = 0; n <= wordcount; n++) {
67 if ((wp = lookup(words[n])) == NULL) {
68 wordvalue[n] = -1;
69 wordtype[n] = -1;
70 } else {
71 wordvalue[n] = wp -> value;
72 wordtype[n] = wp -> article;
73 }
74 }
75}