1: #include "defs"
   2: 
   3: FSTATIC struct nameblock *hashtab[HASHSIZE];
   4: FSTATIC int nhashed = 0;
   5: 
   6: 
   7: /* simple linear hash.  hash function is sum of
   8:    characters mod hash table size.
   9: */
  10: hashloc(s)
  11: char *s;
  12: {
  13: register int i;
  14: register int hashval;
  15: register char *t;
  16: 
  17: hashval = 0;
  18: 
  19: for(t=s; *t!='\0' ; ++t)
  20:     hashval += *t;
  21: 
  22: hashval %= HASHSIZE;
  23: 
  24: for(i=hashval;
  25:     hashtab[i]!=0 && unequal(s,hashtab[i]->namep);
  26:     i = (i+1)%HASHSIZE ) ;
  27: 
  28: return(i);
  29: }
  30: 
  31: 
  32: struct nameblock *srchname(s)
  33: char *s;
  34: {
  35: return( hashtab[hashloc(s)] );
  36: }
  37: 
  38: 
  39: 
  40: struct nameblock *makename(s)
  41: char *s;
  42: {
  43: /* make a fresh copy of the string s */
  44: 
  45: char *copys();
  46: register struct nameblock *p;
  47: 
  48: if(nhashed++ > HASHSIZE-3)
  49:     fatal("Hash table overflow");
  50: 
  51: p = ALLOC(nameblock);
  52: p->nxtnameblock = firstname;
  53: p->namep = copys(s);
  54: p->linep = 0;
  55: p->done = 0;
  56: p->septype = 0;
  57: p->modtime = 0;
  58: 
  59: firstname = p;
  60: if(mainname == NULL)
  61:     if(s[0]!='.' || hasslash(s) )
  62:         mainname = p;
  63: 
  64: hashtab[hashloc(s)] = p;
  65: 
  66: return(p);
  67: }
  68: 
  69: 
  70: 
  71: hasslash(s)
  72: char *s;
  73: {
  74: for( ; *s ; ++s)
  75:     if(*s == '/')
  76:         return(YES);
  77: return(NO);
  78: }
  79: 
  80: 
  81: 
  82: char *copys(s)
  83: register char *s;
  84: {
  85: char *calloc();
  86: register char *t, *t0;
  87: 
  88: if( (t = t0 = calloc( strlen(s)+1 , sizeof(char)) ) == NULL)
  89:     fatal("out of memory");
  90: while(*t++ = *s++)
  91:     ;
  92: return(t0);
  93: }
  94: 
  95: 
  96: 
  97: char *concat(a,b,c)   /* c = concatenation of a and b */
  98: register char *a,*b;
  99: char *c;
 100: {
 101: register char *t;
 102: t = c;
 103: 
 104: while(*t = *a++) t++;
 105: while(*t++ = *b++);
 106: return(c);
 107: }
 108: 
 109: 
 110: 
 111: suffix(a,b,p)  /* is b the suffix of a?  if so, set p = prefix */
 112: register char *a,*b,*p;
 113: {
 114: char *a0,*b0;
 115: a0 = a;
 116: b0 = b;
 117: 
 118: while(*a++);
 119: while(*b++);
 120: 
 121: if( (a-a0) < (b-b0) ) return(0);
 122: 
 123: while(b>b0)
 124:     if(*--a != *--b) return(0);
 125: 
 126: while(a0<a) *p++ = *a0++;
 127: *p = '\0';
 128: 
 129: return(1);
 130: }
 131: 
 132: 
 133: 
 134: 
 135: 
 136: 
 137: int *ckalloc(n)
 138: register int n;
 139: {
 140: register int *p;
 141: 
 142: if( p = (int *) calloc(1,n) )
 143:     return(p);
 144: 
 145: fatal("out of memory");
 146: /* NOTREACHED */
 147: }
 148: 
 149: /* copy string a into b, substituting for arguments */
 150: char *subst(a,b)
 151: register char *a,*b;
 152: {
 153: static depth    = 0;
 154: register char *s;
 155: char vname[100];
 156: struct varblock *varptr(), *vbp;
 157: char closer;
 158: 
 159: if(++depth > 100)
 160:     fatal("infinitely recursive macro?");
 161: if(a!=0)  while(*a)
 162:     {
 163:     if(*a != '$') *b++ = *a++;
 164:     else if(*++a=='\0' || *a=='$')
 165:         *b++ = *a++;
 166:     else    {
 167:         s = vname;
 168:         if( *a=='(' || *a=='{' )
 169:             {
 170:             closer = ( *a=='(' ? ')' : '}');
 171:             ++a;
 172:             while(*a == ' ') ++a;
 173:             while(*a!=' ' && *a!=closer && *a!='\0') *s++ = *a++;
 174:             while(*a!=closer && *a!='\0') ++a;
 175:             if(*a == closer) ++a;
 176:             }
 177:         else    *s++ = *a++;
 178: 
 179:         *s = '\0';
 180:         if( (vbp = varptr(vname)) ->varval != 0)
 181:             {
 182:             b = subst(vbp->varval, b);
 183:             vbp->used = YES;
 184:             }
 185:         }
 186:     }
 187: 
 188: *b = '\0';
 189: --depth;
 190: return(b);
 191: }
 192: 
 193: 
 194: setvar(v,s)
 195: char *v, *s;
 196: {
 197: struct varblock *varptr(), *p;
 198: 
 199: p = varptr(v);
 200: if(p->noreset == 0)
 201:     {
 202:     p->varval = s;
 203:     p->noreset = inarglist;
 204:     if(p->used && unequal(v,"@") && unequal(v,"*")
 205:         && unequal(v,"<") && unequal(v,"?") )
 206:         fprintf(stderr, "Warning: %s changed after being used\n",v);
 207:     }
 208: }
 209: 
 210: 
 211: eqsign(a)   /*look for arguments with equal signs but not colons */
 212: char *a;
 213: {
 214: register char *s, *t;
 215: 
 216: while(*a == ' ') ++a;
 217: for(s=a  ;   *s!='\0' && *s!=':'  ; ++s)
 218:     if(*s == '=')
 219:         {
 220:         for(t = a ; *t!='=' && *t!=' ' && *t!='\t' ;  ++t );
 221:         *t = '\0';
 222: 
 223:         for(++s; *s==' ' || *s=='\t' ; ++s);
 224:         setvar(a, copys(s));
 225:         return(YES);
 226:         }
 227: 
 228: return(NO);
 229: }
 230: 
 231: 
 232: struct varblock *varptr(v)
 233: char *v;
 234: {
 235: register struct varblock *vp;
 236: 
 237: for(vp = firstvar; vp ; vp = vp->nxtvarblock)
 238:     if(! unequal(v , vp->varname))
 239:         return(vp);
 240: 
 241: vp = ALLOC(varblock);
 242: vp->nxtvarblock = firstvar;
 243: firstvar = vp;
 244: vp->varname = copys(v);
 245: vp->varval = 0;
 246: return(vp);
 247: }
 248: 
 249: 
 250: fatal1(s, t)
 251: char *s, *t;
 252: {
 253: char buf[100];
 254: fatal( sprintf(buf, s, t) );
 255: }
 256: 
 257: 
 258: 
 259: fatal(s)
 260: char *s;
 261: {
 262: if(s) fprintf(stderr, "Make: %s.  Stop.\n", s);
 263: else fprintf(stderr, "\nStop.\n");
 264: #ifdef unix
 265: exit(1);
 266: #endif
 267: #ifdef gcos
 268: exit(0);
 269: #endif
 270: }
 271: 
 272: 
 273: 
 274: yyerror(s)
 275: char *s;
 276: {
 277: char buf[50];
 278: extern int yylineno;
 279: 
 280: fatal( sprintf(buf, "line %d: %s", yylineno, s) );
 281: }
 282: 
 283: 
 284: 
 285: struct chain *appendq(head, tail)
 286: struct chain *head;
 287: char *tail;
 288: {
 289: register struct chain *p, *q;
 290: 
 291: p = ALLOC(chain);
 292: p->datap = tail;
 293: 
 294: if(head)
 295:     {
 296:     for(q = head ; q->nextp ; q = q->nextp)
 297:         ;
 298:     q->nextp = p;
 299:     return(head);
 300:     }
 301: else
 302:     return(p);
 303: }
 304: 
 305: 
 306: 
 307: 
 308: 
 309: char *mkqlist(p)
 310: struct chain *p;
 311: {
 312: register char *qbufp, *s;
 313: static char qbuf[QBUFMAX];
 314: 
 315: if(p == NULL)
 316:     {
 317:     qbuf[0] = '\0';
 318:     return;
 319:     }
 320: 
 321: qbufp = qbuf;
 322: 
 323: for( ; p ; p = p->nextp)
 324:     {
 325:     s = p->datap;
 326:     if(qbufp+strlen(s) > &qbuf[QBUFMAX-3])
 327:         {
 328:         fprintf(stderr, "$? list too long\n");
 329:         break;
 330:         }
 331:     while (*s)
 332:         *qbufp++ = *s++;
 333:     *qbufp++ = ' ';
 334:     }
 335: *--qbufp = '\0';
 336: return(qbuf);
 337: }

Defined functions

appendq defined in line 285; used 3 times
ckalloc defined in line 137; never used
concat defined in line 97; used 7 times
copys defined in line 82; used 10 times
eqsign defined in line 211; used 2 times
hashloc defined in line 10; used 2 times
hasslash defined in line 71; used 1 times
  • in line 61
makename defined in line 40; used 3 times
mkqlist defined in line 309; used 3 times
setvar defined in line 194; used 11 times
subst defined in line 150; used 3 times
suffix defined in line 111; used 1 times
varptr defined in line 232; used 8 times
yyerror defined in line 274; never used

Defined variables

hashtab defined in line 3; used 4 times
nhashed defined in line 4; used 1 times
  • in line 48
Last modified: 1982-09-27
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 996
Valid CSS Valid XHTML 1.0 Strict