Annotation of 43BSDReno/pgrm/m4/look.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1989 The Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * This code is derived from software contributed to Berkeley by
        !             6:  * Ozan Yigit.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms are permitted
        !             9:  * provided that: (1) source distributions retain this entire copyright
        !            10:  * notice and comment, and (2) distributions including binaries display
        !            11:  * the following acknowledgement:  ``This product includes software
        !            12:  * developed by the University of California, Berkeley and its contributors''
        !            13:  * in the documentation or other materials provided with the distribution
        !            14:  * and in all advertising materials mentioning features or use of this
        !            15:  * software. Neither the name of the University nor the names of its
        !            16:  * contributors may be used to endorse or promote products derived
        !            17:  * from this software without specific prior written permission.
        !            18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            19:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            20:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            21:  */
        !            22: 
        !            23: #ifndef lint
        !            24: static char sccsid[] = "@(#)look.c     5.2 (Berkeley) 6/1/90";
        !            25: #endif /* not lint */
        !            26: 
        !            27: /*
        !            28:  * look.c
        !            29:  * Facility: m4 macro processor
        !            30:  * by: oz
        !            31:  */
        !            32: 
        !            33: #include "mdef.h"
        !            34: #include "extr.h"
        !            35: 
        !            36: extern char *strsave();
        !            37: 
        !            38: /*
        !            39:  *  hash - compute hash value using the proverbial
        !            40:  *        hashing function. Taken from K&R.
        !            41:  */
        !            42: hash (name)
        !            43: register char *name;
        !            44: {
        !            45:        register int h = 0;
        !            46:        while (*name)
        !            47:                h += *name++;
        !            48:        return (h % HASHSIZE);
        !            49: }
        !            50: 
        !            51: /*
        !            52:  * lookup - find name in the hash table
        !            53:  *
        !            54:  */
        !            55: ndptr lookup(name)
        !            56: char *name;
        !            57: {
        !            58:        register ndptr p;
        !            59: 
        !            60:        for (p = hashtab[hash(name)]; p != nil; p = p->nxtptr)
        !            61:                if (strcmp(name, p->name) == 0)
        !            62:                        break;
        !            63:        return (p);
        !            64: }
        !            65: 
        !            66: /*
        !            67:  * addent - hash and create an entry in the hash
        !            68:  *         table. The new entry is added in front
        !            69:  *         of a hash bucket.
        !            70:  */
        !            71: ndptr addent(name)
        !            72: char *name;
        !            73: {
        !            74:        register int h;
        !            75:        ndptr p;
        !            76: 
        !            77:        h = hash(name);
        !            78:        if ((p = (ndptr) malloc(sizeof(struct ndblock))) != NULL) {
        !            79:                p->nxtptr = hashtab[h];
        !            80:                hashtab[h] = p;
        !            81:                p->name = strsave(name);
        !            82:        }
        !            83:        else
        !            84:                error("m4: no more memory.");
        !            85:        return p;
        !            86: }
        !            87: 
        !            88: /*
        !            89:  * remhash - remove an entry from the hashtable
        !            90:  *
        !            91:  */
        !            92: remhash(name, all)
        !            93: char *name;
        !            94: int all;
        !            95: {
        !            96:        register int h;
        !            97:        register ndptr xp, tp, mp;
        !            98: 
        !            99:        h = hash(name);
        !           100:        mp = hashtab[h];
        !           101:        tp = nil;
        !           102:        while (mp != nil) {
        !           103:                if (strcmp(mp->name, name) == 0) {
        !           104:                        mp = mp->nxtptr;
        !           105:                        if (tp == nil) {
        !           106:                                freent(hashtab[h]);
        !           107:                                hashtab[h] = mp;
        !           108:                        }
        !           109:                        else {
        !           110:                                xp = tp->nxtptr;
        !           111:                                tp->nxtptr = mp;
        !           112:                                freent(xp);
        !           113:                        }
        !           114:                        if (!all)
        !           115:                                break;
        !           116:                }
        !           117:                else {
        !           118:                        tp = mp;
        !           119:                        mp = mp->nxtptr;
        !           120:                }
        !           121:        }
        !           122: }
        !           123: 
        !           124: /*
        !           125:  * freent - free a hashtable information block
        !           126:  *
        !           127:  */
        !           128: freent(p)
        !           129: ndptr p;
        !           130: {
        !           131:        if (!(p->type & STATIC)) {
        !           132:                free(p->name);
        !           133:                if (p->defn != null)
        !           134:                        free(p->defn);
        !           135:        }
        !           136:        free(p);
        !           137: }
        !           138: 

unix.superglobalmegacorp.com

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