summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/sh/parser.c17
-rw-r--r--tools/regression/bin/sh/parser/heredoc4.044
-rw-r--r--tools/regression/bin/sh/parser/heredoc5.056
3 files changed, 113 insertions, 4 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index 29ccd83..c9305b3 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -973,6 +973,8 @@ parsebackq(char *out, struct nodelist **pbqlist,
const int bq_startlinno = plinno;
char *volatile ostr = NULL;
struct parsefile *const savetopfile = getcurrentfile();
+ struct heredoc *const saveheredoclist = heredoclist;
+ struct heredoc *here;
str = NULL;
if (setjmp(jmploc.loc)) {
@@ -981,6 +983,7 @@ parsebackq(char *out, struct nodelist **pbqlist,
ckfree(str);
if (ostr)
ckfree(ostr);
+ heredoclist = saveheredoclist;
handler = savehandler;
if (exception == EXERROR) {
startlinno = bq_startlinno;
@@ -995,6 +998,7 @@ parsebackq(char *out, struct nodelist **pbqlist,
memcpy(str, stackblock(), savelen);
}
handler = &jmploc;
+ heredoclist = NULL;
INTON;
if (oldstyle) {
/* We must read until the closing backquote, giving special
@@ -1091,21 +1095,26 @@ done:
while (stackblocksize() <= savelen)
growstackblock();
STARTSTACKSTR(out);
+ INTOFF;
if (str) {
memcpy(out, str, savelen);
STADJUST(savelen, out);
- INTOFF;
ckfree(str);
str = NULL;
- INTON;
}
if (ostr) {
- INTOFF;
ckfree(ostr);
ostr = NULL;
- INTON;
+ }
+ here = saveheredoclist;
+ if (here != NULL) {
+ while (here->next != NULL)
+ here = here->next;
+ here->next = heredoclist;
+ heredoclist = saveheredoclist;
}
handler = savehandler;
+ INTON;
if (quoted)
USTPUTC(CTLBACKQ | CTLQUOTE, out);
else
diff --git a/tools/regression/bin/sh/parser/heredoc4.0 b/tools/regression/bin/sh/parser/heredoc4.0
new file mode 100644
index 0000000..fa3af5f
--- /dev/null
+++ b/tools/regression/bin/sh/parser/heredoc4.0
@@ -0,0 +1,44 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+ if ! eval "[ $* ]"; then
+ echo "Failed: $*"
+ : $((failures += 1))
+ fi
+}
+
+f() {
+ cat <<EOF && echo `echo bar`
+foo
+EOF
+}
+check '"`f`" = "foo
+bar"'
+
+f() {
+ cat <<EOF && echo $(echo bar)
+foo
+EOF
+}
+check '"$(f)" = "foo
+bar"'
+
+f() {
+ echo `echo bar` && cat <<EOF
+foo
+EOF
+}
+check '"`f`" = "bar
+foo"'
+
+f() {
+ echo $(echo bar) && cat <<EOF
+foo
+EOF
+}
+check '"$(f)" = "bar
+foo"'
+
+exit $((failures != 0))
diff --git a/tools/regression/bin/sh/parser/heredoc5.0 b/tools/regression/bin/sh/parser/heredoc5.0
new file mode 100644
index 0000000..84b0eb2
--- /dev/null
+++ b/tools/regression/bin/sh/parser/heredoc5.0
@@ -0,0 +1,56 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+ if ! eval "[ $* ]"; then
+ echo "Failed: $*"
+ : $((failures += 1))
+ fi
+}
+
+f() {
+ cat <<EOF && echo `cat <<EOF
+bar
+EOF
+`
+foo
+EOF
+}
+check '"`f`" = "foo
+bar"'
+
+f() {
+ cat <<EOF && echo $(cat <<EOF
+bar
+EOF
+)
+foo
+EOF
+}
+check '"$(f)" = "foo
+bar"'
+
+f() {
+ echo `cat <<EOF
+bar
+EOF
+` && cat <<EOF
+foo
+EOF
+}
+check '"`f`" = "bar
+foo"'
+
+f() {
+ echo $(cat <<EOF
+bar
+EOF
+) && cat <<EOF
+foo
+EOF
+}
+check '"$(f)" = "bar
+foo"'
+
+exit $((failures != 0))
OpenPOWER on IntegriCloud