diff options
author | Peter Stephenson <pws@zsh.org> | 2015-02-19 10:22:40 +0000 |
---|---|---|
committer | Peter Stephenson <pws@zsh.org> | 2015-02-19 10:22:40 +0000 |
commit | 52e938bac954d6d503e180287bcf657187ef8803 (patch) | |
tree | 9ecb73af443d7a2953c39462a3c55ad181ac8cc8 /Src/subst.c | |
parent | 9b21dcada9d678da6d23c7e03c68eca926e3ff3e (diff) | |
download | zsh-52e938bac954d6d503e180287bcf657187ef8803.tar.gz zsh-52e938bac954d6d503e180287bcf657187ef8803.tar.xz zsh-52e938bac954d6d503e180287bcf657187ef8803.zip |
34570: Another nasty command / math substituion thing.
Mark arithmetic substitutions with tokens to make sure the substitution go knows what to do. Before it was guessing by counting the parentheses at the end.
Diffstat (limited to 'Src/subst.c')
-rw-r--r-- | Src/subst.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/Src/subst.c b/Src/subst.c index a2bb6483a..056b12b27 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -195,7 +195,7 @@ stringsubst(LinkList list, LinkNode node, int pf_flags, int asssub) while (!errflag && (c = *str)) { if ((qt = c == Qstring) || c == String) { - if ((c = str[1]) == Inpar) { + if ((c = str[1]) == Inpar || c == Inparmath) { if (!qt) list->list.flags |= LF_ARRAY; str++; @@ -258,6 +258,22 @@ stringsubst(LinkList list, LinkNode node, int pf_flags, int asssub) skipparens(Inpar, Outpar, &str); #endif str--; + } else if (c == Inparmath) { + /* Math substitution of the form $((...)) */ + str[-1] = '\0'; + while (*str != Outparmath && *str) + str++; + if (*str != Outparmath) { + zerr("Failed to find end of math substitution"); + return NULL; + } + str[-1] = '\0'; + if (isset(EXECOPT)) + str = arithsubst(str2 + 2, &str3, str+1); + else + strncpy(str3, str2, 1); + setdata(node, (void *) str3); + continue; } else { endchar = c; *str = '\0'; @@ -266,16 +282,6 @@ stringsubst(LinkList list, LinkNode node, int pf_flags, int asssub) DPUTS(!*str, "BUG: parse error in command substitution"); } *str++ = '\0'; - if (endchar == Outpar && str2[1] == '(' && str[-2] == ')') { - /* Math substitution of the form $((...)) */ - str[-2] = '\0'; - if (isset(EXECOPT)) - str = arithsubst(str2 + 2, &str3, str); - else - strncpy(str3, str2, 1); - setdata(node, (void *) str3); - continue; - } /* It is a command substitution, which will be parsed again * * by the lexer, so we untokenize it first, but we cannot use * |