Example #1
0
Envy*
buildenv(Job *j, int slot)
{
	char **p, *cp, *qp;
	Word *w, *v, **l;
	int i;
	char buf[256];

	envupd("target", wdup(j->t));
	if(j->r->attr&REGEXP)
		envupd("stem",newword(""));
	else
		envupd("stem", newword(j->stem));
	envupd("prereq", wdup(j->p));
	sprint(buf, "%d", getpid());
	envupd("pid", newword(buf));
	sprint(buf, "%d", slot);
	envupd("nproc", newword(buf));
	envupd("newprereq", wdup(j->np));
	envupd("alltarget", wdup(j->at));
	l = &v;
	v = w = wdup(j->np);
	while(w){
		cp = strchr(w->s, '(');
		if(cp){
			qp = strchr(cp+1, ')');
			if(qp){
				*qp = 0;
				strcpy(w->s, cp+1);
				l = &w->next;
				w = w->next;
				continue;
			}
		}
		*l = w->next;
		free(w->s);
		free(w);
		w = *l;
	}
	envupd("newmember", v);
		/* update stem0 -> stem9 */
	for(p = myenv; *p; p++)
		if(strcmp(*p, "stem0") == 0)
			break;
	for(i = 0; *p; i++, p++){
		if((j->r->attr&REGEXP) && j->match[i])
			envupd(*p, newword(j->match[i]));
		else 
			envupd(*p, newword(""));
	}
	return envy;
}
Example #2
0
void
addrules(Word *head, Word *tail, char *body, int attr, int hline, char *prog)
{
    Word *w;

    assert(/*addrules args*/ head && body);
    /* tuck away first non-meta rule as default target*/
    if(target1 == 0 && !(attr&REGEXP)) {
        for(w = head; w; w = w->next)
            if(charin(w->s, "%&"))
                break;
        if(w == 0)
            target1 = wdup(head);
    }
    for(w = head; w; w = w->next)
        addrule(w->s, tail, body, head, attr, hline, prog);
}
Example #3
0
static Word*
varmatch(char *name, char **s)
{
	Word *w;
	Symtab *sym;
	char *cp;
	
	sym = symlook(name, S_VAR, 0);
	if(sym){
			/* check for at least one non-NULL value */
		for (w = (Word*)sym->value; w; w = w->next)
			if(w->s && *w->s)
				return wdup(w);
	}
	for(cp = *s; *cp == ' ' || *cp == '\t'; cp++)	/* skip trailing whitespace */
			;
	*s = cp;
	return 0;
}
Example #4
0
static Word*
subsub(Word *v, char *s, char *end)
{
	int nmid;
	Word *head, *tail, *w, *h;
	Word *a, *b, *c, *d;
	Bufblock *buf;
	char *cp, *enda;

	a = extractpat(s, &cp, "=%&", end);
	b = c = d = 0;
	if(PERCENT(*cp))
		b = extractpat(cp+1, &cp, "=", end);
	if(*cp == '=')
		c = extractpat(cp+1, &cp, "&%", end);
	if(PERCENT(*cp))
		d = stow(cp+1);
	else if(*cp)
		d = stow(cp);

	head = tail = 0;
	buf = newbuf();
	for(; v; v = v->next){
		h = w = 0;
		if(submatch(v->s, a, b, &nmid, &enda)){
			/* enda points to end of A match in source;
			 * nmid = number of chars between end of A and start of B
			 */
			if(c){
				h = w = wdup(c);
				while(w->next)
					w = w->next;
			}
			if(PERCENT(*cp) && nmid > 0){	
				if(w){
					bufcpy(buf, w->s, strlen(w->s));
					bufcpy(buf, enda, nmid);
					insert(buf, 0);
					free(w->s);
					w->s = strdup(buf->start);
				} else {
					bufcpy(buf, enda, nmid);
					insert(buf, 0);
					h = w = newword(buf->start);
				}
				buf->current = buf->start;
			}
			if(d && *d->s){
				if(w){

					bufcpy(buf, w->s, strlen(w->s));
					bufcpy(buf, d->s, strlen(d->s));
					insert(buf, 0);
					free(w->s);
					w->s = strdup(buf->start);
					w->next = wdup(d->next);
					while(w->next)
						w = w->next;
					buf->current = buf->start;
				} else
					h = w = wdup(d);
			}
		}
		if(w == 0)
			h = w = newword(v->s);
	
		if(head == 0)
			head = h;
		else
			tail->next = h;
		tail = w;
	}
	freebuf(buf);
	delword(a);
	delword(b);
	delword(c);
	delword(d);
	return head;
}