> > this is one thing that byron understood in his version of rc.
> > he had
> >     x=``ifs {cmd}
> > the `` was required since `singleton was allowed in his version.
> > i think that one could just extend the grammar to allow
> >     x=`ifs {cmd}
> > and i think it would be even better if it were
> >     x=`splitchars {cmd}
> > so ifs is never set.
> 
> I don't quite understand the first two examples. Do they set ifs only
> within the {} ? I guess that risks breaking any scripts you might want
> to run as cmd, so yeah, the 3rd looks good.

i implemented the 3d this evening in a compatable way with
Traditional Rc.  there's an argument that it's not completely
necessary, but it's so easy to make a mistake and type this

        ifs=$something x=`{something}

leaving ifs set rather than the intended

        ifs=$something {x=`{something}}

i also don't see a argument against making the splitting string
local to the backq.  i don't believe i've ever written a script that
uses the fact that ifs can be set once and reused with it's nonstandard
value.

- erik

----

; 8.out
broken! x=`{echo a b c d}
broken! whatis x
x=(a b c d)
broken! x=`/$nl {pwd}
broken! whatis x
x=(usr quanstro src rc)
broken! ifs=/$nl {x=`{pwd}}
broken! whatis x
x=(usr quanstro src rc)

broken! diffy -c *.[chy]
diff -c /n/dump/2011/0429/usr/quanstro/src/rc/code.c code.c
/n/dump/2011/0429/usr/quanstro/src/rc/code.c:145,158 - code.c:145,167
                emitf(Xconc);
                break;
        case '`':
+               emitf(Xmark);
+               if(c0==0){
+                       emitf(Xword);
+                       emits(strdup("ifs"));
+                       emitf(Xdol);
+               }else{
+                       outcode(c0, 0, brkaddr);
+                       emitf(Xglob);
+               }
                emitf(Xbackq);
                if(havefork){
                        p = emiti(0);
-                       outcode(c0, 0, brkaddr);
+                       outcode(c1, 0, brkaddr);
                        emitf(Xexit);
                        stuffdot(p);
                } else
-                       emits(fnstr(c0));
+                       emits(fnstr(c1));
                break;
        case ANDAND:
                outcode(c0, 0, brkaddr);
diff -c /n/dump/2011/0429/usr/quanstro/src/rc/havefork.c havefork.c
/n/dump/2011/0429/usr/quanstro/src/rc/havefork.c:83,93 - havefork.c:83,92
        int pfd[2];
        char *s, *wd, *ewd, *stop;
        struct io *f;
-       var *ifs = vlook("ifs");
        word *v, *nextv;
        Rune r;
  
-       stop = ifs->val? ifs->val->word: "";
+       stop = runq->argv->words->word;
        if(pipe(pfd)<0){
                Xerror("can't make pipe");
                return;
/n/dump/2011/0429/usr/quanstro/src/rc/havefork.c:140,145 - havefork.c:139,145
                        efree(wd);
                closeio(f);
                Waitfor(pid, 0);
+               popword();      /* ditch split in "stop" */
                /* v points to reversed arglist -- reverse it onto argv */
                while(v){
                        nextv = v->next;
/n/dump/2011/0429/usr/quanstro/src/rc/pcmd.c:32,38 - pcmd.c:32,38
        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;
diff -c /n/dump/2011/0429/usr/quanstro/src/rc/syn.y syn.y
/n/dump/2011/0429/usr/quanstro/src/rc/syn.y:96,102 - syn.y:96,103
  |     '"' word                {$$=tree1('"', $2);}
  |     COUNT word              {$$=tree1(COUNT, $2);}
  |     WORD
- |     '`' brace               {$$=tree1('`', $2);}
+ |     '`' brace               {$$=tree2('`', nil, $2);}
+ |     '`' word brace          {$$=tree2('`', $2, $3);}
  |     '(' wordsnl nl ')'              {$$=tree1(PAREN, $2);}
  |     REDIR brace             {$$=mung1($1, $2); $$->type=PIPEFD;}
  keyword: FOR|IN|WHILE|IF|NOT|TWIDDLE|BANG|SUBSHELL|SWITCH|FN|BREAK


Reply via email to