home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / pascal / src / lookup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-16  |  3.8 KB  |  149 lines

  1. /*-
  2.  * Copyright (c) 1980 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. static char sccsid[] = "@(#)lookup.c    5.2 (Berkeley) 4/16/91";
  36. #endif /* not lint */
  37.  
  38. #include "whoami.h"
  39. #include "0.h"
  40.  
  41. struct nl *disptab[077+1];
  42.  
  43. /*
  44.  * Lookup is called to
  45.  * find a symbol in the
  46.  * block structure symbol
  47.  * table and returns a pointer to
  48.  * its namelist entry.
  49.  */
  50. struct nl *
  51. lookup(s)
  52.     register char *s;
  53. {
  54.     register struct nl *p;
  55.     register struct udinfo;
  56.  
  57.     if (s == NIL) {
  58.         nocascade();
  59.         return (NLNIL);
  60.     }
  61.     p = lookup1(s);
  62.     if (p == NLNIL) {
  63.         derror("%s is undefined", s);
  64.         return (NLNIL);
  65.     }
  66.     if (p->class == FVAR) {
  67.         p = p->chain;
  68.         bn--;
  69.     }
  70.     return (p);
  71. }
  72.  
  73. #ifndef PI0
  74. int    flagwas;
  75. #endif
  76. /*
  77.  * Lookup1 is an internal lookup.
  78.  * It is not an error to call lookup1
  79.  * if the symbol is not defined.  Also
  80.  * lookup1 will return FVARs while
  81.  * lookup never will, thus asgnop
  82.  * calls it when it thinks you are
  83.  * assigning to the function variable.
  84.  */
  85.  
  86. struct nl *
  87. lookup1(s)
  88.     register char *s;
  89. {
  90.     register struct nl *p;
  91. #ifndef PI0
  92.     register struct nl *q;
  93. #endif
  94.     register int i;
  95.  
  96.     if (s == NIL)
  97.         return (NLNIL);
  98.     bn = cbn;
  99. #ifndef PI0
  100.     /*
  101.      * We first check the field names
  102.      * of the currently active with
  103.      * statements (expensive since they
  104.      * are not hashed).
  105.      */
  106.     for (p = withlist; p != NLNIL; p = p->nl_next) {
  107.         q = p->type;
  108.         if (q == NLNIL)
  109.             continue;
  110.         if (reclook(q, s) != NIL)
  111.             /*
  112.              * Return the WITHPTR, lvalue understands.
  113.              */
  114.             return (p);
  115.     }
  116. #endif
  117.     /*
  118.      * Symbol table is a 64 way hash
  119.      * on the low bits of the character
  120.      * pointer value. (Simple, but effective)
  121.      */
  122.     i = (int) s & 077;
  123.     for (p = disptab[i]; p != NLNIL; p = p->nl_next)
  124.         if (p->symbol == s && p->class != FIELD && p->class != BADUSE) {
  125.             bn = (p->nl_block & 037);
  126. #ifndef PI0
  127.             flagwas = p->nl_flags;
  128.             p->nl_flags |= NUSED;
  129. #endif
  130.             return (p);
  131.         }
  132.     return (NLNIL);
  133. }
  134.  
  135. #ifndef PI01
  136. nlfund(sp)
  137.     char *sp;
  138. {
  139.     register struct nl *p;
  140.     register int i;
  141.  
  142.     i = (int) sp & 077;
  143.     for (p = disptab[i]; p != NLNIL; p = p->nl_next)
  144.     if (p->symbol == sp && (p->nl_block & 037) == 0)
  145.         return (nloff(p));
  146.     return (0);
  147. }
  148. #endif
  149.