Module Name:    src
Committed By:   rillig
Date:           Fri Jan  7 20:09:58 UTC 2022

Modified Files:
        src/usr.bin/make: for.c nonints.h parse.c

Log Message:
make: eliminate file-scope variable forLevel

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.155 -r1.156 src/usr.bin/make/for.c
cvs rdiff -u -r1.230 -r1.231 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.628 -r1.629 src/usr.bin/make/parse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/for.c
diff -u src/usr.bin/make/for.c:1.155 src/usr.bin/make/for.c:1.156
--- src/usr.bin/make/for.c:1.155	Fri Jan  7 20:04:49 2022
+++ src/usr.bin/make/for.c	Fri Jan  7 20:09:58 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.155 2022/01/07 20:04:49 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.156 2022/01/07 20:09:58 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -58,7 +58,7 @@
 #include "make.h"
 
 /*	"@(#)for.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: for.c,v 1.155 2022/01/07 20:04:49 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.156 2022/01/07 20:09:58 rillig Exp $");
 
 
 typedef struct ForLoop {
@@ -70,7 +70,6 @@ typedef struct ForLoop {
 
 
 static ForLoop *accumFor;	/* Loop being accumulated */
-static int forLevel = 0;	/* Nesting level */
 
 
 static ForLoop *
@@ -224,7 +223,6 @@ For_Eval(const char *line)
 	}
 
 	accumFor = f;
-	forLevel = 1;
 	return 1;
 }
 
@@ -233,7 +231,7 @@ For_Eval(const char *line)
  * Returns false when the matching .endfor is reached.
  */
 bool
-For_Accum(const char *line)
+For_Accum(const char *line, int *forLevel)
 {
 	const char *p = line;
 
@@ -242,12 +240,12 @@ For_Accum(const char *line)
 		cpp_skip_whitespace(&p);
 
 		if (IsEndfor(p)) {
-			DEBUG1(FOR, "For: end for %d\n", forLevel);
-			if (--forLevel <= 0)
+			DEBUG1(FOR, "For: end for %d\n", *forLevel);
+			if (--*forLevel <= 0)
 				return false;
 		} else if (IsFor(p)) {
-			forLevel++;
-			DEBUG1(FOR, "For: new loop %d\n", forLevel);
+			(*forLevel)++;
+			DEBUG1(FOR, "For: new loop %d\n", *forLevel);
 		}
 	}
 

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.230 src/usr.bin/make/nonints.h:1.231
--- src/usr.bin/make/nonints.h:1.230	Fri Jan  7 19:24:27 2022
+++ src/usr.bin/make/nonints.h	Fri Jan  7 20:09:58 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.230 2022/01/07 19:24:27 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.231 2022/01/07 20:09:58 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -118,7 +118,7 @@ void SearchPath_Free(SearchPath *);
 /* for.c */
 struct ForLoop;
 int For_Eval(const char *) MAKE_ATTR_USE;
-bool For_Accum(const char *) MAKE_ATTR_USE;
+bool For_Accum(const char *, int *) MAKE_ATTR_USE;
 void For_Run(int);
 bool For_NextIteration(struct ForLoop *, Buffer *);
 

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.628 src/usr.bin/make/parse.c:1.629
--- src/usr.bin/make/parse.c:1.628	Fri Jan  7 14:03:55 2022
+++ src/usr.bin/make/parse.c	Fri Jan  7 20:09:58 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.628 2022/01/07 14:03:55 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.629 2022/01/07 20:09:58 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -106,7 +106,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.628 2022/01/07 14:03:55 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.629 2022/01/07 20:09:58 rillig Exp $");
 
 /*
  * A file being read.
@@ -2559,6 +2559,7 @@ ParseForLoop(const char *line)
 {
 	int rval;
 	int firstLineno;
+	int forLevel;
 
 	rval = For_Eval(line);
 	if (rval == 0)
@@ -2570,6 +2571,7 @@ ParseForLoop(const char *line)
 	firstLineno = CurFile()->readLines;
 
 	/* Accumulate the loop body until the matching '.endfor'. */
+	forLevel = 1;
 	do {
 		line = ReadLowLevelLine(LK_FOR_BODY);
 		if (line == NULL) {
@@ -2577,7 +2579,7 @@ ParseForLoop(const char *line)
 			    "Unexpected end of file in .for loop");
 			break;
 		}
-	} while (For_Accum(line));
+	} while (For_Accum(line, &forLevel));
 
 	For_Run(firstLineno);
 	return true;

Reply via email to