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