rc: simplify execfinit() / Xrdfn() using the globber to lookup /env/fn'#'*
This commit is contained in:
parent
ce7f7d3ab9
commit
b15430979d
1 changed files with 15 additions and 39 deletions
|
@ -152,42 +152,20 @@ Vinit(void)
|
||||||
}
|
}
|
||||||
close(dir);
|
close(dir);
|
||||||
}
|
}
|
||||||
int envdir;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Xrdfn(void)
|
Xrdfn(void)
|
||||||
{
|
{
|
||||||
int f, len;
|
if(runq->argv->words == 0)
|
||||||
Dir *e;
|
poplist();
|
||||||
char envname[Maxenvname];
|
else {
|
||||||
static Dir *ent, *allocent;
|
int f = open(runq->argv->words->word, 0);
|
||||||
static int nent;
|
popword();
|
||||||
|
runq->pc--;
|
||||||
for(;;){
|
if(f>=0) execcmds(openfd(f));
|
||||||
if(nent == 0){
|
|
||||||
free(allocent);
|
|
||||||
nent = dirread(envdir, &allocent);
|
|
||||||
ent = allocent;
|
|
||||||
}
|
|
||||||
if(nent <= 0)
|
|
||||||
break;
|
|
||||||
while(nent){
|
|
||||||
e = ent++;
|
|
||||||
nent--;
|
|
||||||
len = e->length;
|
|
||||||
if(len && strncmp(e->name, "fn#", 3)==0){
|
|
||||||
snprint(envname, sizeof envname, "/env/%s", e->name);
|
|
||||||
if((f = open(envname, 0))>=0){
|
|
||||||
execcmds(openfd(f));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
close(envdir);
|
|
||||||
Xreturn();
|
|
||||||
}
|
}
|
||||||
union code rdfns[4];
|
union code rdfns[8];
|
||||||
|
|
||||||
void
|
void
|
||||||
execfinit(void)
|
execfinit(void)
|
||||||
|
@ -195,17 +173,15 @@ execfinit(void)
|
||||||
static int first = 1;
|
static int first = 1;
|
||||||
if(first){
|
if(first){
|
||||||
rdfns[0].i = 1;
|
rdfns[0].i = 1;
|
||||||
rdfns[1].f = Xrdfn;
|
rdfns[1].f = Xmark;
|
||||||
rdfns[2].f = Xjump;
|
rdfns[2].f = Xglobs;
|
||||||
rdfns[3].i = 1;
|
rdfns[4].i = Globsize(rdfns[3].s = "/env/fn#\001*");
|
||||||
|
rdfns[5].f = Xglob;
|
||||||
|
rdfns[6].f = Xrdfn;
|
||||||
|
rdfns[7].f = Xreturn;
|
||||||
first = 0;
|
first = 0;
|
||||||
}
|
}
|
||||||
Xpopm();
|
poplist();
|
||||||
envdir = open("/env", 0);
|
|
||||||
if(envdir<0){
|
|
||||||
pfmt(err, "rc: can't open /env: %r\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
start(rdfns, 1, runq->local);
|
start(rdfns, 1, runq->local);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue