home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.sbin / sendmail / src / stab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-20  |  3.5 KB  |  136 lines

  1. /*
  2.  * Copyright (c) 1983 Eric P. Allman
  3.  * Copyright (c) 1988 Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer.
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in the
  13.  *    documentation and/or other materials provided with the distribution.
  14.  * 3. All advertising materials mentioning features or use of this software
  15.  *    must display the following acknowledgement:
  16.  *    This product includes software developed by the University of
  17.  *    California, Berkeley and its contributors.
  18.  * 4. Neither the name of the University nor the names of its contributors
  19.  *    may be used to endorse or promote products derived from this software
  20.  *    without specific prior written permission.
  21.  *
  22.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32.  * SUCH DAMAGE.
  33.  */
  34.  
  35. #ifndef lint
  36. static char sccsid[] = "@(#)stab.c    5.7 (Berkeley) 6/1/90";
  37. #endif /* not lint */
  38.  
  39. # include "sendmail.h"
  40.  
  41. /*
  42. **  STAB -- manage the symbol table
  43. **
  44. **    Parameters:
  45. **        name -- the name to be looked up or inserted.
  46. **        type -- the type of symbol.
  47. **        op -- what to do:
  48. **            ST_ENTER -- enter the name if not
  49. **                already present.
  50. **            ST_FIND -- find it only.
  51. **
  52. **    Returns:
  53. **        pointer to a STAB entry for this name.
  54. **        NULL if not found and not entered.
  55. **
  56. **    Side Effects:
  57. **        can update the symbol table.
  58. */
  59.  
  60. # define STABSIZE    400
  61.  
  62. static STAB    *SymTab[STABSIZE];
  63.  
  64. STAB *
  65. stab(name, type, op)
  66.     char *name;
  67.     int type;
  68.     int op;
  69. {
  70.     register STAB *s;
  71.     register STAB **ps;
  72.     register int hfunc;
  73.     register char *p;
  74.     extern char lower();
  75.  
  76.     if (tTd(36, 5))
  77.         printf("STAB: %s %d ", name, type);
  78.  
  79.     /*
  80.     **  Compute the hashing function
  81.     **
  82.     **    We could probably do better....
  83.     */
  84.  
  85.     hfunc = type;
  86.     for (p = name; *p != '\0'; p++)
  87.         hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE;
  88.  
  89.     if (tTd(36, 9))
  90.         printf("(hfunc=%d) ", hfunc);
  91.  
  92.     ps = &SymTab[hfunc];
  93.     while ((s = *ps) != NULL && (strcasecmp(name, s->s_name) || s->s_type != type))
  94.         ps = &s->s_next;
  95.  
  96.     /*
  97.     **  Dispose of the entry.
  98.     */
  99.  
  100.     if (s != NULL || op == ST_FIND)
  101.     {
  102.         if (tTd(36, 5))
  103.         {
  104.             if (s == NULL)
  105.                 printf("not found\n");
  106.             else
  107.             {
  108.                 long *lp = (long *) s->s_class;
  109.  
  110.                 printf("type %d val %lx %lx %lx %lx\n",
  111.                     s->s_type, lp[0], lp[1], lp[2], lp[3]);
  112.             }
  113.         }
  114.         return (s);
  115.     }
  116.  
  117.     /*
  118.     **  Make a new entry and link it in.
  119.     */
  120.  
  121.     if (tTd(36, 5))
  122.         printf("entered\n");
  123.  
  124.     /* make new entry */
  125.     s = (STAB *) xalloc(sizeof *s);
  126.     bzero((char *) s, sizeof *s);
  127.     s->s_name = newstr(name);
  128.     makelower(s->s_name);
  129.     s->s_type = type;
  130.  
  131.     /* link it in */
  132.     *ps = s;
  133.  
  134.     return (s);
  135. }
  136.