Annotation of 3BSD/cmd/pi/lookup.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.