diff options
Diffstat (limited to 'usr.bin/make/for.c')
-rw-r--r-- | usr.bin/make/for.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/usr.bin/make/for.c b/usr.bin/make/for.c index e2df76c..a083630 100644 --- a/usr.bin/make/for.c +++ b/usr.bin/make/for.c @@ -72,7 +72,7 @@ __FBSDID("$FreeBSD$"); static int forLevel = 0; /* Nesting level */ static char *forVar; /* Iteration variable */ static Buffer forBuf; /* Commands in loop */ -static Lst *forLst; /* List of items */ +static Lst forLst; /* List of items */ /* * State of a for loop. @@ -80,7 +80,7 @@ static Lst *forLst; /* List of items */ typedef struct _For { Buffer buf; /* Unexpanded buffer */ char* var; /* Index name */ - Lst *lst; /* List of variables */ + Lst lst; /* List of variables */ int lineno; /* Line # */ } For; @@ -168,14 +168,14 @@ For_Eval(char *line) /* * Make a list with the remaining words */ - forLst = Lst_Init(); + Lst_Init(&forLst); buf = Buf_Init(0); sub = Var_Subst(NULL, ptr, VAR_CMD, FALSE); #define ADDWORD() \ Buf_AddBytes(buf, ptr - wrd, (Byte *)wrd), \ Buf_AddByte(buf, (Byte)'\0'), \ - Lst_AtFront(forLst, Buf_GetAll(buf, &varlen)), \ + Lst_AtFront(&forLst, Buf_GetAll(buf, &varlen)), \ Buf_Destroy(buf, FALSE) for (ptr = sub; *ptr && isspace((unsigned char)*ptr); ptr++) @@ -277,19 +277,22 @@ For_Run(int lineno) { For arg; - if (forVar == NULL || forBuf == NULL || forLst == NULL) + if (forVar == NULL || forBuf == NULL) return; arg.var = forVar; arg.buf = forBuf; - arg.lst = forLst; + + /* move the forLst to the arg to get it free for nested for's */ + Lst_Init(&arg.lst); + Lst_Concat(&arg.lst, &forLst, LST_CONCLINK); + arg.lineno = lineno; forVar = NULL; forBuf = NULL; - forLst = NULL; - Lst_ForEach(arg.lst, ForExec, &arg); + Lst_ForEach(&arg.lst, ForExec, &arg); free(arg.var); - Lst_Destroy(arg.lst, free); + Lst_Destroy(&arg.lst, free); Buf_Destroy(arg.buf, TRUE); } |