Annotation of 43BSD/games/battlestar/parse.c, revision 1.1

1.1     ! root        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: 
        !             7: #ifndef lint
        !             8: static char sccsid[] = "@(#)parse.c    1.2 4/24/85";
        !             9: #endif
        !            10: 
        !            11: #include "externs.h"
        !            12: 
        !            13: wordinit()
        !            14: {
        !            15:        register struct wlist *w;
        !            16: 
        !            17:        for (w = wlist; w->string; w++)
        !            18:                install(w);
        !            19: }
        !            20: 
        !            21: hash(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: 
        !            34: struct wlist *
        !            35: lookup(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: 
        !            46: install(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: 
        !            59: parse()
        !            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: }

unix.superglobalmegacorp.com

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