Annotation of 43BSD/usr.lib/sendmail/src/stab.c, revision 1.1

1.1     ! root        1: /*
        !             2: **  Sendmail
        !             3: **  Copyright (c) 1983  Eric P. Allman
        !             4: **  Berkeley, California
        !             5: **
        !             6: **  Copyright (c) 1983 Regents of the University of California.
        !             7: **  All rights reserved.  The Berkeley software License Agreement
        !             8: **  specifies the terms and conditions for redistribution.
        !             9: */
        !            10: 
        !            11: #ifndef lint
        !            12: static char    SccsId[] = "@(#)stab.c  5.2 (Berkeley) 6/7/85";
        !            13: #endif not lint
        !            14: 
        !            15: # include "sendmail.h"
        !            16: 
        !            17: /*
        !            18: **  STAB -- manage the symbol table
        !            19: **
        !            20: **     Parameters:
        !            21: **             name -- the name to be looked up or inserted.
        !            22: **             type -- the type of symbol.
        !            23: **             op -- what to do:
        !            24: **                     ST_ENTER -- enter the name if not
        !            25: **                             already present.
        !            26: **                     ST_FIND -- find it only.
        !            27: **
        !            28: **     Returns:
        !            29: **             pointer to a STAB entry for this name.
        !            30: **             NULL if not found and not entered.
        !            31: **
        !            32: **     Side Effects:
        !            33: **             can update the symbol table.
        !            34: */
        !            35: 
        !            36: # define STABSIZE      400
        !            37: 
        !            38: static STAB    *SymTab[STABSIZE];
        !            39: 
        !            40: STAB *
        !            41: stab(name, type, op)
        !            42:        char *name;
        !            43:        int type;
        !            44:        int op;
        !            45: {
        !            46:        register STAB *s;
        !            47:        register STAB **ps;
        !            48:        extern bool sameword();
        !            49:        register int hfunc;
        !            50:        register char *p;
        !            51:        extern char lower();
        !            52: 
        !            53: # ifdef DEBUG
        !            54:        if (tTd(36, 5))
        !            55:                printf("STAB: %s %d ", name, type);
        !            56: # endif DEBUG
        !            57: 
        !            58:        /*
        !            59:        **  Compute the hashing function
        !            60:        **
        !            61:        **      We could probably do better....
        !            62:        */
        !            63: 
        !            64:        hfunc = type;
        !            65:        for (p = name; *p != '\0'; p++)
        !            66:                hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE;
        !            67: 
        !            68: # ifdef DEBUG
        !            69:        if (tTd(36, 9))
        !            70:                printf("(hfunc=%d) ", hfunc);
        !            71: # endif DEBUG
        !            72: 
        !            73:        ps = &SymTab[hfunc];
        !            74:        while ((s = *ps) != NULL && (!sameword(name, s->s_name) || s->s_type != type))
        !            75:                ps = &s->s_next;
        !            76: 
        !            77:        /*
        !            78:        **  Dispose of the entry.
        !            79:        */
        !            80: 
        !            81:        if (s != NULL || op == ST_FIND)
        !            82:        {
        !            83: # ifdef DEBUG
        !            84:                if (tTd(36, 5))
        !            85:                {
        !            86:                        if (s == NULL)
        !            87:                                printf("not found\n");
        !            88:                        else
        !            89:                        {
        !            90:                                long *lp = (long *) s->s_class;
        !            91: 
        !            92:                                printf("type %d val %lx %lx %lx %lx\n",
        !            93:                                        s->s_type, lp[0], lp[1], lp[2], lp[3]);
        !            94:                        }
        !            95:                }
        !            96: # endif DEBUG
        !            97:                return (s);
        !            98:        }
        !            99: 
        !           100:        /*
        !           101:        **  Make a new entry and link it in.
        !           102:        */
        !           103: 
        !           104: # ifdef DEBUG
        !           105:        if (tTd(36, 5))
        !           106:                printf("entered\n");
        !           107: # endif DEBUG
        !           108: 
        !           109:        /* make new entry */
        !           110:        s = (STAB *) xalloc(sizeof *s);
        !           111:        bzero((char *) s, sizeof *s);
        !           112:        s->s_name = newstr(name);
        !           113:        makelower(s->s_name);
        !           114:        s->s_type = type;
        !           115: 
        !           116:        /* link it in */
        !           117:        *ps = s;
        !           118: 
        !           119:        return (s);
        !           120: }

unix.superglobalmegacorp.com

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