Annotation of 43BSDReno/games/battlestar/parse.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: static char sccsid[] = "@(#)parse.c    5.3 (Berkeley) 6/1/90";
                     22: #endif /* not lint */
                     23: 
                     24: #include "externs.h"
                     25: 
                     26: wordinit()
                     27: {
                     28:        register struct wlist *w;
                     29: 
                     30:        for (w = wlist; w->string; w++)
                     31:                install(w);
                     32: }
                     33: 
                     34: hash(s)
                     35:        register char *s;
                     36: {
                     37:        register hashval = 0;
                     38: 
                     39:        while (*s) {
                     40:                hashval += *s++;
                     41:                hashval *= HASHMUL;
                     42:                hashval &= HASHMASK;
                     43:        }
                     44:        return hashval;
                     45: }
                     46: 
                     47: struct wlist *
                     48: lookup(s)
                     49:        char *s;
                     50: {
                     51:        register struct wlist *wp;
                     52: 
                     53:        for (wp = hashtab[hash(s)]; wp != NULL; wp = wp->next)
                     54:                if (*s == *wp->string && strcmp(s, wp->string) == 0)
                     55:                        return wp;
                     56:        return NULL;
                     57: }
                     58: 
                     59: install(wp)
                     60:        register struct wlist *wp;
                     61: {
                     62:        int hashval;
                     63: 
                     64:        if (lookup(wp->string) == NULL) {
                     65:                hashval = hash(wp->string);
                     66:                wp->next = hashtab[hashval];
                     67:                hashtab[hashval] = wp;
                     68:        } else
                     69:                printf("Multiply defined %s.\n", wp->string);
                     70: }
                     71: 
                     72: parse()
                     73: {
                     74:        register struct wlist *wp;
                     75:        register n;
                     76: 
                     77:        wordnumber = 0;           /* for cypher */
                     78:        for (n = 0; n <= wordcount; n++) {
                     79:                if ((wp = lookup(words[n])) == NULL) {
                     80:                        wordvalue[n] = -1;
                     81:                        wordtype[n] = -1;
                     82:                } else {
                     83:                        wordvalue[n] = wp -> value;
                     84:                        wordtype[n] = wp -> article;
                     85:                }
                     86:        }
                     87: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.