Module Name: src
Committed By: rillig
Date: Mon Jan 25 19:10:57 UTC 2021
Modified Files:
src/usr.bin/make: for.c
Log Message:
make(1): extract ForLoop_New to separate function
To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/usr.bin/make/for.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.136 src/usr.bin/make/for.c:1.137
--- src/usr.bin/make/for.c:1.136 Mon Jan 25 19:05:39 2021
+++ src/usr.bin/make/for.c Mon Jan 25 19:10:57 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: for.c,v 1.136 2021/01/25 19:05:39 rillig Exp $ */
+/* $NetBSD: for.c,v 1.137 2021/01/25 19:10:57 rillig Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
@@ -58,9 +58,8 @@
#include "make.h"
/* "@(#)for.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: for.c,v 1.136 2021/01/25 19:05:39 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.137 2021/01/25 19:10:57 rillig Exp $");
-static int forLevel = 0; /* Nesting level */
/* One of the variables to the left of the "in" in a .for loop. */
typedef struct ForVar {
@@ -80,14 +79,25 @@ typedef struct ForLoop {
unsigned int sub_next; /* Where to continue iterating */
} ForLoop;
+
static ForLoop *accumFor; /* Loop being accumulated */
+static int forLevel = 0; /* Nesting level */
-static void
-ForLoop_AddVar(ForLoop *f, const char *name, size_t len)
+
+static ForLoop *
+ForLoop_New(void)
{
- ForVar *var = Vector_Push(&f->vars);
- var->name = bmake_strldup(name, len);
- var->nameLen = len;
+ ForLoop *f = bmake_malloc(sizeof *f);
+
+ Buf_Init(&f->body);
+ Vector_Init(&f->vars, sizeof(ForVar));
+ f->items.words = NULL;
+ f->items.freeIt = NULL;
+ Buf_Init(&f->curBody);
+ f->short_var = FALSE;
+ f->sub_next = 0;
+
+ return f;
}
static void
@@ -107,6 +117,14 @@ ForLoop_Free(ForLoop *f)
free(f);
}
+static void
+ForLoop_AddVar(ForLoop *f, const char *name, size_t len)
+{
+ ForVar *var = Vector_Push(&f->vars);
+ var->name = bmake_strldup(name, len);
+ var->nameLen = len;
+}
+
static Boolean
IsFor(const char *p)
{
@@ -154,14 +172,7 @@ For_Eval(const char *line)
* we found a for loop, and now we are going to parse it.
*/
- f = bmake_malloc(sizeof *f);
- Buf_Init(&f->body);
- Vector_Init(&f->vars, sizeof(ForVar));
- f->items.words = NULL;
- f->items.freeIt = NULL;
- Buf_Init(&f->curBody);
- f->short_var = FALSE;
- f->sub_next = 0;
+ f = ForLoop_New();
/* Grab the variables. Terminate on "in". */
for (;;) {