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

unix.superglobalmegacorp.com

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