1987-03-09 19:15:41 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1985-01-08 09:59:28 +00:00
|
|
|
#ifndef NORCSID
|
2019-05-10 17:17:24 +00:00
|
|
|
static char rcsid[] = "$Id$";
|
1985-01-08 09:59:28 +00:00
|
|
|
#endif
|
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
#include <assert.h>
|
2017-11-14 22:04:01 +00:00
|
|
|
#include <string.h>
|
1985-01-08 09:59:28 +00:00
|
|
|
#include "param.h"
|
|
|
|
#include "lookup.h"
|
2013-05-10 11:04:21 +00:00
|
|
|
#include "extern.h"
|
2019-05-10 17:17:24 +00:00
|
|
|
#include "subr.h"
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
symbol dumsym; /* dummy to return in case of error */
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
/* Forward declarations */
|
|
|
|
static int hashvalue(register char *);
|
|
|
|
|
|
|
|
symbol *lookup(char *name, symtype type, lookupstyle style)
|
1985-01-08 09:59:28 +00:00
|
|
|
{
|
2019-05-10 17:17:24 +00:00
|
|
|
symbol *sy_p, **sy_pp;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
for (sy_pp = &symhash[hashvalue(name)]; (sy_p = *sy_pp) != 0;
|
|
|
|
sy_pp = &sy_p->sy_next)
|
|
|
|
{
|
|
|
|
if (strcmp(sy_p->sy_name, name) != 0)
|
1985-01-08 09:59:28 +00:00
|
|
|
continue;
|
2019-05-10 17:17:24 +00:00
|
|
|
switch (style)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
case justlooking:
|
|
|
|
case mustexist:
|
|
|
|
case makeexist:
|
|
|
|
if (type == symany || type == sy_p->sy_type)
|
|
|
|
return (sy_p);
|
|
|
|
continue;
|
|
|
|
case newsymbol:
|
|
|
|
error("%s already defined", name);
|
|
|
|
return (&dumsym);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (style)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
case justlooking:
|
2019-05-10 17:17:24 +00:00
|
|
|
return ((symbol *) 0);
|
1985-01-08 09:59:28 +00:00
|
|
|
case mustexist:
|
2019-05-10 17:17:24 +00:00
|
|
|
fatal("%s is unknown symbol", name);
|
|
|
|
/* NOTREACHED */
|
1985-01-08 09:59:28 +00:00
|
|
|
case newsymbol:
|
2019-05-10 17:17:24 +00:00
|
|
|
case makeexist:
|
|
|
|
NEW(sy_p, symbol);
|
|
|
|
sy_p->sy_next = 0;
|
|
|
|
sy_p->sy_name = mystrcpy(name);
|
|
|
|
assert(type != symany);
|
|
|
|
sy_p->sy_type = type;
|
|
|
|
*sy_pp = sy_p;
|
|
|
|
return (sy_p);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
static int hashvalue(register char *s)
|
|
|
|
{
|
|
|
|
register unsigned sum = 0;
|
|
|
|
register int i;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
for (i = 0; *s; s++, i = (i + 3) & 07)
|
|
|
|
sum += *s << i;
|
|
|
|
return (sum % NSYMHASH);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|