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): split Var_Subst into easily understand...
details: https://anonhg.NetBSD.org/src/rev/8e057ec63204
branches: trunk
changeset: 958154:8e057ec63204
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Dec 27 11:03:00 2020 +0000
description:
make(1): split Var_Subst into easily understandable functions
Extracting the character-level details makes the essence of Var_Subst
visible in the code, which is to iterate over the given text, handling a
few types of tokens.
diffstat:
usr.bin/make/var.c | 68 ++++++++++++++++++++++++++++++-----------------------
1 files changed, 39 insertions(+), 29 deletions(-)
diffs (103 lines):
diff -r 647751b28b1d -r 8e057ec63204 usr.bin/make/var.c
--- a/usr.bin/make/var.c Sun Dec 27 10:53:23 2020 +0000
+++ b/usr.bin/make/var.c Sun Dec 27 11:03:00 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.767 2020/12/27 10:53:23 rillig Exp $ */
+/* $NetBSD: var.c,v 1.768 2020/12/27 11:03:00 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.767 2020/12/27 10:53:23 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.768 2020/12/27 11:03:00 rillig Exp $");
typedef enum VarFlags {
VAR_NONE = 0,
@@ -4177,8 +4177,21 @@
}
static void
-VarSubstNested(const char **pp, Buffer *buf, GNode *ctxt,
- VarEvalFlags eflags, Boolean *inout_errorReported)
+VarSubstDollarDollar(const char **pp, Buffer *res, VarEvalFlags eflags)
+{
+ /*
+ * A dollar sign may be escaped with another dollar
+ * sign.
+ */
+ if (save_dollars && (eflags & VARE_KEEP_DOLLAR))
+ Buf_AddByte(res, '$');
+ Buf_AddByte(res, '$');
+ *pp += 2;
+}
+
+static void
+VarSubstExpr(const char **pp, Buffer *buf, GNode *ctxt,
+ VarEvalFlags eflags, Boolean *inout_errorReported)
{
const char *p = *pp;
const char *nested_p = p;
@@ -4229,6 +4242,22 @@
*pp = p;
}
+/*
+ * Skip as many characters as possible -- either to the end of the string
+ * or to the next dollar sign (variable expression).
+ */
+static void
+VarSubstPlain(const char **pp, Buffer *res)
+{
+ const char *p = *pp;
+ const char *start = p;
+
+ for (p++; *p != '$' && *p != '\0'; p++)
+ continue;
+ Buf_AddBytesBetween(res, start, p);
+ *pp = p;
+}
+
/* Expand all variable expressions like $V, ${VAR}, $(VAR:Modifiers) in the
* given string.
*
@@ -4254,31 +4283,12 @@
errorReported = FALSE;
while (*p != '\0') {
- if (p[0] == '$' && p[1] == '$') {
- /*
- * A dollar sign may be escaped with another dollar
- * sign.
- */
- if (save_dollars && (eflags & VARE_KEEP_DOLLAR))
- Buf_AddByte(&res, '$');
- Buf_AddByte(&res, '$');
- p += 2;
-
- } else if (p[0] == '$') {
- VarSubstNested(&p, &res, ctxt, eflags, &errorReported);
-
- } else {
- /*
- * Skip as many characters as possible -- either to
- * the end of the string or to the next dollar sign
- * (variable expression).
- */
- const char *plainStart = p;
-
- for (p++; *p != '$' && *p != '\0'; p++)
- continue;
- Buf_AddBytesBetween(&res, plainStart, p);
- }
+ if (p[0] == '$' && p[1] == '$')
+ VarSubstDollarDollar(&p, &res, eflags);
+ else if (p[0] == '$')
+ VarSubstExpr(&p, &res, ctxt, eflags, &errorReported);
+ else
+ VarSubstPlain(&p, &res);
}
*out_res = Buf_DestroyCompact(&res);
Home |
Main Index |
Thread Index |
Old Index