From b2bb207f6bdb8a63b33a853d91b4cf7f34201950 Mon Sep 17 00:00:00 2001 From: harti Date: Tue, 22 Mar 2005 08:16:09 +0000 Subject: [PATCH] Make some callers of VarFind using the same code structure. Patch: 7.161 Submitted by: Max Okumoto --- usr.bin/make/var.c | 61 +++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index a5d7652b714e..43a1c33629de 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -489,26 +489,27 @@ Var_Append(const char *name, const char *val, GNode *ctxt) n = VarPossiblyExpand(name, ctxt); v = VarFind(n, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0); - if (v == NULL) { VarAdd(n, val, ctxt); + + } else if (v->flags & VAR_FROM_ENV) { + Buf_AddByte(v->val, (Byte)' '); + Buf_Append(v->val, val); + DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, Buf_Data(v->val))); + /* + * If the original variable came from the + * environment, we have to install it in the global + * context (we could place it in the environment, but + * then we should provide a way to export other + * variables...) + */ + v->flags &= ~VAR_FROM_ENV; + Lst_AtFront(&ctxt->context, v); + } else { Buf_AddByte(v->val, (Byte)' '); Buf_Append(v->val, val); - DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, Buf_Data(v->val))); - - if (v->flags & VAR_FROM_ENV) { - /* - * If the original variable came from the - * environment, we have to install it in the global - * context (we could place it in the environment, but - * then we should provide a way to export other - * variables...) - */ - v->flags &= ~VAR_FROM_ENV; - Lst_AtFront(&ctxt->context, v); - } } free(n); } @@ -534,14 +535,17 @@ Var_Exists(const char *name, GNode *ctxt) n = VarPossiblyExpand(name, ctxt); v = VarFind(n, ctxt, FIND_CMD | FIND_GLOBAL | FIND_ENV); - free(n); - if (v == NULL) { + free(n); return (FALSE); } else if (v->flags & VAR_FROM_ENV) { VarDestroy(v, TRUE); + free(n); + return (TRUE); + } else { + free(n); + return (TRUE); } - return (TRUE); } /*- @@ -561,22 +565,23 @@ Var_Value(const char *name, GNode *ctxt, char **frp) { Var *v; char *n; + char *p; n = VarPossiblyExpand(name, ctxt); v = VarFind(n, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); - free(n); - *frp = NULL; - if (v != NULL) { - char *p = Buf_Data(v->val); - - if (v->flags & VAR_FROM_ENV) { - VarDestroy(v, FALSE); - *frp = p; - } - return (p); + if (v == NULL) { + p = NULL; + *frp = NULL; + } else if (v->flags & VAR_FROM_ENV) { + p = Buf_Data(v->val); + *frp = p; + VarDestroy(v, FALSE); } else { - return (NULL); + p = Buf_Data(v->val); + *frp = NULL; } + free(n); + return (p); } /*-