From: Martijn Dekker <martijn@inlv.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: '<<-' here-documents oddity with line continuation
Date: Fri, 9 Feb 2018 08:58:27 +0100 [thread overview]
Message-ID: <51ac4bde-cc2f-b26b-228c-136d4cd5df91@inlv.org> (raw)
In-Reply-To: <3216ee27-0c11-013d-3b32-55c8dc8587c3@inlv.org>
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';
next prev parent reply other threads:[~2018-02-09 7:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-03 17:39 Martijn Dekker
2018-02-09 7:01 ` Martijn Dekker
2018-02-09 7:58 ` Martijn Dekker [this message]
2018-02-09 9:24 ` Peter Stephenson
2018-02-09 15:27 ` Stephane Chazelas
2018-02-09 16:07 ` Martijn Dekker
2018-02-09 18:19 ` Martijn Dekker
2018-02-12 10:07 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51ac4bde-cc2f-b26b-228c-136d4cd5df91@inlv.org \
--to=martijn@inlv.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).