Source-Changes-HG archive

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

[src/trunk]: src/bin/sh Allow a heredoc to be positioned outside a `` command...



details:   https://anonhg.NetBSD.org/src/rev/c43d6459e2b1
branches:  trunk
changeset: 814695:c43d6459e2b1
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Apr 04 12:39:08 2016 +0000

description:
Allow a heredoc to be positioned outside a `` command substitution.
POSIX just says "here docs begin after the next newline [token]".
Nothing about "provided it is inside any `` the redirect operator
appears in...    As best I can tell, NetBSD now has the only shell to
handle this "correctly" (which raises the question whether it is
correct - but if not, only erroneous scripts are affected.)
This is required by some (probably broken) autoconfigure related
scripts. (from kre@)

diffstat:

 bin/sh/parser.c |  18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diffs (67 lines):

diff -r 3c784d22b05e -r c43d6459e2b1 bin/sh/parser.c
--- a/bin/sh/parser.c   Mon Apr 04 12:05:40 2016 +0000
+++ b/bin/sh/parser.c   Mon Apr 04 12:39:08 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parser.c,v 1.115 2016/03/31 23:11:05 christos Exp $    */
+/*     $NetBSD: parser.c,v 1.116 2016/04/04 12:39:08 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.115 2016/03/31 23:11:05 christos Exp $");
+__RCSID("$NetBSD: parser.c,v 1.116 2016/04/04 12:39:08 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -81,6 +81,7 @@
        union node *here;               /* redirection node */
        char *eofmark;          /* string indicating end of input */
        int striptabs;          /* if set, strip leading tabs */
+       int startline;          /* line number where << seen */
 };
 
 
@@ -133,6 +134,7 @@
 parsecmd(int interact)
 {
        int t;
+       union node *n;
 
        tokpushback = 0;
        doprompt = interact;
@@ -147,7 +149,11 @@
        if (t == TNL)
                return NULL;
        tokpushback++;
-       return list(1, 0);
+       n = list(1, 0);
+       if (heredoclist)
+               error("%d: Here document (<<%s) expected but not present",
+                       heredoclist->startline, heredoclist->eofmark);
+       return n;
 }
 
 
@@ -206,10 +212,7 @@
                                return n1;
                        break;
                case TEOF:
-                       if (heredoclist)
-                               readheredocs();
-                       else
-                               pungetc();      /* push back EOF on input */
+                       pungetc();      /* push back EOF on input */
                        return n1;
                default:
                        if (nlflag || erflag)
@@ -1407,6 +1410,7 @@
                        np->type = NHERE;
                        heredoc = stalloc(sizeof(struct heredoc));
                        heredoc->here = np;
+                       heredoc->startline = plinno;
                        if ((c = pgetc()) == '-') {
                                heredoc->striptabs = 1;
                        } else {



Home | Main Index | Thread Index | Old Index