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): replace VarFindFlags with a simple Boo...



details:   https://anonhg.NetBSD.org/src/rev/23c3b90987f7
branches:  trunk
changeset: 956409:23c3b90987f7
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 30 07:37:30 2020 +0000

description:
make(1): replace VarFindFlags with a simple Boolean

Either all flags had been given or none.  Except in Var_Append, but
since the ctxt was VAR_GLOBAL anyway, adding FIND_GLOBAL there did not
make a difference.

diffstat:

 usr.bin/make/var.c |  34 +++++++++++++---------------------
 1 files changed, 13 insertions(+), 21 deletions(-)

diffs (127 lines):

diff -r 56f85f5fc8ff -r 23c3b90987f7 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Fri Oct 30 07:30:29 2020 +0000
+++ b/usr.bin/make/var.c        Fri Oct 30 07:37:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.595 2020/10/30 07:30:29 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.596 2020/10/30 07:37:30 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -129,7 +129,7 @@
 #include    "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.595 2020/10/30 07:30:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.596 2020/10/30 07:37:30 rillig Exp $");
 
 #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
 #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -191,12 +191,6 @@
 GNode          *VAR_GLOBAL;    /* variables from the makefile */
 GNode          *VAR_CMDLINE;   /* variables defined on the command-line */
 
-typedef enum VarFindFlags {
-    FIND_CMDLINE       = 0x01, /* look in VAR_CMDLINE when searching */
-    FIND_GLOBAL                = 0x02, /* look in VAR_GLOBAL as well */
-    FIND_ENV           = 0x04  /* look in the environment also */
-} VarFindFlags;
-
 typedef enum VarFlags {
     /* The variable's value is currently being used by Var_Parse or Var_Subst.
      * This marker is used to avoid endless recursion. */
@@ -355,7 +349,7 @@
  * Input:
  *     name            name to find
  *     ctxt            context in which to find it
- *     flags           to look on other contexts as well
+ *     elsewhere       to look in other contexts as well
  *
  * Results:
  *     A pointer to the structure describing the desired variable or
@@ -363,7 +357,7 @@
  *-----------------------------------------------------------------------
  */
 static Var *
-VarFind(const char *name, GNode *ctxt, VarFindFlags flags)
+VarFind(const char *name, GNode *ctxt, Boolean elsewhere)
 {
     Var *var;
     unsigned int nameHash;
@@ -384,12 +378,10 @@
      */
     var = GNode_FindVar(ctxt, name, nameHash);
 
-    if (var == NULL && (flags & FIND_CMDLINE) && ctxt != VAR_CMDLINE)
+    if (var == NULL && elsewhere && ctxt != VAR_CMDLINE)
        var = GNode_FindVar(VAR_CMDLINE, name, nameHash);
 
-    if (!opts.checkEnvFirst && var == NULL && (flags & FIND_GLOBAL) &&
-       ctxt != VAR_GLOBAL)
-    {
+    if (!opts.checkEnvFirst && var == NULL && elsewhere && ctxt != VAR_GLOBAL) {
        var = GNode_FindVar(VAR_GLOBAL, name, nameHash);
        if (var == NULL && ctxt != VAR_INTERNAL) {
            /* VAR_INTERNAL is subordinate to VAR_GLOBAL */
@@ -397,7 +389,7 @@
        }
     }
 
-    if (var == NULL && (flags & FIND_ENV)) {
+    if (var == NULL && elsewhere) {
        char *env;
 
        if ((env = getenv(name)) != NULL) {
@@ -405,7 +397,7 @@
            return VarNew(varname, varname, env, VAR_FROM_ENV);
        }
 
-       if (opts.checkEnvFirst && (flags & FIND_GLOBAL) && ctxt != VAR_GLOBAL) {
+       if (opts.checkEnvFirst && elsewhere && ctxt != VAR_GLOBAL) {
            var = GNode_FindVar(VAR_GLOBAL, name, nameHash);
            if (var == NULL && ctxt != VAR_INTERNAL)
                var = GNode_FindVar(VAR_INTERNAL, name, nameHash);
@@ -940,7 +932,7 @@
        }
     }
 
-    v = VarFind(name, ctxt, ctxt == VAR_GLOBAL ? (FIND_CMDLINE | FIND_ENV) : 0);
+    v = VarFind(name, ctxt, ctxt == VAR_GLOBAL);
 
     if (v == NULL) {
        Var_Set(name, val, ctxt);
@@ -987,7 +979,7 @@
        name = name_freeIt;
     }
 
-    v = VarFind(name, ctxt, FIND_CMDLINE | FIND_GLOBAL | FIND_ENV);
+    v = VarFind(name, ctxt, TRUE);
     free(name_freeIt);
     if (v == NULL)
        return FALSE;
@@ -1015,7 +1007,7 @@
 const char *
 Var_Value(const char *name, GNode *ctxt, char **freeIt)
 {
-    Var *v = VarFind(name, ctxt, FIND_CMDLINE | FIND_GLOBAL | FIND_ENV);
+    Var *v = VarFind(name, ctxt, TRUE);
     char *p;
 
     *freeIt = NULL;
@@ -3555,7 +3547,7 @@
 
        name[0] = startc;
        name[1] = '\0';
-       v = VarFind(name, ctxt, FIND_CMDLINE | FIND_GLOBAL | FIND_ENV);
+       v = VarFind(name, ctxt, TRUE);
        if (v == NULL) {
            *pp += 2;
 
@@ -3590,7 +3582,7 @@
            return VPR_PARSE_MSG;
        }
 
-       v = VarFind(varname, ctxt, FIND_CMDLINE | FIND_GLOBAL | FIND_ENV);
+       v = VarFind(varname, ctxt, TRUE);
 
        /* At this point, p points just after the variable name,
         * either at ':' or at endc. */



Home | Main Index | Thread Index | Old Index