1: /*
   2:  * Copyright (c) 1989, 1993
   3:  *	The Regents of the University of California.  All rights reserved.
   4:  *
   5:  * This code is derived from software contributed to Berkeley by
   6:  * Ozan Yigit at York University.
   7:  *
   8:  * Redistribution and use in source and binary forms, with or without
   9:  * modification, are permitted provided that the following conditions
  10:  * are met:
  11:  * 1. Redistributions of source code must retain the above copyright
  12:  *    notice, this list of conditions and the following disclaimer.
  13:  * 2. Redistributions in binary form must reproduce the above copyright
  14:  *    notice, this list of conditions and the following disclaimer in the
  15:  *    documentation and/or other materials provided with the distribution.
  16:  * 3. All advertising materials mentioning features or use of this software
  17:  *    must display the following acknowledgement:
  18:  *	This product includes software developed by the University of
  19:  *	California, Berkeley and its contributors.
  20:  * 4. Neither the name of the University nor the names of its contributors
  21:  *    may be used to endorse or promote products derived from this software
  22:  *    without specific prior written permission.
  23:  *
  24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34:  * SUCH DAMAGE.
  35:  */
  36: 
  37: #if !defined(lint) && defined(DOSCCS)
  38: static char sccsid[] = "@(#)look.c	8.1 (Berkeley) 6/6/93";
  39: #endif
  40: 
  41: /*
  42:  * look.c
  43:  * Facility: m4 macro processor
  44:  * by: oz
  45:  */
  46: 
  47: #include <sys/types.h>
  48: #include <stdio.h>
  49: #include <string.h>
  50: #include "mdef.h"
  51: #include "stdd.h"
  52: #include "extern.h"
  53: 
  54: int
  55: hash(name)
  56: register char *name;
  57: {
  58:     register unsigned long h = 0;
  59:     while (*name)
  60:         h = (h << 5) + h + *name++;
  61:     return (h % HASHSIZE);
  62: }
  63: 
  64: /*
  65:  * find name in the hash table
  66:  */
  67: ndptr
  68: lookup(name)
  69: char *name;
  70: {
  71:     register ndptr p;
  72: 
  73:     for (p = hashtab[hash(name)]; p != nil; p = p->nxtptr)
  74:         if (STREQ(name, p->name))
  75:             break;
  76:     return (p);
  77: }
  78: 
  79: /*
  80:  * hash and create an entry in the hash table.
  81:  * The new entry is added in front of a hash bucket.
  82:  */
  83: ndptr
  84: addent(name)
  85: char *name;
  86: {
  87:     register int h;
  88:     ndptr p;
  89: 
  90:     h = hash(name);
  91:     p = (ndptr) xalloc(sizeof(struct ndblock));
  92:     p->nxtptr = hashtab[h];
  93:     hashtab[h] = p;
  94:     p->name = xstrdup(name);
  95:     return p;
  96: }
  97: 
  98: static void
  99: freent(p)
 100: ndptr p;
 101: {
 102:     if (!(p->type & STATIC)) {
 103:         free((char *) p->name);
 104:         if (p->defn != null)
 105:             free((char *) p->defn);
 106:     }
 107:     free((char *) p);
 108: }
 109: 
 110: /*
 111:  * remove an entry from the hashtable
 112:  */
 113: void
 114: remhash(name, all)
 115: char *name;
 116: int all;
 117: {
 118:     register int h;
 119:     register ndptr xp, tp, mp;
 120: 
 121:     h = hash(name);
 122:     mp = hashtab[h];
 123:     tp = nil;
 124:     while (mp != nil) {
 125:         if (STREQ(mp->name, name)) {
 126:             mp = mp->nxtptr;
 127:             if (tp == nil) {
 128:                 freent(hashtab[h]);
 129:                 hashtab[h] = mp;
 130:             }
 131:             else {
 132:                 xp = tp->nxtptr;
 133:                 tp->nxtptr = mp;
 134:                 freent(xp);
 135:             }
 136:             if (!all)
 137:                 break;
 138:         }
 139:         else {
 140:             tp = mp;
 141:             mp = mp->nxtptr;
 142:         }
 143:     }
 144: }

Defined functions

addent defined in line 83; used 2 times
freent defined in line 98; used 2 times
hash defined in line 54; used 3 times
lookup defined in line 67; used 4 times
remhash defined in line 113; never used

Defined variables

sccsid defined in line 38; never used
Last modified: 1994-04-06
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2837
Valid CSS Valid XHTML 1.0 Strict