Fix splitting into words of the .for expression to allow for

spaces in values.  Without this change, the following valid
call broke due to parsing of .MAKEFLAGS in bsd.symver.mk:

cd /usr/src/lib/libc && make -n DEBUG_FLAGS="-DFOO -DBAR"

Spotted by:	Igor Sysoev
Submitted by:	Maxim Dounin, ru
MFC after:	1 week
This commit is contained in:
ru 2008-03-24 12:33:28 +00:00
parent 430a85c91d
commit 98fbc814ae

View File

@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
#include "lst.h"
#include "make.h"
#include "parse.h"
#include "str.h"
#include "util.h"
#include "var.h"
@ -97,6 +98,8 @@ For_For(char *line)
char *sub;
Buffer *buf;
size_t varlen;
int i;
ArgArray words;
ptr = line;
@ -148,33 +151,16 @@ For_For(char *line)
/*
* Make a list with the remaining words
* XXX should use brk_string here.
*/
sub = Buf_Peel(Var_Subst(ptr, VAR_CMD, FALSE));
for (ptr = sub; *ptr != '\0' && isspace((u_char)*ptr); ptr++)
;
brk_string(&words, sub, FALSE);
Lst_Init(&forLst);
buf = Buf_Init(0);
for (wrd = ptr; *ptr != '\0'; ptr++) {
if (isspace((u_char)*ptr)) {
Buf_AppendRange(buf, wrd, ptr);
Lst_AtFront(&forLst, Buf_Peel(buf));
buf = Buf_Init(0);
while (*ptr != '\0' && isspace((u_char)*ptr))
ptr++;
wrd = ptr--;
}
for (i = 1; i < words.argc; i++) {
if (words.argv[i][0] != '\0')
Lst_AtFront(&forLst, estrdup(words.argv[i]));
}
ArgArray_Done(&words);
DEBUGF(FOR, ("For: Iterator %s List %s\n", forVar, sub));
if (ptr - wrd > 0) {
Buf_AppendRange(buf, wrd, ptr);
Lst_AtFront(&forLst, Buf_Peel(buf));
} else {
Buf_Destroy(buf, TRUE);
}
free(sub);
forBuf = Buf_Init(0);