Fri Oct 30 06:44:57 2020 UTC ()
make(1): clean up and update module comment in var.c


(rillig)
diff -r1.591 -r1.592 src/usr.bin/make/var.c

cvs diff -r1.591 -r1.592 src/usr.bin/make/var.c (expand / switch to unified diff)

--- src/usr.bin/make/var.c 2020/10/27 07:16:27 1.591
+++ src/usr.bin/make/var.c 2020/10/30 06:44:57 1.592
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.591 2020/10/27 07:16:27 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.592 2020/10/30 06:44:57 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -58,80 +58,88 @@ @@ -58,80 +58,88 @@
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71/*- 71/*
72 * var.c -- 72 * Handling of variables and the expressions formed from them.
73 * Variable-handling functions 73 *
 74 * Variables are set using lines of the form VAR=value. Both the variable
 75 * name and the value can contain references to other variables, by using
 76 * expressions like ${VAR}, ${VAR:Modifiers}, ${${VARNAME}} or ${VAR:${MODS}}.
74 * 77 *
75 * Interface: 78 * Interface:
76 * Var_Set Set the value of a variable in the given 79 * Var_Init Initialize this module.
77 * context. The variable is created if it doesn't 80 *
78 * yet exist. 81 * Var_End Clean up the module.
79 * 82 *
80 * Var_Append Append more characters to an existing variable 83 * Var_Set Set the value of the variable, creating it if
81 * in the given context. The variable needn't 84 * necessary.
82 * exist already -- it will be created if it doesn't. 85 *
83 * A space is placed between the old value and the 86 * Var_Append Append more characters to the variable, creating it if
84 * new one. 87 * necessary. A space is placed between the old value and
 88 * the new one.
85 * 89 *
86 * Var_Exists See if a variable exists. 90 * Var_Exists See if a variable exists.
87 * 91 *
88 * Var_Value Return the unexpanded value of a variable in a 92 * Var_Value Return the unexpanded value of a variable, or NULL if
89 * context or NULL if the variable is undefined. 93 * the variable is undefined.
90 * 94 *
91 * Var_Subst Substitute either a single variable or all 95 * Var_Subst Substitute all variable expressions in a string.
92 * variables in a string, using the given context. 
93 * 96 *
94 * Var_Parse Parse a variable expansion from a string and 97 * Var_Parse Parse a variable expression such as ${VAR:Mpattern}.
95 * return the result and the number of characters 
96 * consumed. 
97 * 98 *
98 * Var_Delete Delete a variable in a context. 99 * Var_Delete Delete a variable.
99 * 100 *
100 * Var_Init Initialize this module. 101 * Var_ExportVars Export some or even all variables to the environment
 102 * of this process and its child processes.
 103 *
 104 * Var_Export Export the variable to the environment of this process
 105 * and its child processes.
 106 *
 107 * Var_UnExport Don't export the variable anymore.
101 * 108 *
102 * Debugging: 109 * Debugging:
103 * Var_Dump Print out all variables defined in the given 110 * Var_Stats Print out hashing statistics if in -dh mode.
104 * context. 111 *
 112 * Var_Dump Print out all variables defined in the given context.
105 * 113 *
106 * XXX: There's a lot of duplication in these functions. 114 * XXX: There's a lot of duplication in these functions.
107 */ 115 */
108 116
109#include <sys/stat.h> 117#include <sys/stat.h>
110#ifndef NO_REGEX 118#ifndef NO_REGEX
111#include <sys/types.h> 119#include <sys/types.h>
112#include <regex.h> 120#include <regex.h>
113#endif 121#endif
114#include <inttypes.h> 122#include <inttypes.h>
115#include <limits.h> 123#include <limits.h>
116#include <time.h> 124#include <time.h>
117 125
118#include "make.h" 126#include "make.h"
119#include "dir.h" 127#include "dir.h"
120#include "job.h" 128#include "job.h"
121#include "metachar.h" 129#include "metachar.h"
122 130
123/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ 131/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
124MAKE_RCSID("$NetBSD: var.c,v 1.591 2020/10/27 07:16:27 rillig Exp $"); 132MAKE_RCSID("$NetBSD: var.c,v 1.592 2020/10/30 06:44:57 rillig Exp $");
125 133
126#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1) 134#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
127#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2) 135#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
128#define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3) 136#define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3)
129#define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4) 137#define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4)
130 138
131ENUM_FLAGS_RTTI_3(VarEvalFlags, 139ENUM_FLAGS_RTTI_3(VarEvalFlags,
132 VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN); 140 VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN);
133 141
134/* 142/*
135 * This lets us tell if we have replaced the original environ 143 * This lets us tell if we have replaced the original environ
136 * (which we cannot free). 144 * (which we cannot free).
137 */ 145 */