home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume2 / basic / part2 / newbs / gvadr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  911 b   |  33 lines

  1. /* gvadr() -- Get variable address from vlist, with type checking.
  2.  *    This routine allows numerous copies of same name as long as
  3.  *    all copies have different types.  Probably doesnt matter since
  4.  *    the parser does the type checking.
  5.  */
  6. struct dictnode *gvadr(s,ty)
  7. char *s;
  8. int ty;
  9. {
  10.     register int i;
  11.     register int qual; /* type qualifier */
  12.  
  13.     /* Inefficient */
  14.     for(i=0; vlist[i].name!=0 && i<VLSIZ; i++)
  15.     if(vlist[i].type_of_value==ty && strcmp(s,vlist[i].name)==0)
  16.         /* match found */
  17.             break;
  18.     if(i >= VLSIZ) {
  19.     fprintf(stderr,"gvadr: out of room in variable list for %s\n",s);
  20.     exit(1);
  21.     }
  22.     /* not on list, enter it */
  23.     if(vlist[i].name == 0) {
  24.     vlist[i].name = myalloc(strlen(s)+1);
  25.     strcpy(vlist[i].name,s);
  26.     vlist[i].val.rval = 0;
  27.     vlist[i].type_of_value = ty;
  28.     if(ty&T_QMASK == Q_ARY)
  29.         vlist[i].val.arval = myalloc(13*sizeof(union value));
  30.     }
  31.     return(&vlist[i]);
  32. }
  33.