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