Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh After discussions with Jilles Tjoelker (FreeBSD shell...



details:   https://anonhg.NetBSD.org/src/rev/406e62494578
branches:  trunk
changeset: 814621:406e62494578
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Mar 31 23:11:05 2016 +0000

description:
After discussions with Jilles Tjoelker (FreeBSD shell) and
following a suggestion from him, the way the fix to PR bin/50993
was implemented has changed a little.   There are three steps involved
in processing a here document, reading it, parsing it, and then
evaluating it before applying it to the correct file descriptor for
the command to use.  The third of those is not related to this
problem, and has not changed.  The bug was caused by combining the
first two steps into one (and not doing it correctly - which would be
hard that way.)  The fix is to split the first two stages into
separate events.   The original fix moved the 2nd stage (parsing)
to just immediately before the 3rd stage (evaluation.)  Jilles
pointed out some unwanted side effects from doing it that way, and
suggested moving the 2nd stage to immediately after the first.
This commit makes that change.  The effect is to revert the changes
to expand.c and parser.h (which are no longer needed) and simplify
slightly the change to parser.c. (from kre@)

diffstat:

 bin/sh/parser.c |  37 +++++++++++++++----------------------
 bin/sh/parser.h |   3 +--
 2 files changed, 16 insertions(+), 24 deletions(-)

diffs (90 lines):

diff -r 1a84ac82cb75 -r 406e62494578 bin/sh/parser.c
--- a/bin/sh/parser.c   Thu Mar 31 22:49:14 2016 +0000
+++ b/bin/sh/parser.c   Thu Mar 31 23:11:05 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parser.c,v 1.114 2016/03/31 16:12:52 christos Exp $    */
+/*     $NetBSD: parser.c,v 1.115 2016/03/31 23:11:05 christos Exp $    */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c   8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.114 2016/03/31 16:12:52 christos Exp $");
+__RCSID("$NetBSD: parser.c,v 1.115 2016/03/31 23:11:05 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -109,7 +109,7 @@
 STATIC union node *simplecmd(union node **, union node *);
 STATIC union node *makename(void);
 STATIC void parsefname(void);
-STATIC void slurp_heredoc(char *const, int, int);
+STATIC void slurp_heredoc(char *const, const int, const int);
 STATIC void readheredocs(void);
 STATIC int peektoken(void);
 STATIC int readtoken(void);
@@ -759,7 +759,7 @@
  */
 
 STATIC void
-slurp_heredoc(char *const eofmark, int striptabs, int sq)
+slurp_heredoc(char *const eofmark, const int striptabs, const int sq)
 {
        int c;
        char *out;
@@ -852,26 +852,19 @@
                n->narg.text = wordtext;
                n->narg.backquote = backquotelist;
                here->here->nhere.doc = n;
-       }
-}
 
-void
-parse_heredoc(union node *n)
-{
-       if (n->narg.type != NARG)
-               abort();
+               if (here->here->nhere.type == NHERE)
+                       continue;
 
-       if (n->narg.text[0] == '\0')            /* nothing to do */
-               return;
-
-       setinputstring(n->narg.text, 1);
-
-       readtoken1(pgetc(), DQSYNTAX, 1);
-
-       n->narg.text = wordtext;
-       n->narg.backquote = backquotelist;
-
-       popfile();
+               /*
+                * Now "parse" here docs that have unquoted eofmarkers.
+                */
+               setinputstring(wordtext, 1);
+               readtoken1(pgetc(), DQSYNTAX, 1);
+               n->narg.text = wordtext;
+               n->narg.backquote = backquotelist;
+               popfile();
+       }
 }
 
 STATIC int
diff -r 1a84ac82cb75 -r 406e62494578 bin/sh/parser.h
--- a/bin/sh/parser.h   Thu Mar 31 22:49:14 2016 +0000
+++ b/bin/sh/parser.h   Thu Mar 31 23:11:05 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parser.h,v 1.20 2016/03/27 14:39:33 christos Exp $     */
+/*     $NetBSD: parser.h,v 1.21 2016/03/31 23:11:05 christos Exp $     */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -81,6 +81,5 @@
 
 union node *parsecmd(int);
 void fixredir(union node *, const char *, int);
-void parse_heredoc(union node *);
 int goodname(char *);
 const char *getprompt(void *);



Home | Main Index | Thread Index | Old Index