From b6251bff913972b5dfb421813fe97a5bfff3627f Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 18 Nov 2018 04:56:48 +0100 Subject: 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. --- sys/src/cmd/rc/code.c | 4 +++- sys/src/cmd/rc/exec.c | 18 +++++++++++------- sys/src/cmd/rc/exec.h | 2 +- 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 @@ -95,9 +95,11 @@ outcode(tree *t, int eflag) emitf(Xdol); 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 -- cgit v1.2.3