summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2021-02-03 13:44:39 +0000
committerrillig <rillig@NetBSD.org>2021-02-03 13:44:39 +0000
commitcdc50a22f04eeeb150e1dc17e8e85c4e1ee8d455 (patch)
tree36506d94fdda1103224f130c4e837f37210730e0 /usr.bin/make
parent1b4aed40f0c2143064dd517dc7dd89de8626ae1f (diff)
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 (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/nonints.h3
-rw-r--r--usr.bin/make/parse.c6
-rw-r--r--usr.bin/make/var.c87
3 files changed, 57 insertions, 39 deletions
diff --git a/usr.bin/make/nonints.h b/usr.bin/make/nonints.h
index 6be68530991..4a0ed0a48ff 100644
--- a/usr.bin/make/nonints.h
+++ b/usr.bin/make/nonints.h
@@ -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 Global_SetExpand(const char *, const char *);
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 --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index a56be04eea8..00d0de1a6e0 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -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 @@ VarAssign_Eval(const char *name, VarAssignOp op, const char *uvalue,
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 --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index e5c30222bba..760979abcd2 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -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,6 +1052,48 @@ Global_SetExpand(const char *name, const char *value)
}
/*
+ * Append the value to the named variable.
+ *
+ * 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)
+{
+ Var *v;
+
+ v = VarFind(name, ctxt, ctxt == VAR_GLOBAL);
+
+ if (v == NULL) {
+ SetVar(name, val, ctxt, VAR_SET_NONE);
+ } else if (v->flags & VAR_READONLY) {
+ DEBUG1(VAR, "Ignoring append to %s since it is read-only\n",
+ name);
+ } else if (ctxt == VAR_CMDLINE || !(v->flags & VAR_FROM_CMD)) {
+ Buf_AddByte(&v->val, ' ');
+ Buf_AddStr(&v->val, val);
+
+ DEBUG3(VAR, "%s:%s = %s\n", ctxt->name, name, v->val.data);
+
+ if (v->flags & VAR_FROM_ENV) {
+ /*
+ * If the original variable came from the environment,
+ * we have to install it in the global context (we
+ * could place it in the environment, but then we
+ * should provide a way to export other variables...)
+ */
+ v->flags &= ~(unsigned)VAR_FROM_ENV;
+ /*
+ * This is the only place where a variable is
+ * created whose v->name is not the same as
+ * ctxt->context->key.
+ */
+ HashTable_Set(&ctxt->vars, name, v);
+ }
+ }
+}
+
+/*
* The variable of the given name has the given value appended to it in the
* given context.
*
@@ -1070,10 +1114,9 @@ Global_SetExpand(const char *name, const char *value)
* a big win and must be tolerated.
*/
void
-Var_Append(const char *name, const char *val, GNode *ctxt)
+Var_AppendExpand(const char *name, const char *val, GNode *ctxt)
{
char *name_freeIt = NULL;
- Var *v;
assert(val != NULL);
@@ -1083,6 +1126,7 @@ Var_Append(const char *name, const char *val, GNode *ctxt)
/* 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);
@@ -1091,42 +1135,15 @@ Var_Append(const char *name, const char *val, GNode *ctxt)
}
}
- v = VarFind(name, ctxt, ctxt == VAR_GLOBAL);
-
- if (v == NULL) {
- SetVar(name, val, ctxt, VAR_SET_NONE);
- } else if (v->flags & VAR_READONLY) {
- DEBUG1(VAR, "Ignoring append to %s since it is read-only\n",
- name);
- } else if (ctxt == VAR_CMDLINE || !(v->flags & VAR_FROM_CMD)) {
- Buf_AddByte(&v->val, ' ');
- Buf_AddStr(&v->val, val);
-
- DEBUG3(VAR, "%s:%s = %s\n", ctxt->name, name, v->val.data);
+ Var_Append(name, val, ctxt);
- if (v->flags & VAR_FROM_ENV) {
- /*
- * If the original variable came from the environment,
- * we have to install it in the global context (we
- * could place it in the environment, but then we
- * should provide a way to export other variables...)
- */
- v->flags &= ~(unsigned)VAR_FROM_ENV;
- /*
- * This is the only place where a variable is
- * created whose v->name is not the same as
- * ctxt->context->key.
- */
- HashTable_Set(&ctxt->vars, name, v);
- }
- }
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 @@ ok:
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;