From aeadeefcdf31d7bbd34b267f1256ffe591757e96 Mon Sep 17 00:00:00 2001 From: Hartmut Brandt Date: Tue, 1 Mar 2005 07:58:18 +0000 Subject: [PATCH] Reverse a condition so that the else clause can be changed to a fallthrough. Patch: 7.82 Submitted by: Max Okumoto --- usr.bin/make/var.c | 77 +++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index fb7ae0f44a3..c0a58981962 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -1679,55 +1679,23 @@ VarParseLong(char foo[], GNode *ctxt, Boolean err, size_t *lengthPtr, } } +/** + * If it's not bounded by braces of some sort, life is much simpler. + * We just need to check for the first character and return the value + * if it exists. + */ static char * VarParseShort(const char input[], GNode *ctxt, Boolean err, size_t *lengthPtr, Boolean *freePtr) { - /* - * If it's not bounded by braces of some sort, life is much simpler. - * We just need to check for the first character and return the value - * if it exists. - */ - Var *v; /* Variable in invocation */ char name[2]; + Var *v; name[0] = input[1]; name[1] = '\0'; v = VarFind(name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); - if (v == NULL) { - if ((ctxt == VAR_CMD) || (ctxt == VAR_GLOBAL)) { - /* - * If substituting a local variable in a non-local - * context, assume it's for dynamic source stuff. We - * have to handle this specially and return the - * longhand for the variable with the dollar sign - * escaped so it makes it back to the caller. Only - * four of the local variables are treated specially - * as they are the only four that will be set when - * dynamic sources are expanded. - */ - /* XXX: It looks like $% and $! are reversed here */ - *freePtr = FALSE; - *lengthPtr = 2; - switch (input[1]) { - case '@': - return ("$(.TARGET)"); - case '%': - return ("$(.ARCHIVE)"); - case '*': - return ("$(.PREFIX)"); - case '!': - return ("$(.MEMBER)"); - default: - return (err ? var_Error : varNoError); - } - } else { - *freePtr = FALSE; - *lengthPtr = 2; - return (err ? var_Error : varNoError); - } - } else { + if (v != NULL) { char *result; result = VarExpand(v, ctxt, err); @@ -1740,6 +1708,37 @@ VarParseShort(const char input[], GNode *ctxt, Boolean err, size_t *lengthPtr, *lengthPtr = 2; return (result); } + + /* + * If substituting a local variable in a non-local context, assume + * it's for dynamic source stuff. We have to handle this specially + * and return the longhand for the variable with the dollar sign + * escaped so it makes it back to the caller. Only four of the local + * variables are treated specially as they are the only four that + * will be set when dynamic sources are expanded. + */ + if ((ctxt == VAR_CMD) || (ctxt == VAR_GLOBAL)) { + *freePtr = FALSE; + *lengthPtr = 2; + + /* XXX: It looks like $% and $! are reversed here */ + switch (input[1]) { + case '@': + return ("$(.TARGET)"); + case '%': + return ("$(.ARCHIVE)"); + case '*': + return ("$(.PREFIX)"); + case '!': + return ("$(.MEMBER)"); + default: + return (err ? var_Error : varNoError); + } + } + + *freePtr = FALSE; + *lengthPtr = 2; + return (err ? var_Error : varNoError); } /*-