Deleted Added
full compact
var.c (160450) var.c (186713)
1/*-
2 * Copyright (c) 2002 Juli Mallett.
3 * Copyright (c) 1988, 1989, 1990, 1993
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1989 by Berkeley Softworks
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by

--- 26 unchanged lines hidden (view full) ---

35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)var.c 8.3 (Berkeley) 3/19/94
40 */
41
42#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2002 Juli Mallett.
3 * Copyright (c) 1988, 1989, 1990, 1993
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1989 by Berkeley Softworks
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by

--- 26 unchanged lines hidden (view full) ---

35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)var.c 8.3 (Berkeley) 3/19/94
40 */
41
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD: head/usr.bin/make/var.c 160450 2006-07-17 21:05:27Z obrien $");
43__FBSDID("$FreeBSD: head/usr.bin/make/var.c 186713 2009-01-03 10:14:01Z obrien $");
44
45/**
46 * var.c --
47 * Variable-handling functions
48 *
49 * Interface:
50 * Var_Set Set the value of a variable in the given
51 * context. The variable is created if it doesn't

--- 889 unchanged lines hidden (view full) ---

941/**
942 * Add a new variable of name name and value val to the given context.
943 *
944 * Side Effects:
945 * The new variable is placed at the front of the given context
946 * The name and val arguments are duplicated so they may
947 * safely be freed.
948 */
44
45/**
46 * var.c --
47 * Variable-handling functions
48 *
49 * Interface:
50 * Var_Set Set the value of a variable in the given
51 * context. The variable is created if it doesn't

--- 889 unchanged lines hidden (view full) ---

941/**
942 * Add a new variable of name name and value val to the given context.
943 *
944 * Side Effects:
945 * The new variable is placed at the front of the given context
946 * The name and val arguments are duplicated so they may
947 * safely be freed.
948 */
949static void
949static Var *
950VarAdd(const char *name, const char *val, GNode *ctxt)
951{
950VarAdd(const char *name, const char *val, GNode *ctxt)
951{
952 Var *v;
952
953
953 Lst_AtFront(&ctxt->context, VarCreate(name, val, 0));
954 Lst_AtFront(&ctxt->context, v = VarCreate(name, val, 0));
954 DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, name, val));
955 DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, name, val));
956 return (v);
955}
956
957/**
958 * Remove a variable from a context.
959 *
960 * Side Effects:
961 * The Var structure is removed and freed.
962 */

--- 36 unchanged lines hidden (view full) ---

999 /*
1000 * We only look for a variable in the given context since anything
1001 * set here will override anything in a lower context, so there's not
1002 * much point in searching them all just to save a bit of memory...
1003 */
1004 n = VarPossiblyExpand(name, ctxt);
1005 v = VarFindOnly(n, ctxt);
1006 if (v == NULL) {
957}
958
959/**
960 * Remove a variable from a context.
961 *
962 * Side Effects:
963 * The Var structure is removed and freed.
964 */

--- 36 unchanged lines hidden (view full) ---

1001 /*
1002 * We only look for a variable in the given context since anything
1003 * set here will override anything in a lower context, so there's not
1004 * much point in searching them all just to save a bit of memory...
1005 */
1006 n = VarPossiblyExpand(name, ctxt);
1007 v = VarFindOnly(n, ctxt);
1008 if (v == NULL) {
1007 VarAdd(n, val, ctxt);
1008 if (ctxt == VAR_CMD) {
1009 /*
1010 * Any variables given on the command line
1011 * are automatically exported to the
1012 * environment (as per POSIX standard)
1013 */
1014 setenv(n, val, 1);
1015 }
1009 v = VarAdd(n, val, ctxt);
1016 } else {
1017 Buf_Clear(v->val);
1018 Buf_Append(v->val, val);
1010 } else {
1011 Buf_Clear(v->val);
1012 Buf_Append(v->val, val);
1019
1020 if (ctxt == VAR_CMD || (v->flags & VAR_TO_ENV)) {
1021 /*
1022 * Any variables given on the command line
1023 * are automatically exported to the
1024 * environment (as per POSIX standard)
1025 */
1026 setenv(n, val, 1);
1027 }
1028 DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, val));
1029 }
1030
1013 DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, val));
1014 }
1015
1016 if (ctxt == VAR_CMD || (v->flags & VAR_TO_ENV)) {
1017 /*
1018 * Any variables given on the command line
1019 * are automatically exported to the
1020 * environment (as per POSIX standard)
1021 */
1022 setenv(n, val, 1);
1023 }
1024
1031 free(n);
1032}
1033
1034/**
1035 * Set the a global name variable to the value.
1036 */
1037void
1038Var_SetGlobal(const char name[], const char value[])

--- 1281 unchanged lines hidden (view full) ---

2320 *
2321 * Results:
2322 * The resulting string.
2323 *
2324 * Side Effects:
2325 * None. The old string must be freed by the caller
2326 */
2327Buffer *
1025 free(n);
1026}
1027
1028/**
1029 * Set the a global name variable to the value.
1030 */
1031void
1032Var_SetGlobal(const char name[], const char value[])

--- 1281 unchanged lines hidden (view full) ---

2314 *
2315 * Results:
2316 * The resulting string.
2317 *
2318 * Side Effects:
2319 * None. The old string must be freed by the caller
2320 */
2321Buffer *
2328Var_Subst(const char *str, GNode *ctxt, Boolean err)
2322//Var_Subst(const char *var, const char *str, GNode *ctxt, Boolean undefErr)
2323Var_Subst( const char *str, GNode *ctxt, Boolean err)
2329{
2330 Boolean errorReported;
2331 Buffer *buf; /* Buffer for forming things */
2332
2333 /*
2334 * Set TRUE if an error has already been reported to prevent a
2335 * plethora of messages when recursing. XXXHB this comment sounds
2336 * wrong.

--- 275 unchanged lines hidden ---
2324{
2325 Boolean errorReported;
2326 Buffer *buf; /* Buffer for forming things */
2327
2328 /*
2329 * Set TRUE if an error has already been reported to prevent a
2330 * plethora of messages when recursing. XXXHB this comment sounds
2331 * wrong.

--- 275 unchanged lines hidden ---