Module Name:    src
Committed By:   rillig
Date:           Sun Dec 13 01:41:12 UTC 2020

Modified Files:
        src/usr.bin/make: nonints.h parse.c var.c

Log Message:
make(1): clean up Var_Export


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.475 -r1.476 src/usr.bin/make/parse.c
cvs rdiff -u -r1.730 -r1.731 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.168 src/usr.bin/make/nonints.h:1.169
--- src/usr.bin/make/nonints.h:1.168	Sat Dec 12 21:20:30 2020
+++ src/usr.bin/make/nonints.h	Sun Dec 13 01:41:12 2020
@@ -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 @@ typedef enum VarParseResult {
     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 @@ VarParseResult Var_Subst(const char *, G
 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 *);
 

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.475 src/usr.bin/make/parse.c:1.476
--- src/usr.bin/make/parse.c:1.475	Sun Dec 13 01:07:54 2020
+++ src/usr.bin/make/parse.c	Sun Dec 13 01:41:12 2020
@@ -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 @@ ParseDirective(char *line)
 		/* 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")) {

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.730 src/usr.bin/make/var.c:1.731
--- src/usr.bin/make/var.c:1.730	Sun Dec 13 01:33:17 2020
+++ src/usr.bin/make/var.c	Sun Dec 13 01:41:12 2020
@@ -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 @@ typedef struct Var {
 	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 @@ ExportVar(const char *name, VarExportMod
 		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 @@ ExportVarsExpand(const char *uvarnames, 
 	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

Reply via email to