diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2018-11-18 04:56:48 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2018-11-18 04:56:48 +0100 |
commit | b6251bff913972b5dfb421813fe97a5bfff3627f (patch) | |
tree | 178e82fd271108762b93be4797d77df6d26abb72 /sys/src/cmd/rc | |
parent | 196da4ec6f429683a351312d1f0bcb05847e7f89 (diff) |
rc: implement $"x in terms of Xdol() and new Xqw() instruction
to get $"1 right, remove Xqdol() and instead implement it in
terms of Xdol() instruction and use the new Xqw() instruction
to quote the resulting list.
Diffstat (limited to 'sys/src/cmd/rc')
-rw-r--r-- | sys/src/cmd/rc/code.c | 4 | ||||
-rw-r--r-- | sys/src/cmd/rc/exec.c | 18 | ||||
-rw-r--r-- | sys/src/cmd/rc/exec.h | 2 | ||||
-rw-r--r-- | sys/src/cmd/rc/pfnc.c | 2 |
4 files changed, 16 insertions, 10 deletions
diff --git a/sys/src/cmd/rc/code.c b/sys/src/cmd/rc/code.c index 927273275..4a415bd54 100644 --- a/sys/src/cmd/rc/code.c +++ b/sys/src/cmd/rc/code.c @@ -96,8 +96,10 @@ outcode(tree *t, int eflag) break; case '"': emitf(Xmark); + emitf(Xmark); outcode(c0, eflag); - emitf(Xqdol); + emitf(Xdol); + emitf(Xqw); break; case SUB: emitf(Xmark); diff --git a/sys/src/cmd/rc/exec.c b/sys/src/cmd/rc/exec.c index 4400e45bc..3d1b0ac5a 100644 --- a/sys/src/cmd/rc/exec.c +++ b/sys/src/cmd/rc/exec.c @@ -233,7 +233,7 @@ main(int argc, char *argv[]) * Xdelfn(name) delete function definition * Xdeltraps(names) delete named traps * Xdol(name) get variable value - * Xqdol(name) concatenate variable components + * Xqw(list) quote list, push result * Xdup[i j] dup file descriptor * Xexit rc exits with status * Xfalse{...} execute {} if false @@ -697,18 +697,22 @@ Xdol(void) } void -Xqdol(void) +Xqw(void) { char *s; word *a; - if(count(runq->argv->words)!=1){ - Xerror1("variable name not singleton!"); + + a = runq->argv->words; + if(a && a->next == 0){ + runq->argv->words = 0; + poplist(); + a->next = runq->argv->words; + runq->argv->words = a; return; } - s = Str(runq->argv->words); - a = vlook(s)->val; + s = list2str(a); poplist(); - Pushword(list2str(a)); + Pushword(s); } word* diff --git a/sys/src/cmd/rc/exec.h b/sys/src/cmd/rc/exec.h index cc24dc961..3f07404a4 100644 --- a/sys/src/cmd/rc/exec.h +++ b/sys/src/cmd/rc/exec.h @@ -2,7 +2,7 @@ * Definitions used in the interpreter */ extern void Xappend(void), Xasync(void), Xbackq(void), Xbang(void), Xclose(void); -extern void Xconc(void), Xcount(void), Xdelfn(void), Xdol(void), Xqdol(void), Xdup(void); +extern void Xconc(void), Xcount(void), Xdelfn(void), Xdol(void), Xqw(void), Xdup(void); extern void Xexit(void), Xfalse(void), Xfn(void), Xfor(void), Xglob(void); extern void Xjump(void), Xmark(void), Xmatch(void), Xpipe(void), Xread(void); extern void Xrdwr(void); diff --git a/sys/src/cmd/rc/pfnc.c b/sys/src/cmd/rc/pfnc.c index 846b70bbe..f8505cfc6 100644 --- a/sys/src/cmd/rc/pfnc.c +++ b/sys/src/cmd/rc/pfnc.c @@ -50,7 +50,7 @@ struct{ Xglobs, "Xglobs", Xrdfn, "Xrdfn", Xsimple, "Xsimple", - Xqdol, "Xqdol", + Xqw, "Xqw", 0}; void |