Annotation of 42BSD/usr.bin/ratfor/rlook.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char sccsid[] = "@(#)rlook.c    1.2 (Berkeley) 8/11/83";
        !             3: #endif
        !             4: 
        !             5: #define NULL 0
        !             6: #define EOS 0
        !             7: #define        HSHSIZ  101
        !             8: struct nlist {
        !             9:        char    *name;
        !            10:        char    *def;
        !            11:        int     ydef;
        !            12:        struct  nlist *next;
        !            13: };
        !            14: 
        !            15: struct nlist   *hshtab[HSHSIZ];
        !            16: struct nlist   *lookup();
        !            17: char   *install();
        !            18: char   *malloc();
        !            19: char   *copy();
        !            20: int    hshval;
        !            21: 
        !            22: struct nlist *lookup(str)
        !            23: char *str;
        !            24: {
        !            25:        register char *s1, *s2;
        !            26:        register struct nlist *np;
        !            27:        static struct nlist nodef;
        !            28: 
        !            29:        s1 = str;
        !            30:        for (hshval = 0; *s1; )
        !            31:                hshval += *s1++;
        !            32:        hshval %= HSHSIZ;
        !            33:        for (np = hshtab[hshval]; np!=NULL; np = np->next) {
        !            34:                s1 = str;
        !            35:                s2 = np->name;
        !            36:                while (*s1++ == *s2)
        !            37:                        if (*s2++ == EOS)
        !            38:                                return(np);
        !            39:        }
        !            40:        return(&nodef);
        !            41: }
        !            42: 
        !            43: char *install(nam, val, tran)
        !            44: char *nam, *val;
        !            45: int tran;
        !            46: {
        !            47:        register struct nlist *np;
        !            48: 
        !            49:        if ((np = lookup(nam))->name == NULL) {
        !            50:                np = (struct nlist *)malloc(sizeof(*np));
        !            51:                np->name = copy(nam);
        !            52:                np->def = copy(val);
        !            53:                np->ydef = tran;
        !            54:                np->next = hshtab[hshval];
        !            55:                hshtab[hshval] = np;
        !            56:                return(np->def);
        !            57:        }
        !            58:        free(np->def);
        !            59:        np->def = copy(val);
        !            60:        return(np->def);
        !            61: }
        !            62: 
        !            63: char *copy(s)
        !            64: register char *s;
        !            65: {
        !            66:        register char *p, *s1;
        !            67: 
        !            68:        p = s1 = (char *) malloc((unsigned)strlen(s)+1);
        !            69:        while (*s1++ = *s++);
        !            70:        return(p);
        !            71: }

unix.superglobalmegacorp.com

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