Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: '<<-' here-documents oddity with line continuation



Op 09-02-18 om 08:01 schreef Martijn Dekker:
> In the next few days I hope to submit a patch that fixes both issues.
> 
> Meanwhile I would welcome opinions whether either or both of these
> issues should be fixed unconditionally, or in emulation only -- and, if
> the latter, what shell option to attach it to. POSIX_STRINGS maybe?

Here's a fairly trivial concept patch. I believe this makes zsh
here-documents act like other POSIX shells. If either or both fixes need
to be conditional upon emulation, an extra call to isset() should suffice.

- M.

diff --git a/Src/exec.c b/Src/exec.c
index c39680d..ca04b05 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4351,7 +4351,7 @@ char *
 gethere(char **strp, int typ)
 {
     char *buf;
-    int bsiz, qt = 0, strip = 0;
+    int bsiz, qt = 0, strip = 0, linecont = 0;
     char *s, *t, *bptr, c;
     char *str = *strp;

@@ -4372,7 +4372,7 @@ gethere(char **strp, int typ)
     for (;;) {
 	t = bptr;

-	while ((c = hgetc()) == '\t' && strip)
+	while ((c = hgetc()) == '\t' && strip && !linecont)
 	    ;
 	for (;;) {
 	    if (bptr == buf + bsiz) {
@@ -4393,12 +4393,14 @@ gethere(char **strp, int typ)
 	    c = hgetc();
 	}
 	*bptr = '\0';
-	if (!strcmp(t, str))
+	if (!strcmp(t, str) && !linecont)
 	    break;
 	if (lexstop) {
 	    t = bptr;
 	    break;
 	}
+	if (!qt)
+	    linecont = (bptr > t && *(bptr - 1) == '\\');
 	*bptr++ = '\n';
     }
     *t = '\0';



Messages sorted by: Reverse Date, Date, Thread, Author