shithub: riscv

Download patch

ref: b15430979d712d27ea4cd40ca2ab031206081dfe
parent: ce7f7d3ab9f193dc35ee005487b83c5a93b963d9
author: cinap_lenrek <[email protected]>
date: Mon May 16 15:57:53 EDT 2016

rc: simplify execfinit() / Xrdfn() using the globber to lookup /env/fn'#'*

--- a/sys/src/cmd/rc/plan9.c
+++ b/sys/src/cmd/rc/plan9.c
@@ -152,42 +152,20 @@
 	}
 	close(dir);
 }
-int envdir;
 
 void
 Xrdfn(void)
 {
-	int f, len;
-	Dir *e;
-	char envname[Maxenvname];
-	static Dir *ent, *allocent;
-	static int nent;
-
-	for(;;){
-		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;
-				}
-			}
-		}
+	if(runq->argv->words == 0)
+		poplist();
+	else {
+		int f = open(runq->argv->words->word, 0);
+		popword();
+		runq->pc--;
+		if(f>=0) execcmds(openfd(f));
 	}
-	close(envdir);
-	Xreturn();
 }
-union code rdfns[4];
+union code rdfns[8];
 
 void
 execfinit(void)
@@ -195,17 +173,15 @@
 	static int first = 1;
 	if(first){
 		rdfns[0].i = 1;
-		rdfns[1].f = Xrdfn;
-		rdfns[2].f = Xjump;
-		rdfns[3].i = 1;
+		rdfns[1].f = Xmark;
+		rdfns[2].f = Xglobs;
+		rdfns[4].i = Globsize(rdfns[3].s = "/env/fn#\001*");
+		rdfns[5].f = Xglob;
+		rdfns[6].f = Xrdfn;
+		rdfns[7].f = Xreturn;
 		first = 0;
 	}
-	Xpopm();
-	envdir = open("/env", 0);
-	if(envdir<0){
-		pfmt(err, "rc: can't open /env: %r\n");
-		return;
-	}
+	poplist();
 	start(rdfns, 1, runq->local);
 }