Source-Changes-HG archive

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

[src/trunk]: src/bin/sh Fix value of ${LINENO} in "for" commands.



details:   https://anonhg.NetBSD.org/src/rev/54d89de7c6fa
branches:  trunk
changeset: 1026284:54d89de7c6fa
user:      kre <kre%NetBSD.org@localhost>
date:      Tue Nov 16 11:25:44 2021 +0000

description:
Fix value of ${LINENO} in "for" commands.

This affects (as best I can tell) only uses of ${LINENO} in PS4
when -x is enabled (and perhaps only when the list contains no
expansions).   "for" like "case" (which was already handled) is
special in that it generates trace output before actually executing
any kind of simple command.

diffstat:

 bin/sh/eval.c    |  5 +++--
 bin/sh/nodetypes |  3 ++-
 bin/sh/parser.c  |  5 +++--
 3 files changed, 8 insertions(+), 5 deletions(-)

diffs (69 lines):

diff -r b2639cfae214 -r 54d89de7c6fa bin/sh/eval.c
--- a/bin/sh/eval.c     Tue Nov 16 11:15:26 2021 +0000
+++ b/bin/sh/eval.c     Tue Nov 16 11:25:44 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.c,v 1.183 2021/11/10 15:26:34 kre Exp $   */
+/*     $NetBSD: eval.c,v 1.184 2021/11/16 11:25:44 kre Exp $   */
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c     8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.183 2021/11/10 15:26:34 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.184 2021/11/16 11:25:44 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -469,6 +469,7 @@
 
        loopnest++;
        for (sp = arglist.list ; sp ; sp = sp->next) {
+               line_number = n->nfor.lineno;
                if (xflag) {
                        outxstr(expandstr(ps4val(), line_number));
                        outxstr("for ");
diff -r b2639cfae214 -r 54d89de7c6fa bin/sh/nodetypes
--- a/bin/sh/nodetypes  Tue Nov 16 11:15:26 2021 +0000
+++ b/bin/sh/nodetypes  Tue Nov 16 11:25:44 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: nodetypes,v 1.18 2017/06/08 13:12:17 kre Exp $
+#      $NetBSD: nodetypes,v 1.19 2021/11/16 11:25:44 kre Exp $
 # Copyright (c) 1991, 1993
 #      The Regents of the University of California.  All rights reserved.
 #
@@ -90,6 +90,7 @@
        args      nodeptr               # for var in args
        body      nodeptr               # do body; done
        var       string                # the for variable
+       lineno    int
 
 NCASE ncase                    # a case statement
        type      int
diff -r b2639cfae214 -r 54d89de7c6fa bin/sh/parser.c
--- a/bin/sh/parser.c   Tue Nov 16 11:15:26 2021 +0000
+++ b/bin/sh/parser.c   Tue Nov 16 11:25:44 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parser.c,v 1.174 2021/09/15 18:29:45 kre Exp $ */
+/*     $NetBSD: parser.c,v 1.175 2021/11/16 11:25:44 kre 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.174 2021/09/15 18:29:45 kre Exp $");
+__RCSID("$NetBSD: parser.c,v 1.175 2021/11/16 11:25:44 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -411,6 +411,7 @@
                n1 = stalloc(sizeof(struct nfor));
                n1->type = NFOR;
                n1->nfor.var = wordtext;
+               n1->nfor.lineno = startlinno;
                linebreak();
                if (lasttoken==TWORD && !quoteflag && equal(wordtext,"in")) {
                        app = &ap;



Home | Main Index | Thread Index | Old Index