char *infile;
int mkinline;
static int rhead(char *, Word **, Word **, int *, char **);
static char *rbody(Biobuf*);
extern Word *target1;
void
parse(char *f, int fd, int varoverride)
{
int hline;
char *body;
Word *head, *tail;
int attr, set, pid;
char *prog, *p;
int newfd;
Biobuf in;
Bufblock *buf;
if(fd < 0){
perror(f);
Exit();
}
ipush();
infile = strdup(f);
mkinline = 1;
Binit(&in, fd, OREAD);
buf = newbuf();
while(assline(&in, buf)){
hline = mkinline;
switch(rhead(buf->start, &head, &tail, &attr, &prog))
{
case '<':
p = wtos(tail, ' ');
if(*p == 0){
SYNERR(-1);
fprint(2, "missing include file name\n");
Exit();
}
newfd = open(p, OREAD);
if(newfd < 0){
fprint(2, "warning: skipping missing include file: ");
perror(p);
} else
parse(p, newfd, 0);
break;
case '|':
p = wtos(tail, ' ');
if(*p == 0){
SYNERR(-1);
fprint(2, "missing include program name\n");
Exit();
}
execinit();
pid=pipecmd(p, envy, &newfd);
if(newfd < 0){
fprint(2, "warning: skipping missing program file: ");
perror(p);
} else
parse(p, newfd, 0);
while(waitup(-3, &pid) >= 0)
;
if(pid != 0){
fprint(2, "bad include program status\n");
Exit();
}
break;
case ':':
body = rbody(&in);
addrules(head, tail, body, attr, hline, prog);
break;
case '=':
if(head->next){
SYNERR(-1);
fprint(2, "multiple vars on left side of assignment\n");
Exit();
}
if(symlook(head->s, S_OVERRIDE, 0)){
set = varoverride;
} else {
set = 1;
if(varoverride)
symlook(head->s, S_OVERRIDE, (void *)"");
}
if(set){
/*
char *cp;
dumpw("tail", tail);
cp = wtos(tail, ' '); print("assign %s to %s\n", head->s, cp); free(cp);
*/
setvar(head->s, (void *) tail);
symlook(head->s, S_WESET, (void *)"");
}
if(attr)
symlook(head->s, S_NOEXPORT, (void *)"");
break;
default:
SYNERR(hline);
fprint(2, "expected one of :<=\n");
Exit();
break;
}
}
close(fd);
freebuf(buf);
ipop();
}
void
addrules(Word *head, Word *tail, char *body, int attr, int hline, char *prog)
{
Word *w;