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: extract ExistsInCmdline from Var_SetWithF...



details:   https://anonhg.NetBSD.org/src/rev/285de65ab7be
branches:  trunk
changeset: 952978:285de65ab7be
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Feb 22 21:43:57 2021 +0000

description:
make: extract ExistsInCmdline from Var_SetWithFlags

No functional change.

diffstat:

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

diffs (79 lines):

diff -r 8bfc91713509 -r 285de65ab7be usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Feb 22 21:30:33 2021 +0000
+++ b/usr.bin/make/var.c        Mon Feb 22 21:43:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.833 2021/02/22 21:30:33 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.834 2021/02/22 21:43:57 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.833 2021/02/22 21:30:33 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.834 2021/02/22 21:43:57 rillig Exp $");
 
 typedef enum VarFlags {
        VFL_NONE        = 0,
@@ -930,6 +930,32 @@
        FStr_Done(&varnames);
 }
 
+/*
+ * When there is a variable of the same name in the command line scope, the
+ * global variable would not be visible anywhere.  Therefore there is no
+ * point in setting it at all.
+ *
+ * See 'scope == SCOPE_CMDLINE' in Var_SetWithFlags.
+ */
+static Boolean
+ExistsInCmdline(const char *name, const char *val)
+{
+       Var *v;
+
+       v = VarFind(name, SCOPE_CMDLINE, FALSE);
+       if (v == NULL)
+               return FALSE;
+
+       if (v->flags & VFL_FROM_CMD) {
+               DEBUG3(VAR, "%s:%s = %s ignored!\n",
+                   SCOPE_GLOBAL->name, name, val);
+               return TRUE;
+       }
+
+       VarFreeEnv(v, TRUE);
+       return FALSE;
+}
+
 /* Set the variable to the value; the name is not expanded. */
 void
 Var_SetWithFlags(GNode *scope, const char *name, const char *val,
@@ -943,25 +969,8 @@
                return;
        }
 
-       if (scope == SCOPE_GLOBAL) {
-               v = VarFind(name, SCOPE_CMDLINE, FALSE);
-               if (v != NULL) {
-                       /*
-                        * When there is a variable of the same name in the
-                        * command line scope, the global variable would not
-                        * be visible anywhere.  Therefore there is no point
-                        * in setting it at all.
-                        *
-                        * See 'scope == SCOPE_CMDLINE' below.
-                        */
-                       if (v->flags & VFL_FROM_CMD) {
-                               DEBUG3(VAR, "%s:%s = %s ignored!\n",
-                                   scope->name, name, val);
-                               return;
-                       }
-                       VarFreeEnv(v, TRUE);
-               }
-       }
+       if (scope == SCOPE_GLOBAL && ExistsInCmdline(name, val))
+               return;
 
        /*
         * Only look for a variable in the given scope since anything set



Home | Main Index | Thread Index | Old Index