Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make(1): extract ParseVarname from Var_Parse
details: https://anonhg.NetBSD.org/src/rev/e2da62105dab
branches: trunk
changeset: 938643:e2da62105dab
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Sep 12 19:24:59 2020 +0000
description:
make(1): extract ParseVarname from Var_Parse
This was an easy part since it affects only a few variables. 250 lines
for a single function is still quite a lot, so further refactorings will
follow.
diffstat:
usr.bin/make/var.c | 67 ++++++++++++++++++++++++++++++-----------------------
1 files changed, 38 insertions(+), 29 deletions(-)
diffs (108 lines):
diff -r 56ab2894c874 -r e2da62105dab usr.bin/make/var.c
--- a/usr.bin/make/var.c Sat Sep 12 19:15:20 2020 +0000
+++ b/usr.bin/make/var.c Sat Sep 12 19:24:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.500 2020/09/12 19:15:20 rillig Exp $ */
+/* $NetBSD: var.c,v 1.501 2020/09/12 19:24:59 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.500 2020/09/12 19:15:20 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.501 2020/09/12 19:24:59 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: var.c,v 1.500 2020/09/12 19:15:20 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.501 2020/09/12 19:24:59 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -3302,6 +3302,38 @@
return FALSE;
}
+/* Skip to the end character or a colon, whichever comes first. */
+static void
+ParseVarname(const char **pp, char startc, char endc,
+ GNode *ctxt, VarEvalFlags eflags, Buffer *namebuf)
+{
+ const char *p = *pp;
+ int depth = 1;
+
+ while (*p != '\0') {
+ /* Track depth so we can spot parse errors. */
+ if (*p == startc)
+ depth++;
+ if (*p == endc) {
+ if (--depth == 0)
+ break;
+ }
+ if (*p == ':' && depth == 1)
+ break;
+ /* A variable inside a variable, expand. */
+ if (*p == '$') {
+ void *freeIt;
+ const char *rval = Var_Parse(&p, ctxt, eflags, &freeIt);
+ Buf_AddStr(namebuf, rval);
+ free(freeIt);
+ } else {
+ Buf_AddByte(namebuf, *p);
+ p++;
+ }
+ }
+ *pp = p;
+}
+
/*-
*-----------------------------------------------------------------------
* Var_Parse --
@@ -3427,7 +3459,6 @@
}
} else {
Buffer namebuf; /* Holds the variable name */
- int depth;
size_t namelen;
char *varname;
@@ -3435,31 +3466,9 @@
Buf_Init(&namebuf, 0);
- /*
- * Skip to the end character or a colon, whichever comes first.
- */
- depth = 1;
- for (p = start + 2; *p != '\0';) {
- /* Track depth so we can spot parse errors. */
- if (*p == startc)
- depth++;
- if (*p == endc) {
- if (--depth == 0)
- break;
- }
- if (*p == ':' && depth == 1)
- break;
- /* A variable inside a variable, expand. */
- if (*p == '$') {
- void *freeIt;
- const char *rval = Var_Parse(&p, ctxt, eflags, &freeIt);
- Buf_AddStr(&namebuf, rval);
- free(freeIt);
- } else {
- Buf_AddByte(&namebuf, *p);
- p++;
- }
- }
+ p = start + 2;
+ ParseVarname(&p, startc, endc, ctxt, eflags, &namebuf);
+
if (*p == ':') {
haveModifier = TRUE;
} else if (*p == endc) {
Home |
Main Index |
Thread Index |
Old Index