about summary refs log tree commit diff
path: root/Src/exec.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2010-09-14 14:46:26 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2010-09-14 14:46:26 +0000
commitf1495f5099073e2e4896c13e28e8d936b4979fd3 (patch)
treed793cce372b9e1c4435db4174867c8a4cb37cb0c /Src/exec.c
parent3b6b4982b9a61cb84888e8eba7200637fc3b3c12 (diff)
downloadzsh-f1495f5099073e2e4896c13e28e8d936b4979fd3.tar.gz
zsh-f1495f5099073e2e4896c13e28e8d936b4979fd3.tar.xz
zsh-f1495f5099073e2e4896c13e28e8d936b4979fd3.zip
28259: Finally fix some ancient problems with here-documents
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Src/exec.c b/Src/exec.c
index e866639b9..f50209a7a 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3449,11 +3449,12 @@ closem(int how)
 
 /**/
 char *
-gethere(char *str, int typ)
+gethere(char **strp, int typ)
 {
     char *buf;
     int bsiz, qt = 0, strip = 0;
     char *s, *t, *bptr, c;
+    char *str = *strp;
 
     for (s = str; *s; s++)
 	if (inull(*s)) {
@@ -3467,6 +3468,7 @@ gethere(char *str, int typ)
 	while (*str == '\t')
 	    str++;
     }
+    *strp = str;
     bptr = buf = zalloc(bsiz = 256);
     for (;;) {
 	t = bptr;
@@ -3500,8 +3502,6 @@ gethere(char *str, int typ)
 	}
 	*bptr++ = '\n';
     }
-    if (t > buf && t[-1] == '\n')
-	t--;
     *t = '\0';
     if (!qt) {
 	int ef = errflag;
@@ -3529,7 +3529,15 @@ getherestr(struct redir *fn)
     singsub(&t);
     untokenize(t);
     unmetafy(t, &len);
-    t[len++] = '\n';
+    /*
+     * For real here-strings we append a newline, as if the
+     * string given was a complete command line.
+     *
+     * For here-strings from here documents, we use the original
+     * text exactly.
+     */
+    if (!(fn->flags & REDIRF_FROM_HEREDOC))
+	t[len++] = '\n';
     if ((fd = gettempfile(NULL, 1, &s)) < 0)
 	return -1;
     write_loop(fd, t, len);