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): extract GetVarnamesToUnexport from Var...
details: https://anonhg.NetBSD.org/src/rev/9306a1120ccc
branches: trunk
changeset: 946713:9306a1120ccc
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Dec 06 17:22:44 2020 +0000
description:
make(1): extract GetVarnamesToUnexport from Var_UnExport
diffstat:
usr.bin/make/var.c | 66 +++++++++++++++++++++++++++++++++--------------------
1 files changed, 41 insertions(+), 25 deletions(-)
diffs (108 lines):
diff -r 98c5aec704db -r 9306a1120ccc usr.bin/make/var.c
--- a/usr.bin/make/var.c Sun Dec 06 16:24:30 2020 +0000
+++ b/usr.bin/make/var.c Sun Dec 06 17:22:44 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.713 2020/12/06 16:24:30 rillig Exp $ */
+/* $NetBSD: var.c,v 1.714 2020/12/06 17:22:44 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.713 2020/12/06 16:24:30 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.714 2020/12/06 17:22:44 rillig Exp $");
/* A string that may need to be freed after use. */
typedef struct FStr {
@@ -725,7 +725,7 @@
extern char **environ;
static void
-UnexportEnv(void)
+ClearEnv(void)
{
const char *cp;
char **newenv;
@@ -751,6 +751,39 @@
}
static void
+GetVarnamesToUnexport(const char *str,
+ const char **out_args, FStr *out_varnames,
+ UnexportWhat *out_what)
+{
+ UnexportWhat what;
+ FStr varnames = FSTR_INIT;
+
+ str += strlen("unexport");
+ if (strncmp(str, "-env", 4) == 0) {
+ ClearEnv();
+ what = UNEXPORT_ENV;
+ } else {
+ cpp_skip_whitespace(&str);
+ what = str[0] != '\0' ? UNEXPORT_NAMED : UNEXPORT_ALL;
+ if (what == UNEXPORT_NAMED)
+ FStr_Assign(&varnames, str, NULL);
+ }
+ *out_args = str;
+
+ if (what != UNEXPORT_NAMED) {
+ char *expanded;
+ /* Using .MAKE.EXPORTED */
+ (void)Var_Subst("${" MAKE_EXPORTED ":O:u}", VAR_GLOBAL,
+ VARE_WANTRES, &expanded);
+ /* TODO: handle errors */
+ FStr_Assign(&varnames, expanded, expanded);
+ }
+
+ *out_varnames = varnames;
+ *out_what = what;
+}
+
+static void
UnexportVar(const char *varname, UnexportWhat what)
{
Var *v = VarFind(varname, VAR_GLOBAL, FALSE);
@@ -788,27 +821,10 @@
Var_UnExport(const char *str)
{
UnexportWhat what;
- FStr varnames = FSTR_INIT;
-
- str += strlen("unexport");
- if (strncmp(str, "-env", 4) == 0) {
- UnexportEnv();
- what = UNEXPORT_ENV;
- } else {
- cpp_skip_whitespace(&str);
- what = str[0] != '\0' ? UNEXPORT_NAMED : UNEXPORT_ALL;
- if (what == UNEXPORT_NAMED)
- FStr_Assign(&varnames, str, NULL);
- }
-
- if (what != UNEXPORT_NAMED) {
- char *expanded;
- /* Using .MAKE.EXPORTED */
- (void)Var_Subst("${" MAKE_EXPORTED ":O:u}", VAR_GLOBAL,
- VARE_WANTRES, &expanded);
- /* TODO: handle errors */
- FStr_Assign(&varnames, expanded, expanded);
- }
+ FStr varnames;
+ const char *args;
+
+ GetVarnamesToUnexport(str, &args, &varnames, &what);
{
size_t i;
@@ -819,7 +835,7 @@
UnexportVar(varname, what);
}
Words_Free(words);
- if (varnames.str != str)
+ if (varnames.str != args)
Var_Delete(MAKE_EXPORTED, VAR_GLOBAL);
}
Home |
Main Index |
Thread Index |
Old Index