]> git.lizzy.rs Git - plan9front.git/commitdiff
rc: implement 9atoms ` split {command} syntax extension
authorcinap_lenrek <cinap_lenrek@felloff.net>
Thu, 30 Jun 2016 17:09:27 +0000 (19:09 +0200)
committercinap_lenrek <cinap_lenrek@felloff.net>
Thu, 30 Jun 2016 17:09:27 +0000 (19:09 +0200)
sys/man/1/rc
sys/src/cmd/rc/code.c
sys/src/cmd/rc/exec.c
sys/src/cmd/rc/havefork.c
sys/src/cmd/rc/pcmd.c
sys/src/cmd/rc/syn.y

index 29cfd94b58942cbabd2eb809e5c77f80c57234b6..2b12cf0f73ca9e39f0c0ec66aba4b1b136375a17 100644 (file)
@@ -233,6 +233,8 @@ The value is a single string containing the components of the named variable
 separated by spaces.  A variable with zero elements yields the empty string.
 .HP
 .BI `{ command }
+.HP
+.BI ` "split " { command }
 .br
 .I rc
 executes the
@@ -245,6 +247,8 @@ If
 .B $ifs
 is not otherwise set, its value is
 .BR "'\ \et\en'" .
+In the second form of the command, split is used instead of
+.BR $ifs .
 .HP
 .BI <{ command }
 .HP
index 9ec637988bd96cb5e725107379af79e3405cf5ef..927273275f5dfc7141ae7d7affeaca3bc64dec9a 100644 (file)
@@ -125,9 +125,19 @@ outcode(tree *t, int eflag)
                emitf(Xconc);
                break;
        case '`':
+               emitf(Xmark);
+               if(c0){
+                       outcode(c0, 0);
+                       emitf(Xglob);
+               } else {
+                       emitf(Xmark);
+                       emitf(Xword);
+                       emits(estrdup("ifs"));
+                       emitf(Xdol);
+               }
                emitf(Xbackq);
                p = emiti(0);
-               outcode(c0, 0);
+               outcode(c1, 0);
                emitf(Xexit);
                stuffdot(p);
                break;
index dd194db8763302b5b37106895dbb32d68da08ba0..10cb769352bd2ae1f34f7809e067148653795beb 100644 (file)
@@ -208,7 +208,7 @@ main(int argc, char *argv[])
  * Xappend(file)[fd]                   open file to append
  * Xassign(name, val)                  assign val to name
  * Xasync{... Xexit}                   make thread for {}, no wait
- * Xbackq{... Xreturn}                 make thread for {}, push stdout
+ * Xbackq(split){... Xreturn}          make thread for {}, push stdout
  * Xbang                               complement condition
  * Xcase(pat, value){...}              exec code on match, leave (value) on
  *                                     stack
index 7f359423b6f6dbd2c4d9a2be14b5c262b88f23e4..ad5a802986d82d15b2f303d5c098a001264e5a15 100644 (file)
@@ -85,10 +85,11 @@ Xbackq(void)
        int pfd[2];
        char *s, *wd, *ewd, *stop;
        struct io *f;
-       var *ifs = vlook("ifs");
        word *v, *nextv;
 
-       stop = ifs->val? ifs->val->word: "";
+       stop = "";
+       if(runq->argv && runq->argv->words)
+               stop = runq->argv->words->word;
        if(pipe(pfd)<0){
                Xerror("can't make pipe");
                return;
@@ -135,6 +136,7 @@ Xbackq(void)
                free(wd);
                closeio(f);
                Waitfor(pid, 0);
+               poplist();      /* ditch split in "stop" */
                /* v points to reversed arglist -- reverse it onto argv */
                while(v){
                        nextv = v->next;
index 8caf60a28cc0a0ff2babe23be79919f0942304c1..88989237009ccf58001cb4251e3cde0941922457 100644 (file)
@@ -32,7 +32,7 @@ pcmd(io *f, tree *t)
        break;
        case '^':       pfmt(f, "%t^%t", c0, c1);
        break;
-       case '`':       pfmt(f, "`%t", c0);
+       case '`':       pfmt(f, "`%t%t", c0, c1);
        break;
        case ANDAND:    pfmt(f, "%t && %t", c0, c1);
        break;
index c7de3531385d2618b2a080252c850c3f21633e4e..051c9e88ed830c2ac58a656455217656b8c9fd16 100644 (file)
@@ -83,7 +83,8 @@ comword: '$' word             {$$=tree1('$', $2);}
 |      '"' word                {$$=tree1('"', $2);}
 |      COUNT word              {$$=tree1(COUNT, $2);}
 |      WORD
-|      '`' brace               {$$=tree1('`', $2);}
+|      '`' brace               {$$=tree2('`', (struct tree*)0, $2);}
+|      '`' word brace          {$$=tree2('`', $2, $3);}
 |      '(' words ')'           {$$=tree1(PAREN, $2);}
 |      REDIR brace             {$$=mung1($1, $2); $$->type=PIPEFD;}
 keyword: FOR|IN|WHILE|IF|NOT|TWIDDLE|BANG|SUBSHELL|SWITCH|FN