From 8f01c3796f0fc3bc616125288a2aa7058c442292 Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Thu, 27 Dec 2007 13:54:16 +1100 Subject: [PARSER] Add FAKEEOFMARK for expandstr Previously expandstr used the string "" to indicate that it needs to be treated just like a here-doc except that there is no terminator. However, the string "" is in fact a valid here-doc terminator so now that we deal with it correctly expandstr no longer works in the presence of new-lines in the prompt. This patch introduces the FAKEEOFMARK macro which does not equal any real EOF marker but is distinct from the NULL pointer which is used to indicate non-here-doc contexts. Thanks to Markus Triska for reporting this regression. Signed-off-by: Herbert Xu --- src/parser.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/parser.c b/src/parser.c index 2d20b00..3206328 100644 --- a/src/parser.c +++ b/src/parser.c @@ -64,6 +64,11 @@ +/* Used by expandstr to get here-doc like behaviour. */ +#define FAKEEOFMARK (char *)1 + + + struct heredoc { struct heredoc *next; /* next here document in list */ union node *here; /* redirection node */ @@ -113,6 +118,11 @@ isassignment(const char *p) return *q == '='; } +static inline int realeofmark(const char *eofmark) +{ + return eofmark && eofmark != FAKEEOFMARK; +} + /* * Read and parse a command. Returns NEOF on end of file. (NULL is a @@ -1030,7 +1040,7 @@ endword: */ checkend: { - if (eofmark) { + if (realeofmark(eofmark)) { int markloc; char *p; @@ -1492,7 +1502,7 @@ expandstr(const char *ps) /* XXX Fix (char *) cast. */ setinputstring((char *)ps); - readtoken1(pgetc(), DQSYNTAX, nullstr, 0); + readtoken1(pgetc(), DQSYNTAX, FAKEEOFMARK, 0); popfile(); n.narg.type = NARG; -- cgit 1.4.1