1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)lookup.c	5.1 (Berkeley) 6/5/85";
   9: #endif not lint
  10: 
  11: #include "whoami.h"
  12: #include "0.h"
  13: 
  14: struct nl *disptab[077+1];
  15: 
  16: /*
  17:  * Lookup is called to
  18:  * find a symbol in the
  19:  * block structure symbol
  20:  * table and returns a pointer to
  21:  * its namelist entry.
  22:  */
  23: struct nl *
  24: lookup(s)
  25:     register char *s;
  26: {
  27:     register struct nl *p;
  28:     register struct udinfo;
  29: 
  30:     if (s == NIL) {
  31:         nocascade();
  32:         return (NLNIL);
  33:     }
  34:     p = lookup1(s);
  35:     if (p == NLNIL) {
  36:         derror("%s is undefined", s);
  37:         return (NLNIL);
  38:     }
  39:     if (p->class == FVAR) {
  40:         p = p->chain;
  41:         bn--;
  42:     }
  43:     return (p);
  44: }
  45: 
  46: #ifndef PI0
  47: int flagwas;
  48: #endif
  49: /*
  50:  * Lookup1 is an internal lookup.
  51:  * It is not an error to call lookup1
  52:  * if the symbol is not defined.  Also
  53:  * lookup1 will return FVARs while
  54:  * lookup never will, thus asgnop
  55:  * calls it when it thinks you are
  56:  * assigning to the function variable.
  57:  */
  58: 
  59: struct nl *
  60: lookup1(s)
  61:     register char *s;
  62: {
  63:     register struct nl *p;
  64: #ifndef PI0
  65:     register struct nl *q;
  66: #endif
  67:     register int i;
  68: 
  69:     if (s == NIL)
  70:         return (NLNIL);
  71:     bn = cbn;
  72: #ifndef PI0
  73:     /*
  74: 	 * We first check the field names
  75: 	 * of the currently active with
  76: 	 * statements (expensive since they
  77: 	 * are not hashed).
  78: 	 */
  79:     for (p = withlist; p != NLNIL; p = p->nl_next) {
  80:         q = p->type;
  81:         if (q == NLNIL)
  82:             continue;
  83:         if (reclook(q, s) != NIL)
  84:             /*
  85: 			 * Return the WITHPTR, lvalue understands.
  86: 			 */
  87:             return (p);
  88:     }
  89: #endif
  90:     /*
  91: 	 * Symbol table is a 64 way hash
  92: 	 * on the low bits of the character
  93: 	 * pointer value. (Simple, but effective)
  94: 	 */
  95:     i = (int) s & 077;
  96:     for (p = disptab[i]; p != NLNIL; p = p->nl_next)
  97:         if (p->symbol == s && p->class != FIELD && p->class != BADUSE) {
  98:             bn = (p->nl_block & 037);
  99: #ifndef PI0
 100:             flagwas = p->nl_flags;
 101:             p->nl_flags |= NUSED;
 102: #endif
 103:             return (p);
 104:         }
 105:     return (NLNIL);
 106: }
 107: 
 108: #ifndef PI01
 109: nlfund(sp)
 110:     char *sp;
 111: {
 112:     register struct nl *p;
 113:     register int i;
 114: 
 115:     i = (int) sp & 077;
 116:     for (p = disptab[i]; p != NLNIL; p = p->nl_next)
 117:     if (p->symbol == sp && (p->nl_block & 037) == 0)
 118:         return (nloff(p));
 119:     return (0);
 120: }
 121: #endif

Defined functions

nlfund defined in line 109; used 1 times

Defined variables

flagwas defined in line 47; used 3 times
sccsid defined in line 8; never used
Last modified: 1985-06-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2370
Valid CSS Valid XHTML 1.0 Strict