diff options
| author | tjg <tjg> | 2001-10-02 13:00:35 +0000 |
|---|---|---|
| committer | Toby Goodwin <toby@paccrat.org> | 2015-05-16 21:23:19 +0100 |
| commit | a11a8d312e531231ed4d284f3cd129ccf2de2a43 (patch) | |
| tree | c007353858e83d5056bf06632a1a2de09a97fdcb | |
| parent | 38da49b97b529815045c23cfef4820a56179eebb (diff) | |
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.
| -rw-r--r-- | footobar.c | 10 | ||||
| -rw-r--r-- | lex.c | 6 | ||||
| -rw-r--r-- | rc.h | 2 |
3 files changed, 11 insertions, 7 deletions
@@ -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; } @@ -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; } @@ -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 *); |