diff options
Diffstat (limited to 'Src')
-rw-r--r-- | Src/parse.c | 6 | ||||
-rw-r--r-- | Src/text.c | 19 | ||||
-rw-r--r-- | Src/zsh.h | 12 |
3 files changed, 29 insertions, 8 deletions
diff --git a/Src/parse.c b/Src/parse.c index af3cba9d3..54543a642 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -1861,7 +1861,7 @@ par_redir(int *rp, char *idstring) void setheredoc(int pc, int type, char *str) { - ecbuf[pc] = WCB_REDIR(type); + ecbuf[pc] = WCB_REDIR(type | REDIR_FROM_HEREDOC_MASK); ecbuf[pc + 2] = ecstrcode(str); } @@ -2409,6 +2409,10 @@ ecgetredirs(Estate s) r->type = WC_REDIR_TYPE(code); r->fd1 = *s->pc++; r->name = ecgetstr(s, EC_DUP, NULL); + if (WC_REDIR_FROM_HEREDOC(code)) + r->flags = REDIRF_FROM_HEREDOC; + else + r->flags = 0; if (WC_REDIR_VARID(code)) r->varid = ecgetstr(s, EC_DUP, NULL); else diff --git a/Src/text.c b/Src/text.c index 593c25776..7fdc5757f 100644 --- a/Src/text.c +++ b/Src/text.c @@ -831,17 +831,22 @@ getredirs(LinkList redirs) taddstr(fstr[f->type]); if (f->type != REDIR_MERGEIN && f->type != REDIR_MERGEOUT) taddchr(' '); - if (f->type == REDIR_HERESTR && !has_token(f->name)) { + if (f->type == REDIR_HERESTR && + (f->flags & REDIRF_FROM_HEREDOC)) { /* * Strings that came from here-documents are converted * to here strings without quotation, so add that - * now. If tokens are already present taddstr() - * will do the right thing (anyway, adding more - * quotes certainly isn't right in that case). + * now. If tokens are present we need to do double quoting. */ - taddchr('\''); - taddstr(quotestring(f->name, NULL, QT_SINGLE)); - taddchr('\''); + if (!has_token(f->name)) { + taddchr('\''); + taddstr(quotestring(f->name, NULL, QT_SINGLE)); + taddchr('\''); + } else { + taddchr('"'); + taddstr(quotestring(f->name, NULL, QT_DOUBLE)); + taddchr('"'); + } } else taddstr(f->name); taddchr(' '); diff --git a/Src/zsh.h b/Src/zsh.h index fb4d51ecd..495f51ad2 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -309,7 +309,10 @@ enum { REDIR_OUTPIPE /* > >(...) */ }; #define REDIR_TYPE_MASK (0x1f) +/* Redir using {var} syntax */ #define REDIR_VARID_MASK (0x20) +/* Mark here-string that came from a here-document */ +#define REDIR_FROM_HEREDOC_MASK (0x40) #define IS_WRITE_FILE(X) ((X)>=REDIR_WRITE && (X)<=REDIR_READWRITE) #define IS_APPEND_REDIR(X) (IS_WRITE_FILE(X) && ((X) & 2)) @@ -550,10 +553,18 @@ struct conddef { #define CONDDEF(name, flags, handler, min, max, condid) \ { NULL, name, flags, handler, min, max, condid, NULL } +/* Flags for redirections */ + +enum { + /* Mark a here-string that came from a here-document */ + REDIRF_FROM_HEREDOC = 1 +}; + /* tree element for redirection lists */ struct redir { int type; + int flags; int fd1, fd2; char *name; char *varid; @@ -744,6 +755,7 @@ struct eccstr { #define WC_REDIR_TYPE(C) ((int)(wc_data(C) & REDIR_TYPE_MASK)) #define WC_REDIR_VARID(C) ((int)(wc_data(C) & REDIR_VARID_MASK)) +#define WC_REDIR_FROM_HEREDOC(C) ((int)(wc_data(C) & REDIR_FROM_HEREDOC_MASK)) #define WCB_REDIR(T) wc_bld(WC_REDIR, (T)) /* Size of redir is 4 words if REDIR_VARID_MASK is set, else 3 */ #define WC_REDIR_WORDS(C) (WC_REDIR_VARID(C) ? 4 : 3) |