From 2aeb32481a28e43256eb1cc8a29fe6f04fe3c351 Mon Sep 17 00:00:00 2001 From: dsl Date: Sun, 4 Jan 2009 20:17:36 +0000 Subject: [PATCH] Count () and {} when looking to the '=' that terminates the variable being assigned to. Should fix: A.${B:S/=//} = c --- usr.bin/make/parse.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index 07e84e8ef09e..4c2b809c39bf 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.152 2008/12/13 15:19:29 dsl Exp $ */ +/* $NetBSD: parse.c,v 1.153 2009/01/04 20:17:36 dsl Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: parse.c,v 1.152 2008/12/13 15:19:29 dsl Exp $"; +static char rcsid[] = "$NetBSD: parse.c,v 1.153 2009/01/04 20:17:36 dsl Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: parse.c,v 1.152 2008/12/13 15:19:29 dsl Exp $"); +__RCSID("$NetBSD: parse.c,v 1.153 2009/01/04 20:17:36 dsl Exp $"); #endif #endif /* not lint */ #endif @@ -1496,6 +1496,7 @@ Parse_DoVar(char *line, GNode *ctxt) Boolean freeCp = FALSE; /* TRUE if cp needs to be freed, * i.e. if any variable expansion was * performed */ + int depth; /* * Skip to variable name @@ -1506,9 +1507,19 @@ Parse_DoVar(char *line, GNode *ctxt) /* * Skip to operator character, nulling out whitespace as we go + * XXX Rather than counting () and {} we should look for $ and + * then expand the variable. */ - for (cp = line + 1; *cp != '='; cp++) { - if (isspace ((unsigned char)*cp)) { + for (depth = 0, cp = line + 1; depth != 0 || *cp != '='; cp++) { + if (*cp == '(' || *cp == '{') { + depth++; + continue; + } + if (*cp == ')' || *cp == '}') { + depth--; + continue; + } + if (depth == 0 && isspace ((unsigned char)*cp)) { *cp = '\0'; } }