3 static int hasslash(char *);
4 static int haspercent(char *);
5 static void rehash(void);
7 /* simple linear hash. hash function is sum of
8 characters mod hash table size.
19 for(t=s; *t!='\0' ; ++t)
25 hashtab[i]!=0 && !equal(s,hashtab[i]->namep);
26 i = i >= hashsize-1 ? 0 : i+1) ;
35 return hashtab[hashloc(s)] ;
45 if(nhashed > hashthresh)
49 hashtab[hashloc(s)] = p = ALLOC(nameblock);
50 p->nxtnameblock = firstname;
51 p->namep = copys(s); /* make a fresh copy of the string s */
52 /* p->linep = 0; p->done = 0; p->septype = 0; p->modtime = 0; */
55 if(mainname==NULL && !haspercent(s) && (*s!='.' || hasslash(s)) )
93 nameblkp p, *hp, *endohash;
95 endohash = hashtab + hashsize;
101 hashtab[hashloc(p->namep)] = p;
103 free( (char *) ohash);
111 hashtab = (nameblkp *) ckalloc(hashsize * sizeof(nameblkp));
112 hashthresh = (2*hashsize)/3;
117 nameblkp chkname(char *s)
125 /*TEMP fprintf(stderr, "chkname(%s): look=%d\n", s, k); */
142 if( (t = malloc( strlen(s)+1 ) ) == NULL)
143 fatal("out of memory");
151 concat(char *a, char *b, char *c) /* c = concatenation of a and b */
156 while(*t = *a++) t++;
163 suffix(char *a, char *b, char *p) /* is b the suffix of a? if so, set p = prefix */
172 if( (a-a0) < (b-b0) ) return 0;
175 if(*--a != *--b) return 0;
177 while(a0<a) *p++ = *a0++;
188 if( p = (int *) calloc(1,n) )
191 fatal("out of memory");
192 return 0;/* NOTREACHED */
195 /* copy string a into b, substituting for arguments */
197 subst(char *a, char *b)
202 struct varblock *vbp;
206 fatal("infinitely recursive macro?");
209 if(*a!='$' || a[1]=='\0' || *++a=='$')
210 /* if a non-macro character copy it. if $$ or $\0, copy $ */
214 if( *a=='(' || *a=='{' )
216 closer = ( *a=='(' ? ')' : '}');
218 while(*a == ' ') ++a;
219 while(*a!=' ' && *a!=closer && *a!='\0') *s++ = *a++;
220 while(*a!=closer && *a!='\0') ++a;
221 if(*a == closer) ++a;
226 if( (vbp = varptr(vname)) ->varval != 0)
228 b = subst(vbp->varval, b);
240 setvar(char *v, char *s, int dyn)
248 p->noreset = inarglist;
250 fprintf(stderr, "Warning: %s changed after being used\n",v);
253 /* change string pointed to by environment to new v=s */
257 *(p->export) = t = (char *) ckalloc(lenv + strlen(s) + 2);
268 /* for setting Bradford's *D and *F family of macros whens setting * etc */
270 set3var(char *macro, char *value)
273 char macjunk[8], *lastslash, *dirpart, *filepart;
275 setvar(macro, value, YES);
277 dirpart = filepart = CHNULL;
281 for(s = value; *s; ++s)
286 dirpart = copys(value);
287 filepart = dirpart + (lastslash-value);
296 setvar(concat(macro, "D", macjunk), dirpart, YES);
297 setvar(concat(macro, "F", macjunk), filepart, YES);
302 eqsign(char *a) /*look for arguments with equal signs but not colons */
307 while(*a == ' ') ++a;
308 for(s=a ; *s!='\0' && *s!=':' ; ++s)
311 for(t = a ; *t!='=' && *t!=' ' && *t!='\t' ; ++t );
315 for(++s; *s==' ' || *s=='\t' ; ++s);
316 setvar(a, copys(s), NO);
329 /* for compatibility, $(TGS) = $^ */
332 for(vp = firstvar; vp ; vp = vp->nxtvarblock)
333 if(equal(v , vp->varname))
336 vp = ALLOC(varblock);
337 vp->nxtvarblock = firstvar;
339 vp->varname = copys(v);
349 if(!isalpha(line[0]))
351 for(s=line+1 ; *s && (isalpha(*s) | isdigit(*s)) ; ++s)
356 if(s[0]!=':' || s[1]!='=')
361 setvar(line, copys(s+2), YES);
369 fatal1(char *s, char *t)
382 fprintf(stderr, "Make: %s. Stop.\n", s);
384 fprintf(stderr, "\nStop.\n");
392 /* appends to the chain for $? and $^ */
394 appendq(chainp head, char *tail)
403 for(q = head ; q->nextp ; q = q->nextp)
416 /* builds the value for $? and $^ */
418 mkqlist(chainp p, char *qbuf)
427 for( ; p ; p = p->nextp)
430 if(qbufp+strlen(s) > &qbuf[QBUFMAX-3])
432 fprintf(stderr, "$? list too long\n");
454 p->left = copys(name);
456 p->right = copys(s+1);
457 p->llen = strlen(p->left);
458 p->rlen = strlen(p->right);
459 p->totlen = p->llen + p->rlen;
467 wildmatch(wildp p, char *name, int len)
473 if(len < p->totlen ||
474 strncmp(name, p->left, p->llen) ||
475 strncmp(s = name+len-p->rlen, p->right, p->rlen) )
478 /*TEMP fprintf(stderr, "wildmatch(%s)=%s%%%s)\n", name,p->left,p->right); */
481 stem = copys(name + p->llen);
488 /* substitute stem for any % marks */
490 wildsub(char *pat, char *stem)
492 static char temp[100];