1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-15 10:17:20 +00:00

Make some callers of VarFind using the same code structure.

Patch:		7.161

Submitted by:	Max Okumoto <okumoto@ucsd.edu>
This commit is contained in:
Hartmut Brandt 2005-03-22 08:16:09 +00:00
parent 29b59e2865
commit a4c193bbe2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=143968

View File

@ -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);
}
/*-