148064Sbostic /*- 248064Sbostic * %sccs.include.proprietary.c% 348064Sbostic */ 448064Sbostic 514504Ssam #ifndef lint 6*62210Sbostic static char sccsid[] = "@(#)rlook.c 8.1 (Berkeley) 06/06/93"; 748064Sbostic #endif /* not lint */ 814504Ssam 99730Sclemc #define NULL 0 109730Sclemc #define EOS 0 119730Sclemc #define HSHSIZ 101 129730Sclemc struct nlist { 139730Sclemc char *name; 149730Sclemc char *def; 159730Sclemc int ydef; 169730Sclemc struct nlist *next; 179730Sclemc }; 189730Sclemc 199730Sclemc struct nlist *hshtab[HSHSIZ]; 209730Sclemc struct nlist *lookup(); 219730Sclemc char *install(); 229730Sclemc char *malloc(); 239730Sclemc char *copy(); 249730Sclemc int hshval; 259730Sclemc lookup(str)269730Sclemcstruct nlist *lookup(str) 279730Sclemc char *str; 289730Sclemc { 299730Sclemc register char *s1, *s2; 309730Sclemc register struct nlist *np; 319730Sclemc static struct nlist nodef; 329730Sclemc 339730Sclemc s1 = str; 349730Sclemc for (hshval = 0; *s1; ) 359730Sclemc hshval += *s1++; 369730Sclemc hshval %= HSHSIZ; 379730Sclemc for (np = hshtab[hshval]; np!=NULL; np = np->next) { 389730Sclemc s1 = str; 399730Sclemc s2 = np->name; 409730Sclemc while (*s1++ == *s2) 419730Sclemc if (*s2++ == EOS) 429730Sclemc return(np); 439730Sclemc } 449730Sclemc return(&nodef); 459730Sclemc } 469730Sclemc install(nam,val,tran)479730Sclemcchar *install(nam, val, tran) 489730Sclemc char *nam, *val; 499730Sclemc int tran; 509730Sclemc { 519730Sclemc register struct nlist *np; 529730Sclemc 539730Sclemc if ((np = lookup(nam))->name == NULL) { 549730Sclemc np = (struct nlist *)malloc(sizeof(*np)); 559730Sclemc np->name = copy(nam); 569730Sclemc np->def = copy(val); 579730Sclemc np->ydef = tran; 589730Sclemc np->next = hshtab[hshval]; 599730Sclemc hshtab[hshval] = np; 609730Sclemc return(np->def); 619730Sclemc } 629730Sclemc free(np->def); 639730Sclemc np->def = copy(val); 649730Sclemc return(np->def); 659730Sclemc } 669730Sclemc copy(s)679730Sclemcchar *copy(s) 689730Sclemc register char *s; 699730Sclemc { 709730Sclemc register char *p, *s1; 719730Sclemc 729730Sclemc p = s1 = (char *) malloc((unsigned)strlen(s)+1); 739730Sclemc while (*s1++ = *s++); 749730Sclemc return(p); 759730Sclemc } 76