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 Var_Export



details:   https://anonhg.NetBSD.org/src/rev/c2f86effd912
branches:  trunk
changeset: 979080:c2f86effd912
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Dec 13 01:41:12 2020 +0000

description:
make(1): clean up Var_Export

diffstat:

 usr.bin/make/nonints.h |  13 +++++++++++--
 usr.bin/make/parse.c   |  16 ++++++++++------
 usr.bin/make/var.c     |  41 +++++++----------------------------------
 3 files changed, 28 insertions(+), 42 deletions(-)

diffs (153 lines):

diff -r 6b8b3ca0a33b -r c2f86effd912 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sun Dec 13 01:33:17 2020 +0000
+++ b/usr.bin/make/nonints.h    Sun Dec 13 01:41:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.168 2020/12/12 21:20:30 rillig Exp $     */
+/*     $NetBSD: nonints.h,v 1.169 2020/12/13 01:41:12 rillig Exp $     */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -311,6 +311,15 @@
     VPR_UNKNOWN                = 0x0008
 } VarParseResult;
 
+typedef enum VarExportMode {
+       /* .export-env */
+       VEM_NORMAL,
+       /* .export: Initial export or update an already exported variable. */
+       VEM_PARENT,
+       /* .export-literal: Do not expand the variable value. */
+       VEM_LITERAL
+} VarExportMode;
+
 void Var_Delete(const char *, GNode *);
 void Var_Set(const char *, const char *, GNode *);
 void Var_SetWithFlags(const char *, const char *, GNode *, VarSetFlags);
@@ -324,7 +333,7 @@
 void Var_Stats(void);
 void Var_Dump(GNode *);
 void Var_ReexportVars(void);
-void Var_Export(const char *);
+void Var_Export(VarExportMode, const char *);
 void Var_ExportVars(const char *);
 void Var_UnExport(const char *);
 
diff -r 6b8b3ca0a33b -r c2f86effd912 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sun Dec 13 01:33:17 2020 +0000
+++ b/usr.bin/make/parse.c      Sun Dec 13 01:41:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.475 2020/12/13 01:07:54 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.476 2020/12/13 01:41:12 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.475 2020/12/13 01:07:54 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.476 2020/12/13 01:41:12 rillig Exp $");
 
 /* types and constants */
 
@@ -2988,10 +2988,14 @@
                /* TODO: undefine all variables, not only the first */
                /* TODO: use Str_Words, like everywhere else */
                return TRUE;
-       } else if (IsDirective(dir, dirlen, "export") ||
-                  IsDirective(dir, dirlen, "export-env") ||
-                  IsDirective(dir, dirlen, "export-literal")) {
-               Var_Export(dir + strlen("export"));
+       } else if (IsDirective(dir, dirlen, "export")) {
+               Var_Export(VEM_PARENT, arg);
+               return TRUE;
+       } else if (IsDirective(dir, dirlen, "export-env")) {
+               Var_Export(VEM_NORMAL, arg);
+               return TRUE;
+       } else if (IsDirective(dir, dirlen, "export-literal")) {
+               Var_Export(VEM_LITERAL, arg);
                return TRUE;
        } else if (IsDirective(dir, dirlen, "unexport") ||
                   IsDirective(dir, dirlen, "unexport-env")) {
diff -r 6b8b3ca0a33b -r c2f86effd912 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Dec 13 01:33:17 2020 +0000
+++ b/usr.bin/make/var.c        Sun Dec 13 01:41:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.730 2020/12/13 01:33:17 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.731 2020/12/13 01:41:12 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.730 2020/12/13 01:33:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.731 2020/12/13 01:41:12 rillig Exp $");
 
 /* A string that may need to be freed after use. */
 typedef struct FStr {
@@ -212,14 +212,6 @@
        VarFlags flags;
 } Var;
 
-typedef enum VarExportMode {
-       VEM_NORMAL,
-       /* Initial export or updating an already exported variable. */
-       VEM_PARENT,
-       /* Do not expand the variable value. */
-       VEM_LITERAL
-} VarExportMode;
-
 /*
  * Exporting vars is expensive so skip it if we can
  */
@@ -578,7 +570,7 @@
                return FALSE;   /* nothing to do */
 
        val = Buf_GetAll(&v->val, NULL);
-       if (!(mode == VEM_LITERAL) && strchr(val, '$') != NULL) {
+       if (mode != VEM_LITERAL && strchr(val, '$') != NULL) {
                char *expr;
 
                if (parent) {
@@ -700,35 +692,16 @@
        free(xvarnames);
 }
 
-/*
- * This is called when .export is seen or .MAKE.EXPORTED is modified.
- *
- * It is also called when any exported variable is modified.
- * XXX: Is it really?
- *
- * str has the format "[-env|-literal] varname...".
- */
+/* Export the named variables, or all variables. */
 void
-Var_Export(const char *str)
+Var_Export(VarExportMode mode, const char *varnames)
 {
-       VarExportMode mode;
-
-       if (str[0] == '\0') {
+       if (mode == VEM_PARENT && varnames[0] == '\0') {
                var_exportedVars = VAR_EXPORTED_ALL; /* use with caution! */
                return;
        }
 
-       if (strncmp(str, "-env", 4) == 0) {
-               str += 4;
-               mode = VEM_NORMAL;
-       } else if (strncmp(str, "-literal", 8) == 0) {
-               str += 8;
-               mode = VEM_LITERAL;
-       } else {
-               mode = VEM_PARENT;
-       }
-
-       ExportVarsExpand(str, TRUE, mode);
+       ExportVarsExpand(varnames, TRUE, mode);
 }
 
 void



Home | Main Index | Thread Index | Old Index