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: split Var_Append into Var_Append and Var_...
details: https://anonhg.NetBSD.org/src/rev/87be7a93a924
branches: trunk
changeset: 951472:87be7a93a924
user: rillig <rillig%NetBSD.org@localhost>
date: Wed Feb 03 13:44:39 2021 +0000
description:
make: split Var_Append into Var_Append and Var_AppendExpand
The plain Var_Append now does not expand the variable name anymore. It
is used in situations where the variable name is known to not contain a
dollar sign.
This is a preparation for adding Global_Append, corresponding to
Global_AppendExpand.
diffstat:
usr.bin/make/nonints.h | 3 +-
usr.bin/make/parse.c | 6 +-
usr.bin/make/var.c | 95 +++++++++++++++++++++++++++++--------------------
3 files changed, 61 insertions(+), 43 deletions(-)
diffs (194 lines):
diff -r 6d2954eaf197 -r 87be7a93a924 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h Wed Feb 03 12:11:34 2021 +0000
+++ b/usr.bin/make/nonints.h Wed Feb 03 13:44:39 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nonints.h,v 1.192 2021/02/03 08:08:18 rillig Exp $ */
+/* $NetBSD: nonints.h,v 1.193 2021/02/03 13:44:39 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -376,6 +376,7 @@
void Var_Set(const char *, const char *, GNode *);
void Var_SetWithFlags(const char *, const char *, GNode *, VarSetFlags);
void Var_Append(const char *, const char *, GNode *);
+void Var_AppendExpand(const char *, const char *, GNode *);
void Global_AppendExpand(const char *, const char *);
Boolean Var_Exists(const char *, GNode *);
FStr Var_Value(const char *, GNode *);
diff -r 6d2954eaf197 -r 87be7a93a924 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Wed Feb 03 12:11:34 2021 +0000
+++ b/usr.bin/make/parse.c Wed Feb 03 13:44:39 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.540 2021/02/03 08:08:18 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.541 2021/02/03 13:44:39 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.540 2021/02/03 08:08:18 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.541 2021/02/03 13:44:39 rillig Exp $");
/* types and constants */
@@ -1954,7 +1954,7 @@
FStr avalue = FStr_InitRefer(uvalue);
if (op == VAR_APPEND)
- Var_Append(name, uvalue, ctxt);
+ Var_AppendExpand(name, uvalue, ctxt);
else if (op == VAR_SUBST)
VarAssign_EvalSubst(name, uvalue, ctxt, &avalue);
else if (op == VAR_SHELL)
diff -r 6d2954eaf197 -r 87be7a93a924 usr.bin/make/var.c
--- a/usr.bin/make/var.c Wed Feb 03 12:11:34 2021 +0000
+++ b/usr.bin/make/var.c Wed Feb 03 13:44:39 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.793 2021/02/03 08:40:47 rillig Exp $ */
+/* $NetBSD: var.c,v 1.794 2021/02/03 13:44:39 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -83,7 +83,9 @@
* Var_Set Set the value of the variable, creating it if
* necessary.
*
- * Var_Append Append more characters to the variable, creating it if
+ * Var_Append
+ * Var_AppendExpand
+ * Append more characters to the variable, creating it if
* necessary. A space is placed between the old value and
* the new one.
*
@@ -131,7 +133,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.793 2021/02/03 08:40:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.794 2021/02/03 13:44:39 rillig Exp $");
typedef enum VarFlags {
VAR_NONE = 0,
@@ -1050,47 +1052,16 @@
}
/*
- * The variable of the given name has the given value appended to it in the
- * given context.
- *
- * If the variable doesn't exist, it is created. Otherwise the strings are
- * concatenated, with a space in between.
+ * Append the value to the named variable.
*
- * Input:
- * name name of the variable to modify, is expanded once
- * val string to append to it
- * ctxt context in which this should occur
- *
- * Notes:
- * Only if the variable is being sought in the global context is the
- * environment searched.
- * XXX: Knows its calling circumstances in that if called with ctxt
- * an actual target, it will only search that context since only
- * a local variable could be being appended to. This is actually
- * a big win and must be tolerated.
+ * If the variable doesn't exist, it is created. Otherwise a single space
+ * and the given value are appended.
*/
void
Var_Append(const char *name, const char *val, GNode *ctxt)
{
- char *name_freeIt = NULL;
Var *v;
- assert(val != NULL);
-
- if (strchr(name, '$') != NULL) {
- const char *unexpanded_name = name;
- (void)Var_Subst(name, ctxt, VARE_WANTRES, &name_freeIt);
- /* TODO: handle errors */
- name = name_freeIt;
- if (name[0] == '\0') {
- DEBUG2(VAR, "Var_Append(\"%s\", \"%s\", ...) "
- "name expands to empty string - ignored\n",
- unexpanded_name, val);
- free(name_freeIt);
- return;
- }
- }
-
v = VarFind(name, ctxt, ctxt == VAR_GLOBAL);
if (v == NULL) {
@@ -1120,13 +1091,59 @@
HashTable_Set(&ctxt->vars, name, v);
}
}
+}
+
+/*
+ * The variable of the given name has the given value appended to it in the
+ * given context.
+ *
+ * If the variable doesn't exist, it is created. Otherwise the strings are
+ * concatenated, with a space in between.
+ *
+ * Input:
+ * name name of the variable to modify, is expanded once
+ * val string to append to it
+ * ctxt context in which this should occur
+ *
+ * Notes:
+ * Only if the variable is being sought in the global context is the
+ * environment searched.
+ * XXX: Knows its calling circumstances in that if called with ctxt
+ * an actual target, it will only search that context since only
+ * a local variable could be being appended to. This is actually
+ * a big win and must be tolerated.
+ */
+void
+Var_AppendExpand(const char *name, const char *val, GNode *ctxt)
+{
+ char *name_freeIt = NULL;
+
+ assert(val != NULL);
+
+ if (strchr(name, '$') != NULL) {
+ const char *unexpanded_name = name;
+ (void)Var_Subst(name, ctxt, VARE_WANTRES, &name_freeIt);
+ /* TODO: handle errors */
+ name = name_freeIt;
+ if (name[0] == '\0') {
+ /* TODO: update function name in the debug message */
+ DEBUG2(VAR, "Var_Append(\"%s\", \"%s\", ...) "
+ "name expands to empty string - ignored\n",
+ unexpanded_name, val);
+ free(name_freeIt);
+ return;
+ }
+ }
+
+ Var_Append(name, val, ctxt);
+
free(name_freeIt);
}
void
Global_AppendExpand(const char *name, const char *value)
{
- Var_Append(name, value, VAR_GLOBAL);
+ Var_AppendExpand(name, value, VAR_GLOBAL);
}
/*
@@ -3257,7 +3274,7 @@
if (st->eflags & VARE_WANTRES) {
switch (op[0]) {
case '+':
- Var_Append(st->var->name.str, val, ctxt);
+ Var_AppendExpand(st->var->name.str, val, ctxt);
break;
case '!': {
const char *errfmt;
Home |
Main Index |
Thread Index |
Old Index