]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/rc/simple.c
git/branch: somewhere in the syncing, the fix for junk files was lost
[plan9front.git] / sys / src / cmd / rc / simple.c
index a29359866fa71f16cd86ade7399d94fbecd26db2..3987dbe5ad6f952f218f2a244c408397410b0b50 100644 (file)
  */
 int
 exitnext(void){
-       union code *c=&runq->code[runq->pc];
-       while(c->f==Xpopredir) c++;
+       code *c=&runq->code[runq->pc];
+       while(1){
+               if(c->f==Xpopredir || c->f==Xunlocal)
+                       c++;
+               else if(c->f==Xsrcline || c->f==Xsrcfile)
+                       c += 2;
+               else
+                       break;
+       }
        return c->f==Xexit;
 }
 
@@ -70,7 +77,6 @@ Xsimple(void)
                }
        }
 }
-struct word nullpath = { "", 0};
 
 void
 doredir(redir *rp)
@@ -95,16 +101,18 @@ doredir(redir *rp)
 }
 
 word*
-searchpath(char *w)
+searchpath(char *w, char *v)
 {
+       static struct word nullpath = { "", 0 };
        word *path;
-       if(strncmp(w, "/", 1)==0
-       || strncmp(w, "#", 1)==0
-       || strncmp(w, "./", 2)==0
-       || strncmp(w, "../", 3)==0
-       || (path = vlook("path")->val)==0)
-               path=&nullpath;
-       return path;
+
+       if(w[0] && w[0] != '/' && w[0] != '#' &&
+         (w[0] != '.' || (w[1] && w[1] != '/' && (w[1] != '.' || w[2] && w[2] != '/')))){
+               path = vlook(v)->val;
+               if(path)
+                       return path;
+       }
+       return &nullpath;
 }
 
 void
@@ -116,7 +124,7 @@ execexec(void)
                return;
        }
        doredir(runq->redir);
-       Execute(runq->argv->words, searchpath(runq->argv->words->word));
+       Execute(runq->argv->words, searchpath(runq->argv->words->word, "path"));
        poplist();
        Xexit();
 }
@@ -153,24 +161,19 @@ execcd(void)
        char *dir;
 
        setstatus("can't cd");
-       cdpath = vlook("cdpath")->val;
        switch(count(a)){
        default:
                pfmt(err, "Usage: cd [directory]\n");
                break;
        case 2:
-               if(a->next->word[0]=='/' || cdpath==0)
-                       cdpath = &nullpath;
-               for(; cdpath; cdpath = cdpath->next){
+               a = a->next;
+               for(cdpath = searchpath(a->word, "cdpath"); cdpath; cdpath = cdpath->next){
                        if(cdpath->word[0] != '\0')
-                               dir = smprint("%s/%s", cdpath->word,
-                                       a->next->word);
+                               dir = smprint("%s/%s", cdpath->word, a->word);
                        else
-                               dir = estrdup(a->next->word);
-
+                               dir = estrdup(a->word);
                        if(dochdir(dir) >= 0){
-                               if(cdpath->word[0] != '\0' &&
-                                   strcmp(cdpath->word, ".") != 0)
+                               if(cdpath->word[0] != '\0' && strcmp(cdpath->word, ".") != 0)
                                        pfmt(err, "%s\n", dir);
                                free(dir);
                                setstatus("");
@@ -179,7 +182,7 @@ execcd(void)
                        free(dir);
                }
                if(cdpath==0)
-                       pfmt(err, "Can't cd %s: %r\n", a->next->word);
+                       pfmt(err, "Can't cd %s: %r\n", a->word);
                break;
        case 1:
                a = vlook("home")->val;
@@ -264,6 +267,7 @@ void
 execcmds(io *f)
 {
        static int first = 1;
+
        if(first){
                rdcmds[0].i = 1;
                rdcmds[1].f = Xrdcmds;
@@ -323,6 +327,7 @@ execdot(void)
        }
        else
                eflagok = 1;
+
        popword();
        if(p->argv->words && strcmp(p->argv->words->word, "-i")==0){
                iflag = 1;
@@ -336,7 +341,7 @@ execdot(void)
        zero = estrdup(p->argv->words->word);
        popword();
        fd = -1;
-       for(path = searchpath(zero); path; path = path->next){
+       for(path = searchpath(zero, "path"); path; path = path->next){
                if(path->word[0] != '\0')
                        file = smprint("%s/%s", path->word, zero);
                else
@@ -358,6 +363,9 @@ execdot(void)
                Xerror(".: can't open");
                return;
        }
+
+       lexline = 1;
+
        /* set up for a new command loop */
        start(dotcmds, 1, (struct var *)0);
        pushredir(RCLOSE, fd, 0);
@@ -452,7 +460,7 @@ execwhatis(void){   /* mildly wrong -- should fork before writing */
                                        break;
                                }
                        if(!bp->name){
-                               for(path = searchpath(a->word); path;
+                               for(path = searchpath(a->word, "path"); path;
                                    path = path->next){
                                        if(path->word[0] != '\0')
                                                file = smprint("%s/%s",