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): clean up various things in var.c
details: https://anonhg.NetBSD.org/src/rev/945f6ef7257f
branches: trunk
changeset: 936222:945f6ef7257f
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Jul 21 21:13:24 2020 +0000
description:
make(1): clean up various things in var.c
diffstat:
usr.bin/make/make.h | 4 +-
usr.bin/make/var.c | 110 ++++++++++++++++++++++++---------------------------
2 files changed, 55 insertions(+), 59 deletions(-)
diffs (truncated from 320 to 300 lines):
diff -r 5862111ddc73 -r 945f6ef7257f usr.bin/make/make.h
--- a/usr.bin/make/make.h Tue Jul 21 20:56:56 2020 +0000
+++ b/usr.bin/make/make.h Tue Jul 21 21:13:24 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.110 2020/07/18 21:37:38 sjg Exp $ */
+/* $NetBSD: make.h,v 1.111 2020/07/21 21:13:24 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -423,6 +423,8 @@
extern char *makeDependfile; /* .depend */
extern char **savedEnv; /* if we replaced environ this will be non-NULL */
+extern int makelevel;
+
/*
* We cannot vfork() in a child of vfork().
* Most systems do not enforce this but some do.
diff -r 5862111ddc73 -r 945f6ef7257f usr.bin/make/var.c
--- a/usr.bin/make/var.c Tue Jul 21 20:56:56 2020 +0000
+++ b/usr.bin/make/var.c Tue Jul 21 21:13:24 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.291 2020/07/21 20:56:56 rillig Exp $ */
+/* $NetBSD: var.c,v 1.292 2020/07/21 21:13:24 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.291 2020/07/21 20:56:56 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.292 2020/07/21 21:13:24 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.291 2020/07/21 20:56:56 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.292 2020/07/21 21:13:24 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -88,8 +88,7 @@
* Interface:
* Var_Set Set the value of a variable in the given
* context. The variable is created if it doesn't
- * yet exist. The value and variable name need not
- * be preserved.
+ * yet exist.
*
* Var_Append Append more characters to an existing variable
* in the given context. The variable needn't
@@ -103,8 +102,7 @@
* NULL if the variable is undefined.
*
* Var_Subst Substitute either a single variable or all
- * variables in a string, using the given context as
- * the top-most one.
+ * variables in a string, using the given context.
*
* Var_Parse Parse a variable expansion from a string and
* return the result and the number of characters
@@ -128,8 +126,8 @@
#endif
#include <ctype.h>
#include <inttypes.h>
+#include <limits.h>
#include <stdlib.h>
-#include <limits.h>
#include <time.h>
#include "make.h"
@@ -138,7 +136,6 @@
#include "job.h"
#include "metachar.h"
-extern int makelevel;
/*
* This lets us tell if we have replaced the original environ
* (which we cannot free).
@@ -154,7 +151,7 @@
/*
* Similar to var_Error, but returned when the 'VARE_UNDEFERR' flag for
- * Var_Parse is not set. Why not just use a constant? Well, gcc likes
+ * Var_Parse is not set. Why not just use a constant? Well, GCC likes
* to condense identical string instances...
*/
static char varNoError[] = "";
@@ -163,27 +160,26 @@
* Traditionally we consume $$ during := like any other expansion.
* Other make's do not.
* This knob allows controlling the behavior.
- * FALSE for old behavior.
- * TRUE for new compatible.
+ * FALSE to consume $$ during := assignment.
+ * TRUE to preserve $$ during := assignment.
*/
#define SAVE_DOLLARS ".MAKE.SAVE_DOLLARS"
static Boolean save_dollars = TRUE;
/*
* Internally, variables are contained in four different contexts.
- * 1) the environment. They may not be changed. If an environment
- * variable is appended-to, the result is placed in the global
+ * 1) the environment. They cannot be changed. If an environment
+ * variable is appended to, the result is placed in the global
* context.
* 2) the global context. Variables set in the Makefile are located in
- * the global context. It is the penultimate context searched when
- * substituting.
+ * the global context.
* 3) the command-line context. All variables set on the command line
* are placed in this context. They are UNALTERABLE once placed here.
* 4) the local context. Each target has associated with it a context
* list. On this list are located the structures describing such
* local variables as $(@) and $(*)
* The four contexts are searched in the reverse order from which they are
- * listed.
+ * listed (but see checkEnvFirst).
*/
GNode *VAR_INTERNAL; /* variables from make itself */
GNode *VAR_GLOBAL; /* variables from the makefile */
@@ -196,7 +192,8 @@
} VarFindFlags;
typedef enum {
- VAR_IN_USE = 0x01, /* Variable's value is currently being used.
+ VAR_IN_USE = 0x01, /* Variable's value is currently being used
+ * by Var_Parse or Var_Subst.
* Used to avoid endless recursion */
VAR_FROM_ENV = 0x02, /* Variable comes from the environment */
VAR_JUNK = 0x04, /* Variable is a junk variable that
@@ -221,19 +218,24 @@
/*
* Exporting vars is expensive so skip it if we can
*/
-#define VAR_EXPORTED_NONE 0
-#define VAR_EXPORTED_YES 1
-#define VAR_EXPORTED_ALL 2
-static int var_exportedVars = VAR_EXPORTED_NONE;
-/*
- * We pass this to Var_Export when doing the initial export
- * or after updating an exported var.
- */
-#define VAR_EXPORT_PARENT 1
-/*
- * We pass this to Var_Export1 to tell it to leave the value alone.
- */
-#define VAR_EXPORT_LITERAL 2
+typedef enum {
+ VAR_EXPORTED_NONE,
+ VAR_EXPORTED_YES,
+ VAR_EXPORTED_ALL
+} VarExportedMode;
+static VarExportedMode var_exportedVars = VAR_EXPORTED_NONE;
+
+typedef enum {
+ /*
+ * We pass this to Var_Export when doing the initial export
+ * or after updating an exported var.
+ */
+ VAR_EXPORT_PARENT = 0x01,
+ /*
+ * We pass this to Var_Export1 to tell it to leave the value alone.
+ */
+ VAR_EXPORT_LITERAL = 0x02
+} VarExportFlags;
/* Flags for pattern matching in the :S and :C modifiers */
typedef enum {
@@ -245,7 +247,7 @@
} VarPatternFlags;
typedef enum {
- VAR_NO_EXPORT = 0x01 /* do not export */
+ VAR_NO_EXPORT = 0x01 /* do not export */
} VarSet_Flags;
typedef struct {
@@ -490,12 +492,10 @@
free(cp);
if (ln != NULL) {
Var *v = (Var *)Hash_GetValue(ln);
- if (v->flags & VAR_EXPORTED) {
+ if (v->flags & VAR_EXPORTED)
unsetenv(v->name);
- }
- if (strcmp(MAKE_EXPORTED, v->name) == 0) {
+ if (strcmp(MAKE_EXPORTED, v->name) == 0)
var_exportedVars = VAR_EXPORTED_NONE;
- }
if (v->name != ln->name)
free(v->name);
Hash_DeleteEntry(&ctxt->context, ln);
@@ -513,13 +513,13 @@
* We only manipulate flags of vars if 'parent' is set.
*/
static int
-Var_Export1(const char *name, int flags)
+Var_Export1(const char *name, VarExportFlags flags)
{
char tmp[BUFSIZ];
Var *v;
char *val = NULL;
int n;
- int parent = (flags & VAR_EXPORT_PARENT);
+ VarExportFlags parent = flags & VAR_EXPORT_PARENT;
if (*name == '.')
return 0; /* skip internals */
@@ -542,7 +542,7 @@
if (v == NULL)
return 0;
if (!parent &&
- (v->flags & (VAR_EXPORTED|VAR_REEXPORT)) == VAR_EXPORTED) {
+ (v->flags & (VAR_EXPORTED | VAR_REEXPORT)) == VAR_EXPORTED) {
return 0; /* nothing to do */
}
val = Buf_GetAll(&v->val, NULL);
@@ -553,7 +553,7 @@
* No point actually exporting it now though,
* the child can do it at the last minute.
*/
- v->flags |= (VAR_EXPORTED|VAR_REEXPORT);
+ v->flags |= (VAR_EXPORTED | VAR_REEXPORT);
return 1;
}
if (v->flags & VAR_IN_USE) {
@@ -570,12 +570,10 @@
free(val);
}
} else {
- if (parent) {
+ if (parent)
v->flags &= ~VAR_REEXPORT; /* once will do */
- }
- if (parent || !(v->flags & VAR_EXPORTED)) {
+ if (parent || !(v->flags & VAR_EXPORTED))
setenv(name, val, 1);
- }
}
/*
* This is so Var_Set knows to call Var_Export again...
@@ -776,11 +774,9 @@
if (!v)
continue;
if (!unexport_env &&
- (v->flags & (VAR_EXPORTED|VAR_REEXPORT)) == VAR_EXPORTED)
- {
+ (v->flags & (VAR_EXPORTED | VAR_REEXPORT)) == VAR_EXPORTED)
unsetenv(v->name);
- }
- v->flags &= ~(VAR_EXPORTED|VAR_REEXPORT);
+ v->flags &= ~(VAR_EXPORTED | VAR_REEXPORT);
/*
* If we are unexporting a list,
* remove each one from .MAKE.EXPORTED.
@@ -888,10 +884,8 @@
Var_Append(MAKEOVERRIDES, name, VAR_GLOBAL);
}
- if (*name == '.') {
- if (strcmp(name, SAVE_DOLLARS) == 0)
- save_dollars = s2Boolean(val, save_dollars);
- }
+ if (name[0] == '.' && strcmp(name, SAVE_DOLLARS) == 0)
+ save_dollars = s2Boolean(val, save_dollars);
out:
free(expanded_name);
@@ -1536,7 +1530,7 @@
/*-
* Implements the :[first..last] modifier.
- * This is a special case of VarModify since we want to be able
+ * This is a special case of ModifyWords since we want to be able
* to scan the list backwards if first > last.
*/
static char *
@@ -1654,7 +1648,7 @@
}
if (DEBUG(VAR)) {
- fprintf(debug_file, "VarModify: split \"%s\" into %d words\n",
+ fprintf(debug_file, "ModifyWords: split \"%s\" into %d words\n",
str, ac);
}
@@ -2418,7 +2412,7 @@
endpat = cp2;
} else {
/*
- * Either Var_Subst or VarModify will need a
+ * Either Var_Subst or ModifyWords will need a
* nul-terminated string soon, so construct one now.
*/
pattern = bmake_strndup(st->tstr+1, endpat - (st->tstr + 1));
Home |
Main Index |
Thread Index |
Old Index