home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / pi1 / lookup.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  2KB  |  116 lines

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