Module Name: src Committed By: rillig Date: Wed Feb 3 13:44:39 UTC 2021
Modified Files: src/usr.bin/make: nonints.h parse.c var.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.192 -r1.193 src/usr.bin/make/nonints.h cvs rdiff -u -r1.540 -r1.541 src/usr.bin/make/parse.c cvs rdiff -u -r1.793 -r1.794 src/usr.bin/make/var.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/nonints.h diff -u src/usr.bin/make/nonints.h:1.192 src/usr.bin/make/nonints.h:1.193 --- src/usr.bin/make/nonints.h:1.192 Wed Feb 3 08:08:18 2021 +++ src/usr.bin/make/nonints.h Wed Feb 3 13:44:39 2021 @@ -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 *, cons 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 *); Index: src/usr.bin/make/parse.c diff -u src/usr.bin/make/parse.c:1.540 src/usr.bin/make/parse.c:1.541 --- src/usr.bin/make/parse.c:1.540 Wed Feb 3 08:08:18 2021 +++ src/usr.bin/make/parse.c Wed Feb 3 13:44:39 2021 @@ -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, VarAssi 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) Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.793 src/usr.bin/make/var.c:1.794 --- src/usr.bin/make/var.c:1.793 Wed Feb 3 08:40:47 2021 +++ src/usr.bin/make/var.c Wed Feb 3 13:44:39 2021 @@ -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 } /* + * 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 * 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 /* 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 } } - 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;