From d1688ca54177882828624cb5abcb3e2d727ad39f Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Sat, 11 Mar 2000 00:11:02 +0000 Subject: zsh-workers/10059 --- Src/builtin.c | 10 +++++----- Src/lex.c | 5 ++--- Src/parse.c | 36 ++++++++++++++++++++++++++---------- Src/text.c | 7 ++++++- Src/zsh.h | 3 ++- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/Src/builtin.c b/Src/builtin.c index 60595c3bd..90ca5133c 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -1816,17 +1816,17 @@ bin_typeset(char *name, char **argv, char *ops, int func) /* Sanity checks on the options. Remove conficting options. */ if (on & PM_FFLOAT) { - off |= PM_RIGHT_B | PM_LEFT | PM_RIGHT_Z | PM_UPPER | PM_ARRAY - | PM_INTEGER | PM_EFLOAT; + off |= PM_RIGHT_B | PM_LEFT | PM_RIGHT_Z | PM_UPPER | PM_ARRAY | + PM_HASHED | PM_INTEGER | PM_EFLOAT; /* Allow `float -F' to work even though float sets -E by default */ on &= ~PM_EFLOAT; } if (on & PM_EFLOAT) - off |= PM_RIGHT_B | PM_LEFT | PM_RIGHT_Z | PM_UPPER | PM_ARRAY - | PM_INTEGER | PM_FFLOAT; + off |= PM_RIGHT_B | PM_LEFT | PM_RIGHT_Z | PM_UPPER | PM_ARRAY | + PM_HASHED | PM_INTEGER | PM_FFLOAT; if (on & PM_INTEGER) off |= PM_RIGHT_B | PM_LEFT | PM_RIGHT_Z | PM_UPPER | PM_ARRAY | - PM_EFLOAT | PM_FFLOAT; + PM_HASHED | PM_EFLOAT | PM_FFLOAT; if (on & PM_LEFT) off |= PM_RIGHT_B | PM_INTEGER | PM_EFLOAT | PM_FFLOAT; if (on & PM_RIGHT_B) diff --git a/Src/lex.c b/Src/lex.c index ce245429d..3f3c0f9d2 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -339,10 +339,9 @@ yylex(void) char *name; hwbegin(0); - cmdpush(WC_REDIR_TYPE(*(hdocs->pc)) == HEREDOC ? - CS_HEREDOC : CS_HEREDOCD); + cmdpush(hdocs->type == HEREDOC ? CS_HEREDOC : CS_HEREDOCD); STOPHIST - name = gethere(hdocs->str, WC_REDIR_TYPE(*hdocs->pc)); + name = gethere(hdocs->str, hdocs->type); ALLOWHIST cmdpop(); hwend(); diff --git a/Src/parse.c b/Src/parse.c index d4bde90e9..73ed40e2f 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -233,6 +233,18 @@ Eccstr ecstrs; /**/ int ecsoffs, ecssub, ecnfunc; +/* Adjust pointers in here-doc structs. */ + +static void +ecadjusthere(int p, int d) +{ + struct heredocs *h; + + for (h = hdocs; h; h = h->next) + if (h->pc >= p) + h->pc += d; +} + /* Insert n free code-slots at position p. */ static void @@ -250,6 +262,7 @@ ecispace(int p, int n) if ((m = ecused - p) > 0) memmove(ecbuf + p + n, ecbuf + p, m * sizeof(wordcode)); ecused += n; + ecadjusthere(p, n); } /* Add one wordcode. */ @@ -278,6 +291,7 @@ ecdel(int p) if (n > 0) memmove(ecbuf + p, ecbuf + p + 1, n * sizeof(wordcode)); ecused--; + ecadjusthere(p, -1); } /* Build the wordcode for a string. */ @@ -682,7 +696,6 @@ par_pline(int *complex) for (r = p + 1; wc_code(ecbuf[r]) == WC_REDIR; r += 3); ecispace(r, 3); - p += 3; ecbuf[r] = WCB_REDIR(MERGEOUT); ecbuf[r + 1] = 2; ecbuf[r + 2] = ecstrcode("1"); @@ -690,6 +703,8 @@ par_pline(int *complex) *complex = 1; cmdpush(CS_ERRPIPE); yylex(); + while (tok == SEPER) + yylex(); ecbuf[p] = WCB_PIPE(WC_PIPE_MID, (line >= 0 ? line + 1 : 0)); ecispace(p + 1, 1); ecbuf[p + 1] = ecused - 1 - p; @@ -1577,12 +1592,6 @@ par_redir(int *rp) /* <<[-] name */ struct heredocs **hd; - for (hd = &hdocs; *hd; hd = &(*hd)->next); - *hd = zalloc(sizeof(struct heredocs)); - (*hd)->next = NULL; - (*hd)->pc = ecbuf + r; - (*hd)->str = tokstr; - /* If we ever need more than three codes (or less), we have to change * the factors in par_cmd() and par_simple(), too. */ ecispace(r, 3); @@ -1590,6 +1599,13 @@ par_redir(int *rp) ecbuf[r] = WCB_REDIR(type); ecbuf[r + 1] = fd1; + for (hd = &hdocs; *hd; hd = &(*hd)->next); + *hd = zalloc(sizeof(struct heredocs)); + (*hd)->next = NULL; + (*hd)->type = type; + (*hd)->pc = r; + (*hd)->str = tokstr; + yylex(); return; } @@ -1626,10 +1642,10 @@ par_redir(int *rp) /**/ void -setheredoc(Wordcode pc, int type, char *str) +setheredoc(int pc, int type, char *str) { - pc[0] = WCB_REDIR(type); - pc[2] = ecstrcode(str); + ecbuf[pc] = WCB_REDIR(type); + ecbuf[pc + 2] = ecstrcode(str); } /* diff --git a/Src/text.c b/Src/text.c index ab052b22a..fbc393e26 100644 --- a/Src/text.c +++ b/Src/text.c @@ -737,7 +737,12 @@ getredirs(LinkList redirs) taddchr('0' + f->fd1); taddstr(fstr[f->type]); taddchr(' '); - taddstr(f->name); + if (f->type == HERESTR) { + taddchr('\''); + taddstr(bslashquote(f->name, NULL, 1)); + taddchr('\''); + } else + taddstr(f->name); taddchr(' '); break; #ifdef DEBUG diff --git a/Src/zsh.h b/Src/zsh.h index 77de1ec61..9a21674a6 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -737,7 +737,8 @@ struct execstack { struct heredocs { struct heredocs *next; - Wordcode pc; + int type; + int pc; char *str; }; -- cgit 1.4.1