From 73c5a04dfa25e72e29e9135c3e6c1b24728da3b7 Mon Sep 17 00:00:00 2001 From: Hartmut Brandt Date: Mon, 21 Mar 2005 07:40:33 +0000 Subject: [PATCH] Reduce the number of explicit parameters passed to VarParse() by passing them through struct VarParser. Patch: 7.127 Submitted by: Max Okumoto --- usr.bin/make/var.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index e119980dddd1..8e7909c9b3be 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -105,10 +105,11 @@ __FBSDID("$FreeBSD$"); */ typedef struct VarParser { const char *const input; /* pointer to input string */ + const char *ptr; /* current parser pos in input str */ GNode *ctxt; Boolean err; } VarParser; -static char *VarParse(const char [], VarParser *, size_t *, Boolean *); +static char *VarParse(VarParser *, size_t *, Boolean *); /* * This is a harmless return value for Var_Parse that can be used by Var_Subst @@ -1919,26 +1920,31 @@ VarParseShort(const char input[], VarParser *vp, } static char * -VarParse(const char input[], VarParser *vp, size_t *consumed, Boolean *freeResult) +VarParse(VarParser *vp, size_t *consumed, Boolean *freeResult) { - /* assert(input[0] == '$'); */ + char *value; - *consumed += 1; /* consume '$' */ - input += 1; + /* assert(vp->ptr[0] == '$'); */ - if (input[0] == '\0') { + vp->ptr += 1; /* consume '$' */ + + if (vp->ptr[0] == '\0') { + *consumed += 1; /* consume '$' */ /* Error, there is only a dollar sign in the input string. */ *freeResult = FALSE; - return (vp->err ? var_Error : varNoError); + value = vp->err ? var_Error : varNoError; - } else if (input[0] == OPEN_PAREN || input[0] == OPEN_BRACE) { + } else if (vp->ptr[0] == OPEN_PAREN || vp->ptr[0] == OPEN_BRACE) { + *consumed += 1; /* consume '$' */ /* multi letter variable name */ - return (VarParseLong(input, vp, consumed, freeResult)); + value = VarParseLong(vp->ptr, vp, consumed, freeResult); } else { + *consumed += 1; /* consume '$' */ /* single letter variable name */ - return (VarParseShort(input, vp, consumed, freeResult)); + value = VarParseShort(vp->ptr, vp, consumed, freeResult); } + return (value); } /*- @@ -1970,12 +1976,13 @@ Var_Parse(const char input[], GNode *ctxt, Boolean err, size_t *consumed, Boolean *freeResult) { VarParser vp = { + input, input, ctxt, err }; - return VarParse(input, &vp, consumed, freeResult); + return VarParse(&vp, consumed, freeResult); } /*-