1*14504Ssam #ifndef lint 2*14504Ssam static char sccsid[] = "@(#)rlook.c 1.2 (Berkeley) 08/11/83"; 3*14504Ssam #endif 4*14504Ssam 59730Sclemc #define NULL 0 69730Sclemc #define EOS 0 79730Sclemc #define HSHSIZ 101 89730Sclemc struct nlist { 99730Sclemc char *name; 109730Sclemc char *def; 119730Sclemc int ydef; 129730Sclemc struct nlist *next; 139730Sclemc }; 149730Sclemc 159730Sclemc struct nlist *hshtab[HSHSIZ]; 169730Sclemc struct nlist *lookup(); 179730Sclemc char *install(); 189730Sclemc char *malloc(); 199730Sclemc char *copy(); 209730Sclemc int hshval; 219730Sclemc 229730Sclemc struct nlist *lookup(str) 239730Sclemc char *str; 249730Sclemc { 259730Sclemc register char *s1, *s2; 269730Sclemc register struct nlist *np; 279730Sclemc static struct nlist nodef; 289730Sclemc 299730Sclemc s1 = str; 309730Sclemc for (hshval = 0; *s1; ) 319730Sclemc hshval += *s1++; 329730Sclemc hshval %= HSHSIZ; 339730Sclemc for (np = hshtab[hshval]; np!=NULL; np = np->next) { 349730Sclemc s1 = str; 359730Sclemc s2 = np->name; 369730Sclemc while (*s1++ == *s2) 379730Sclemc if (*s2++ == EOS) 389730Sclemc return(np); 399730Sclemc } 409730Sclemc return(&nodef); 419730Sclemc } 429730Sclemc 439730Sclemc char *install(nam, val, tran) 449730Sclemc char *nam, *val; 459730Sclemc int tran; 469730Sclemc { 479730Sclemc register struct nlist *np; 489730Sclemc 499730Sclemc if ((np = lookup(nam))->name == NULL) { 509730Sclemc np = (struct nlist *)malloc(sizeof(*np)); 519730Sclemc np->name = copy(nam); 529730Sclemc np->def = copy(val); 539730Sclemc np->ydef = tran; 549730Sclemc np->next = hshtab[hshval]; 559730Sclemc hshtab[hshval] = np; 569730Sclemc return(np->def); 579730Sclemc } 589730Sclemc free(np->def); 599730Sclemc np->def = copy(val); 609730Sclemc return(np->def); 619730Sclemc } 629730Sclemc 639730Sclemc char *copy(s) 649730Sclemc register char *s; 659730Sclemc { 669730Sclemc register char *p, *s1; 679730Sclemc 689730Sclemc p = s1 = (char *) malloc((unsigned)strlen(s)+1); 699730Sclemc while (*s1++ = *s++); 709730Sclemc return(p); 719730Sclemc } 72