Use defines for character constants for open and closing braces and
parantheses. This helps editors to find its way through the horrible mess of Var_Parse. Rewrite a for() loop into a while() to make it clearer. Submitted by: Max Okumoto <okumoto@ucsd.edu>
This commit is contained in:
parent
1217303f75
commit
2890fef88d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=141583
@ -136,6 +136,11 @@ GNode *VAR_CMD; /* variables defined on the command-line */
|
||||
#define FIND_GLOBAL 0x2 /* look in VAR_GLOBAL as well */
|
||||
#define FIND_ENV 0x4 /* look in the environment also */
|
||||
|
||||
#define OPEN_PAREN '('
|
||||
#define CLOSE_PAREN ')'
|
||||
#define OPEN_BRACE '{'
|
||||
#define CLOSE_BRACE '}'
|
||||
|
||||
static char *VarGetPattern(GNode *, int, char **, int, int *, size_t *,
|
||||
VarPattern *);
|
||||
static int VarPrintVar(void *, void *);
|
||||
@ -732,14 +737,14 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags,
|
||||
} else {
|
||||
char *cp2 = &cp[1];
|
||||
|
||||
if (*cp2 == '(' || *cp2 == '{') {
|
||||
if (*cp2 == OPEN_PAREN || *cp2 == OPEN_BRACE) {
|
||||
/*
|
||||
* Find the end of this variable reference
|
||||
* and suck it in without further ado.
|
||||
* It will be interperated later.
|
||||
*/
|
||||
int have = *cp2;
|
||||
int want = (*cp2 == '(') ? ')' : '}';
|
||||
int want = (*cp2 == OPEN_PAREN) ? CLOSE_PAREN : CLOSE_BRACE;
|
||||
int depth = 1;
|
||||
|
||||
for (++cp2; *cp2 != '\0' && depth > 0; ++cp2) {
|
||||
@ -886,7 +891,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr,
|
||||
dynamic = FALSE;
|
||||
start = str;
|
||||
|
||||
if (str[1] != '(' && str[1] != '{') {
|
||||
if (str[1] != OPEN_PAREN && str[1] != OPEN_BRACE) {
|
||||
/*
|
||||
* 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
|
||||
@ -942,7 +947,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr,
|
||||
Buffer *buf = Buf_Init(MAKE_BSIZE);
|
||||
|
||||
startc = str[1];
|
||||
endc = startc == '(' ? ')' : '}';
|
||||
endc = (startc == OPEN_PAREN) ? CLOSE_PAREN : CLOSE_BRACE;
|
||||
|
||||
/*
|
||||
* Skip to the end character or a colon, whichever comes first,
|
||||
@ -1763,11 +1768,14 @@ Var_Subst(const char *var, char *str, GNode *ctxt, Boolean undefErr)
|
||||
} while (str[0] != '$' && str[0] != '\0');
|
||||
Buf_AppendRange(buf, cp, str);
|
||||
} else {
|
||||
/*
|
||||
* Variable invocation.
|
||||
*/
|
||||
if (var != NULL) {
|
||||
int expand;
|
||||
for (;;) {
|
||||
if (str[1] != '(' && str[1] != '{') {
|
||||
if (str[1] != *var || var[1] != '\0') {
|
||||
if (str[1] != OPEN_PAREN && str[1] != OPEN_BRACE) {
|
||||
if (str[1] != var[0] || var[1] != '\0') {
|
||||
Buf_AddBytes(buf, 2, (const Byte *)str);
|
||||
str += 2;
|
||||
expand = FALSE;
|
||||
@ -1775,15 +1783,18 @@ Var_Subst(const char *var, char *str, GNode *ctxt, Boolean undefErr)
|
||||
expand = TRUE;
|
||||
break;
|
||||
} else {
|
||||
char *p;
|
||||
const char *p = str + 2;
|
||||
|
||||
/*
|
||||
* Scan up to the end of the variable name.
|
||||
*/
|
||||
for (p = &str[2]; *p &&
|
||||
*p != ':' && *p != ')' && *p != '}'; p++)
|
||||
if (*p == '$')
|
||||
break;
|
||||
while (*p != '\0' &&
|
||||
*p != ':' &&
|
||||
*p != CLOSE_PAREN &&
|
||||
*p != CLOSE_BRACE &&
|
||||
*p != '$') {
|
||||
++p;
|
||||
}
|
||||
/*
|
||||
* A variable inside the variable. We cannot expand
|
||||
* the external variable yet, so we try again with
|
||||
|
Loading…
Reference in New Issue
Block a user