diff --git a/sh.c b/sh.c index 2d5565fc..181a7be2 100644 --- a/sh.c +++ b/sh.c @@ -1100,7 +1100,9 @@ main(int argc, char **argv) if (adrof(STRedit)) unsetv(STRedit); editing = 0; - } + pchrs = ";&\n"; + } else + pchrs = ";&\n#"; intty |= intact; #ifndef convex if (intty || (intact && isatty(SHOUT))) { diff --git a/sh.h b/sh.h index 19bf10d6..c941fa4b 100644 --- a/sh.h +++ b/sh.h @@ -1305,5 +1305,6 @@ extern int filec; #define TEXP_IGNORE 1 /* in ignore, it means to ignore value, just parse */ #define TEXP_NOGLOB 2 /* in ignore, it means not to globone */ +extern char *pchrs; #endif /* _h_sh */ diff --git a/sh.lex.c b/sh.lex.c index 2de265b5..93357eaa 100644 --- a/sh.lex.c +++ b/sh.lex.c @@ -148,8 +148,7 @@ lex(struct wordent *hp) int parsehtime = enterhist; int toolong = 0; - histvalid = 0; - histline.len = 0; + histvalid = histline.len = 0; if (!postcmd_active) btell(&lineloc); @@ -320,8 +319,15 @@ word(int parsehtime) goto ret; case '#': - if (intty || (enterhist && !parsehtime)) + if (enterhist && !parsehtime) break; + if (intty) { + do + Strbuf_append1(&wbuf, c); + while ((c = getC(0)) != CHAR_ERR && c != '\n'); + ungetC('\n'); + goto ret; + } c = 0; h = 0; do { diff --git a/sh.parse.c b/sh.parse.c index 211a1012..c4ed1e05 100644 --- a/sh.parse.c +++ b/sh.parse.c @@ -197,6 +197,8 @@ freenod(struct wordent *p1, struct wordent *p2) #define P_OUT 4 #define P_DIAG 8 +char *pchrs; + /* * syntax * empty @@ -205,9 +207,8 @@ freenod(struct wordent *p1, struct wordent *p2) struct command * syntax(const struct wordent *p1, const struct wordent *p2, int flags) { - while (p1 != p2) - if (any(";&\n", p1->word[0])) + if (any(pchrs, p1->word[0])) p1 = p1->next; else return (syn0(p1, p2, flags)); @@ -273,9 +274,21 @@ syn0(const struct wordent *p1, const struct wordent *p2, int flags) t->t_dcar = t1; t->t_dcdr = syntax(p, p2, flags); return (t); + + case '#': + if (intty) { + struct wordent *p1 = p2->prev; + + p1 = p1->prev = p1->prev->prev; + xfree(p1->next->word); + xfree(p1->next); + p1->next = p2->prev; + goto out; + } default: break; } +out: if (l == 0) return (syn1(p1, p2, flags)); seterror(ERR_TOOMANYLP);