rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit a11a8d312e531231ed4d284f3cd129ccf2de2a43
parent 38da49b97b529815045c23cfef4820a56179eebb
Author: tjg <tjg>
Date:   Tue,  2 Oct 2001 13:00:35 +0000

  Bug: it's no longer possible to use parentheses to sneak a word that
  needs quoting past the "quoting detector", so `fn x { echo $(x.y) }'
  now works both in the current rc and its descendants.

Diffstat:
Mfootobar.c | 10++++++----
Mlex.c | 6++++--
Mrc.h | 2+-
3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/footobar.c b/footobar.c @@ -46,7 +46,9 @@ static int defaultfd(int op) { /* convert a function in Node * form into something rc can parse (and humans can read?) */ static bool Tconv(Format *f, int ignore) { + bool dollar = f->flags & FMT_altform; Node *n = va_arg(f->args, Node *); + if (n == NULL) { fmtprint(f, "()"); return FALSE; @@ -72,7 +74,7 @@ static bool Tconv(Format *f, int ignore) { case nForin: fmtprint(f, "for(%T in %T)%T", n->u[0].p, n->u[1].p, n->u[2].p); break; case nVarsub: fmtprint(f, "$%T(%T)", n->u[0].p, n->u[1].p); break; case nWord: - fmtprint(f, quotep(n->u[0].s) ? "%#S" : "%S", n->u[0].s); + fmtprint(f, quotep(n->u[0].s, dollar) ? "%#S" : "%S", n->u[0].s); break; case nCount: case nFlat: case nVar: { char *lp = "", *rp = ""; @@ -83,9 +85,9 @@ static bool Tconv(Format *f, int ignore) { switch (n->type) { default: panic("this can't happen"); break; - case nCount: fmtprint(f, "$#%s%T%s", lp, n0, rp); break; - case nFlat: fmtprint(f, "$^%s%T%s", lp, n0, rp); break; - case nVar: fmtprint(f, "$%s%T%s", lp, n0, rp); break; + case nCount: fmtprint(f, "$#%s%#T%s", lp, n0, rp); break; + case nFlat: fmtprint(f, "$^%s%#T%s", lp, n0, rp); break; + case nVar: fmtprint(f, "$%s%#T%s", lp, n0, rp); break; } break; } diff --git a/lex.c b/lex.c @@ -70,11 +70,13 @@ enum filedescriptors { }; /* does this string require quoting? */ -extern bool quotep(char *s) { +extern bool quotep(char *s, bool dollar) { unsigned char c; + const char *meta; + meta = dollar ? dnw : nw; while ((c = *s++)) - if (nw[c]) + if (meta[c]) return TRUE; return FALSE; } diff --git a/rc.h b/rc.h @@ -280,7 +280,7 @@ extern bool rcrc; /* lex.c */ -extern bool quotep(char *); +extern bool quotep(char *, bool); extern int yylex(void); extern void inityy(void); extern void yyerror(const char *);