make(1): migrate to Var_ParsePP in Var_Parse and Var_Subst

This commit is contained in:
rillig 2020-09-07 07:10:56 +00:00
parent 3aea87db6a
commit 11dcb9bdaf

View File

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.489 2020/09/07 07:04:30 rillig Exp $ */
/* $NetBSD: var.c,v 1.490 2020/09/07 07:10:56 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: var.c,v 1.489 2020/09/07 07:04:30 rillig Exp $";
static char rcsid[] = "$NetBSD: var.c,v 1.490 2020/09/07 07:10:56 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: var.c,v 1.489 2020/09/07 07:04:30 rillig Exp $");
__RCSID("$NetBSD: var.c,v 1.490 2020/09/07 07:10:56 rillig Exp $");
#endif
#endif /* not lint */
#endif
@ -3429,7 +3429,7 @@ Var_Parse(const char * const str, GNode *ctxt, VarEvalFlags eflags,
* Skip to the end character or a colon, whichever comes first.
*/
depth = 1;
for (tstr = str + 2; *tstr != '\0'; tstr++) {
for (tstr = str + 2; *tstr != '\0';) {
/* Track depth so we can spot parse errors. */
if (*tstr == startc)
depth++;
@ -3441,15 +3441,14 @@ Var_Parse(const char * const str, GNode *ctxt, VarEvalFlags eflags,
break;
/* A variable inside a variable, expand. */
if (*tstr == '$') {
int rlen;
void *freeIt;
const char *rval = Var_Parse(tstr, ctxt, eflags, &rlen,
&freeIt);
const char *rval = Var_ParsePP(&tstr, ctxt, eflags, &freeIt);
Buf_AddStr(&namebuf, rval);
free(freeIt);
tstr += rlen - 1;
} else
} else {
Buf_AddByte(&namebuf, *tstr);
tstr++;
}
}
if (*tstr == ':') {
haveModifier = TRUE;
@ -3696,9 +3695,9 @@ Var_Subst(const char *str, GNode *ctxt, VarEvalFlags eflags)
continue;
Buf_AddBytesBetween(&buf, cp, str);
} else {
int length;
const char *nested_str = str;
void *freeIt;
const char *val = Var_Parse(str, ctxt, eflags, &length, &freeIt);
const char *val = Var_ParsePP(&nested_str, ctxt, eflags, &freeIt);
if (val == var_Error || val == varNoError) {
/*
@ -3708,7 +3707,7 @@ Var_Subst(const char *str, GNode *ctxt, VarEvalFlags eflags)
* the string...
*/
if (oldVars) {
str += length;
str = nested_str;
} else if ((eflags & VARE_UNDEFERR) || val == var_Error) {
/*
* If variable is undefined, complain and skip the
@ -3717,18 +3716,18 @@ Var_Subst(const char *str, GNode *ctxt, VarEvalFlags eflags)
*/
if (!errorReported) {
Parse_Error(PARSE_FATAL, "Undefined variable \"%.*s\"",
length, str);
(int)(size_t)(nested_str - str), str);
}
str += length;
str = nested_str;
errorReported = TRUE;
} else {
Buf_AddByte(&buf, *str);
str += 1;
str++;
}
} else {
size_t val_len;
str += length;
str = nested_str;
val_len = strlen(val);
Buf_AddBytes(&buf, val, val_len);