for.c revision 1.109 1 1.109 rillig /* $NetBSD: for.c,v 1.109 2020/10/26 07:03:47 rillig Exp $ */
2 1.3 christos
3 1.1 cgd /*
4 1.1 cgd * Copyright (c) 1992, The Regents of the University of California.
5 1.1 cgd * All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.15 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 cgd * may be used to endorse or promote products derived from this software
17 1.1 cgd * without specific prior written permission.
18 1.1 cgd *
19 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 cgd * SUCH DAMAGE.
30 1.1 cgd */
31 1.1 cgd
32 1.1 cgd /*-
33 1.80 rillig * Handling of .for/.endfor loops in a makefile.
34 1.80 rillig *
35 1.80 rillig * For loops are of the form:
36 1.80 rillig *
37 1.80 rillig * .for <varname...> in <value...>
38 1.80 rillig * ...
39 1.80 rillig * .endfor
40 1.80 rillig *
41 1.80 rillig * When a .for line is parsed, all following lines are accumulated into a
42 1.80 rillig * buffer, up to but excluding the corresponding .endfor line. To find the
43 1.80 rillig * corresponding .endfor, the number of nested .for and .endfor directives
44 1.80 rillig * are counted.
45 1.80 rillig *
46 1.80 rillig * During parsing, any nested .for loops are just passed through; they get
47 1.80 rillig * handled recursively in For_Eval when the enclosing .for loop is evaluated
48 1.80 rillig * in For_Run.
49 1.80 rillig *
50 1.80 rillig * When the .for loop has been parsed completely, the variable expressions
51 1.80 rillig * for the iteration variables are replaced with expressions of the form
52 1.80 rillig * ${:Uvalue}, and then this modified body is "included" as a special file.
53 1.1 cgd *
54 1.1 cgd * Interface:
55 1.88 rillig * For_Eval Evaluate the loop in the passed line.
56 1.88 rillig *
57 1.1 cgd * For_Run Run accumulated loop
58 1.1 cgd */
59 1.1 cgd
60 1.1 cgd #include "make.h"
61 1.1 cgd
62 1.83 rillig /* "@(#)for.c 8.1 (Berkeley) 6/6/93" */
63 1.109 rillig MAKE_RCSID("$NetBSD: for.c,v 1.109 2020/10/26 07:03:47 rillig Exp $");
64 1.83 rillig
65 1.106 rillig /* The .for loop substitutes the items as ${:U<value>...}, which means
66 1.106 rillig * that characters that break this syntax must be backslash-escaped. */
67 1.94 rillig typedef enum ForEscapes {
68 1.75 rillig FOR_SUB_ESCAPE_CHAR = 0x0001,
69 1.75 rillig FOR_SUB_ESCAPE_BRACE = 0x0002,
70 1.75 rillig FOR_SUB_ESCAPE_PAREN = 0x0004
71 1.75 rillig } ForEscapes;
72 1.42 dsl
73 1.63 rillig static int forLevel = 0; /* Nesting level */
74 1.1 cgd
75 1.96 rillig /* One of the variables to the left of the "in" in a .for loop. */
76 1.96 rillig typedef struct ForVar {
77 1.96 rillig char *name;
78 1.96 rillig size_t len;
79 1.96 rillig } ForVar;
80 1.96 rillig
81 1.1 cgd /*
82 1.1 cgd * State of a for loop.
83 1.1 cgd */
84 1.86 rillig typedef struct For {
85 1.103 rillig Buffer body; /* Unexpanded body of the loop */
86 1.103 rillig Vector /* of ForVar */ vars; /* Iteration variables */
87 1.102 rillig Words items; /* Substitution items */
88 1.103 rillig Buffer curBody; /* Expanded body of the current iteration */
89 1.69 rillig /* Is any of the names 1 character long? If so, when the variable values
90 1.69 rillig * are substituted, the parser must handle $V expressions as well, not
91 1.69 rillig * only ${V} and $(V). */
92 1.69 rillig Boolean short_var;
93 1.103 rillig unsigned int sub_next; /* Where to continue iterating */
94 1.2 jtc } For;
95 1.1 cgd
96 1.63 rillig static For *accumFor; /* Loop being accumulated */
97 1.1 cgd
98 1.96 rillig static void
99 1.96 rillig ForAddVar(For *f, const char *name, size_t len)
100 1.96 rillig {
101 1.96 rillig ForVar *var = Vector_Push(&f->vars);
102 1.96 rillig var->name = bmake_strldup(name, len);
103 1.96 rillig var->len = len;
104 1.96 rillig }
105 1.96 rillig
106 1.96 rillig static void
107 1.109 rillig For_Free(For *f)
108 1.96 rillig {
109 1.109 rillig Buf_Destroy(&f->body, TRUE);
110 1.96 rillig
111 1.109 rillig while (f->vars.len > 0) {
112 1.109 rillig ForVar *var = Vector_Pop(&f->vars);
113 1.109 rillig free(var->name);
114 1.109 rillig }
115 1.109 rillig Vector_Done(&f->vars);
116 1.96 rillig
117 1.109 rillig Words_Free(f->items);
118 1.109 rillig Buf_Destroy(&f->curBody, TRUE);
119 1.96 rillig
120 1.109 rillig free(f);
121 1.43 dsl }
122 1.43 dsl
123 1.99 rillig static ForEscapes
124 1.99 rillig GetEscapes(const char *word)
125 1.99 rillig {
126 1.99 rillig const char *p;
127 1.99 rillig ForEscapes escapes = 0;
128 1.99 rillig
129 1.99 rillig for (p = word; *p != '\0'; p++) {
130 1.99 rillig switch (*p) {
131 1.99 rillig case ':':
132 1.99 rillig case '$':
133 1.99 rillig case '\\':
134 1.99 rillig escapes |= FOR_SUB_ESCAPE_CHAR;
135 1.99 rillig break;
136 1.99 rillig case ')':
137 1.99 rillig escapes |= FOR_SUB_ESCAPE_PAREN;
138 1.99 rillig break;
139 1.99 rillig case '}':
140 1.99 rillig escapes |= FOR_SUB_ESCAPE_BRACE;
141 1.99 rillig break;
142 1.99 rillig }
143 1.99 rillig }
144 1.99 rillig return escapes;
145 1.99 rillig }
146 1.99 rillig
147 1.106 rillig static Boolean
148 1.106 rillig IsFor(const char *p)
149 1.106 rillig {
150 1.106 rillig return p[0] == 'f' && p[1] == 'o' && p[2] == 'r' && ch_isspace(p[3]);
151 1.106 rillig }
152 1.106 rillig
153 1.106 rillig static Boolean
154 1.106 rillig IsEndfor(const char *p)
155 1.106 rillig {
156 1.106 rillig return p[0] == 'e' && strncmp(p, "endfor", 6) == 0 &&
157 1.106 rillig (p[6] == '\0' || ch_isspace(p[6]));
158 1.106 rillig }
159 1.106 rillig
160 1.70 rillig /* Evaluate the for loop in the passed line. The line looks like this:
161 1.70 rillig * .for <varname...> in <value...>
162 1.1 cgd *
163 1.13 wiz * Input:
164 1.13 wiz * line Line to parse
165 1.13 wiz *
166 1.1 cgd * Results:
167 1.35 dsl * 0: Not a .for statement, parse the line
168 1.35 dsl * 1: We found a for loop
169 1.35 dsl * -1: A .for statement with a bad syntax error, discard.
170 1.1 cgd */
171 1.1 cgd int
172 1.73 rillig For_Eval(const char *line)
173 1.1 cgd {
174 1.109 rillig For *f;
175 1.105 rillig const char *p;
176 1.33 dsl
177 1.108 rillig p = line + 1; /* skip the '.' */
178 1.105 rillig cpp_skip_whitespace(&p);
179 1.43 dsl
180 1.106 rillig if (!IsFor(p)) {
181 1.106 rillig if (IsEndfor(p)) {
182 1.32 dsl Parse_Error(PARSE_FATAL, "for-less endfor");
183 1.32 dsl return -1;
184 1.32 dsl }
185 1.32 dsl return 0;
186 1.32 dsl }
187 1.105 rillig p += 3;
188 1.1 cgd
189 1.32 dsl /*
190 1.32 dsl * we found a for loop, and now we are going to parse it.
191 1.32 dsl */
192 1.1 cgd
193 1.109 rillig f = bmake_malloc(sizeof *f);
194 1.109 rillig Buf_Init(&f->body, 0);
195 1.109 rillig Vector_Init(&f->vars, sizeof(ForVar));
196 1.109 rillig f->items.words = NULL;
197 1.109 rillig f->items.freeIt = NULL;
198 1.109 rillig Buf_Init(&f->curBody, 0);
199 1.109 rillig f->short_var = FALSE;
200 1.109 rillig f->sub_next = 0;
201 1.43 dsl
202 1.33 dsl /* Grab the variables. Terminate on "in". */
203 1.93 rillig for (;;) {
204 1.72 rillig size_t len;
205 1.72 rillig
206 1.105 rillig cpp_skip_whitespace(&p);
207 1.105 rillig if (*p == '\0') {
208 1.33 dsl Parse_Error(PARSE_FATAL, "missing `in' in for");
209 1.109 rillig For_Free(f);
210 1.33 dsl return -1;
211 1.33 dsl }
212 1.72 rillig
213 1.104 rillig /* XXX: This allows arbitrary variable names; see directive-for.mk. */
214 1.106 rillig for (len = 1; p[len] != '\0' && !ch_isspace(p[len]); len++)
215 1.33 dsl continue;
216 1.104 rillig
217 1.105 rillig if (len == 2 && p[0] == 'i' && p[1] == 'n') {
218 1.105 rillig p += 2;
219 1.33 dsl break;
220 1.33 dsl }
221 1.43 dsl if (len == 1)
222 1.109 rillig f->short_var = TRUE;
223 1.69 rillig
224 1.109 rillig ForAddVar(f, p, len);
225 1.105 rillig p += len;
226 1.32 dsl }
227 1.1 cgd
228 1.109 rillig if (f->vars.len == 0) {
229 1.32 dsl Parse_Error(PARSE_FATAL, "no iteration variables in for");
230 1.109 rillig For_Free(f);
231 1.32 dsl return -1;
232 1.32 dsl }
233 1.4 christos
234 1.105 rillig cpp_skip_whitespace(&p);
235 1.32 dsl
236 1.72 rillig {
237 1.85 rillig char *items;
238 1.105 rillig (void)Var_Subst(p, VAR_GLOBAL, VARE_WANTRES, &items);
239 1.85 rillig /* TODO: handle errors */
240 1.109 rillig f->items = Str_Words(items, FALSE);
241 1.72 rillig free(items);
242 1.65 rillig
243 1.109 rillig if (f->items.len == 1 && f->items.words[0][0] == '\0')
244 1.109 rillig f->items.len = 0; /* .for var in ${:U} */
245 1.72 rillig }
246 1.72 rillig
247 1.72 rillig {
248 1.95 rillig size_t nitems, nvars;
249 1.7 christos
250 1.109 rillig if ((nitems = f->items.len) > 0 && nitems % (nvars = f->vars.len)) {
251 1.49 sjg Parse_Error(PARSE_FATAL,
252 1.65 rillig "Wrong number of words (%zu) in .for substitution list"
253 1.107 rillig " with %zu variables", nitems, nvars);
254 1.49 sjg /*
255 1.49 sjg * Return 'success' so that the body of the .for loop is
256 1.49 sjg * accumulated.
257 1.49 sjg * Remove all items so that the loop doesn't iterate.
258 1.49 sjg */
259 1.109 rillig f->items.len = 0;
260 1.49 sjg }
261 1.32 dsl }
262 1.32 dsl
263 1.109 rillig accumFor = f;
264 1.32 dsl forLevel = 1;
265 1.32 dsl return 1;
266 1.32 dsl }
267 1.7 christos
268 1.35 dsl /*
269 1.35 dsl * Add another line to a .for loop.
270 1.81 rillig * Returns FALSE when the matching .endfor is reached.
271 1.35 dsl */
272 1.81 rillig Boolean
273 1.73 rillig For_Accum(const char *line)
274 1.32 dsl {
275 1.73 rillig const char *ptr = line;
276 1.26 dsl
277 1.26 dsl if (*ptr == '.') {
278 1.92 rillig ptr++;
279 1.92 rillig cpp_skip_whitespace(&ptr);
280 1.1 cgd
281 1.106 rillig if (IsEndfor(ptr)) {
282 1.89 rillig DEBUG1(FOR, "For: end for %d\n", forLevel);
283 1.32 dsl if (--forLevel <= 0)
284 1.81 rillig return FALSE;
285 1.106 rillig } else if (IsFor(ptr)) {
286 1.1 cgd forLevel++;
287 1.89 rillig DEBUG1(FOR, "For: new loop %d\n", forLevel);
288 1.1 cgd }
289 1.1 cgd }
290 1.1 cgd
291 1.103 rillig Buf_AddStr(&accumFor->body, line);
292 1.103 rillig Buf_AddByte(&accumFor->body, '\n');
293 1.81 rillig return TRUE;
294 1.1 cgd }
295 1.1 cgd
296 1.42 dsl
297 1.59 rillig static size_t
298 1.45 dsl for_var_len(const char *var)
299 1.45 dsl {
300 1.45 dsl char ch, var_start, var_end;
301 1.61 rillig int depth;
302 1.61 rillig size_t len;
303 1.45 dsl
304 1.45 dsl var_start = *var;
305 1.45 dsl if (var_start == 0)
306 1.45 dsl /* just escape the $ */
307 1.45 dsl return 0;
308 1.45 dsl
309 1.45 dsl if (var_start == '(')
310 1.45 dsl var_end = ')';
311 1.45 dsl else if (var_start == '{')
312 1.45 dsl var_end = '}';
313 1.45 dsl else
314 1.45 dsl /* Single char variable */
315 1.45 dsl return 1;
316 1.45 dsl
317 1.61 rillig depth = 1;
318 1.45 dsl for (len = 1; (ch = var[len++]) != 0;) {
319 1.45 dsl if (ch == var_start)
320 1.45 dsl depth++;
321 1.45 dsl else if (ch == var_end && --depth == 0)
322 1.45 dsl return len;
323 1.45 dsl }
324 1.45 dsl
325 1.45 dsl /* Variable end not found, escape the $ */
326 1.45 dsl return 0;
327 1.45 dsl }
328 1.45 dsl
329 1.42 dsl static void
330 1.101 rillig for_substitute(Buffer *cmds, const char *item, char ech)
331 1.42 dsl {
332 1.100 rillig ForEscapes escapes = GetEscapes(item);
333 1.61 rillig char ch;
334 1.61 rillig
335 1.42 dsl /* If there were no escapes, or the only escape is the other variable
336 1.42 dsl * terminator, then just substitute the full string */
337 1.93 rillig if (!(escapes & (ech == ')' ? ~(unsigned)FOR_SUB_ESCAPE_BRACE
338 1.93 rillig : ~(unsigned)FOR_SUB_ESCAPE_PAREN))) {
339 1.59 rillig Buf_AddStr(cmds, item);
340 1.42 dsl return;
341 1.42 dsl }
342 1.42 dsl
343 1.74 rillig /* Escape ':', '$', '\\' and 'ech' - these will be removed later by
344 1.74 rillig * :U processing, see ApplyModifier_Defined. */
345 1.95 rillig while ((ch = *item++) != '\0') {
346 1.45 dsl if (ch == '$') {
347 1.59 rillig size_t len = for_var_len(item);
348 1.45 dsl if (len != 0) {
349 1.62 rillig Buf_AddBytes(cmds, item - 1, len + 1);
350 1.45 dsl item += len;
351 1.45 dsl continue;
352 1.45 dsl }
353 1.45 dsl Buf_AddByte(cmds, '\\');
354 1.45 dsl } else if (ch == ':' || ch == '\\' || ch == ech)
355 1.42 dsl Buf_AddByte(cmds, '\\');
356 1.42 dsl Buf_AddByte(cmds, ch);
357 1.42 dsl }
358 1.42 dsl }
359 1.42 dsl
360 1.109 rillig /* While expanding the body of a .for loop, replace expressions like
361 1.109 rillig * ${i}, ${i:...}, $(i) or $(i:...) with their ${:U...} expansion. */
362 1.97 rillig static void
363 1.109 rillig SubstVarLong(For *f, const char **inout_cp, const char **inout_cmd_cp, char ech)
364 1.97 rillig {
365 1.97 rillig size_t i;
366 1.97 rillig const char *cp = *inout_cp;
367 1.97 rillig const char *cmd_cp = *inout_cmd_cp;
368 1.97 rillig
369 1.109 rillig for (i = 0; i < f->vars.len; i++) {
370 1.109 rillig ForVar *forVar = Vector_Get(&f->vars, i);
371 1.97 rillig char *var = forVar->name;
372 1.97 rillig size_t vlen = forVar->len;
373 1.97 rillig
374 1.97 rillig /* XXX: undefined behavior for cp if vlen is longer than cp? */
375 1.97 rillig if (memcmp(cp, var, vlen) != 0)
376 1.97 rillig continue;
377 1.97 rillig /* XXX: why test for backslash here? */
378 1.97 rillig if (cp[vlen] != ':' && cp[vlen] != ech && cp[vlen] != '\\')
379 1.97 rillig continue;
380 1.97 rillig
381 1.97 rillig /* Found a variable match. Replace with :U<value> */
382 1.109 rillig Buf_AddBytesBetween(&f->curBody, cmd_cp, cp);
383 1.109 rillig Buf_AddStr(&f->curBody, ":U");
384 1.97 rillig cp += vlen;
385 1.97 rillig cmd_cp = cp;
386 1.109 rillig for_substitute(&f->curBody, f->items.words[f->sub_next + i], ech);
387 1.97 rillig break;
388 1.97 rillig }
389 1.97 rillig
390 1.97 rillig *inout_cp = cp;
391 1.97 rillig *inout_cmd_cp = cmd_cp;
392 1.97 rillig }
393 1.97 rillig
394 1.109 rillig /* While expanding the body of a .for loop, replace single-character
395 1.109 rillig * variable expressions like $i with their ${:U...} expansion. */
396 1.98 rillig static void
397 1.109 rillig SubstVarShort(For *f, char const ch,
398 1.103 rillig const char **inout_cp, const char **input_cmd_cp)
399 1.98 rillig {
400 1.98 rillig const char *cp = *inout_cp;
401 1.98 rillig const char *cmd_cp = *input_cmd_cp;
402 1.98 rillig size_t i;
403 1.98 rillig
404 1.98 rillig /* Probably a single character name, ignore $$ and stupid ones. {*/
405 1.109 rillig if (!f->short_var || strchr("}):$", ch) != NULL) {
406 1.98 rillig cp++;
407 1.98 rillig *inout_cp = cp;
408 1.98 rillig return;
409 1.98 rillig }
410 1.98 rillig
411 1.109 rillig for (i = 0; i < f->vars.len; i++) {
412 1.109 rillig ForVar *var = Vector_Get(&f->vars, i);
413 1.109 rillig char *varname = var->name;
414 1.109 rillig if (varname[0] != ch || varname[1] != '\0')
415 1.98 rillig continue;
416 1.98 rillig
417 1.98 rillig /* Found a variable match. Replace with ${:U<value>} */
418 1.109 rillig Buf_AddBytesBetween(&f->curBody, cmd_cp, cp);
419 1.109 rillig Buf_AddStr(&f->curBody, "{:U");
420 1.98 rillig cmd_cp = ++cp;
421 1.109 rillig for_substitute(&f->curBody, f->items.words[f->sub_next + i], '}');
422 1.109 rillig Buf_AddByte(&f->curBody, '}');
423 1.98 rillig break;
424 1.98 rillig }
425 1.98 rillig
426 1.98 rillig *inout_cp = cp;
427 1.98 rillig *input_cmd_cp = cmd_cp;
428 1.98 rillig }
429 1.98 rillig
430 1.95 rillig /*
431 1.95 rillig * Scan the for loop body and replace references to the loop variables
432 1.95 rillig * with variable references that expand to the required text.
433 1.95 rillig *
434 1.95 rillig * Using variable expansions ensures that the .for loop can't generate
435 1.95 rillig * syntax, and that the later parsing will still see a variable.
436 1.95 rillig * We assume that the null variable will never be defined.
437 1.95 rillig *
438 1.95 rillig * The detection of substitutions of the loop control variable is naive.
439 1.95 rillig * Many of the modifiers use \ to escape $ (not $) so it is possible
440 1.95 rillig * to contrive a makefile where an unwanted substitution happens.
441 1.95 rillig */
442 1.43 dsl static char *
443 1.109 rillig ForIterate(void *v_arg, size_t *out_len)
444 1.1 cgd {
445 1.109 rillig For *f = v_arg;
446 1.77 rillig const char *cp;
447 1.77 rillig const char *cmd_cp;
448 1.77 rillig const char *body_end;
449 1.76 rillig char *cmds_str;
450 1.61 rillig size_t cmd_len;
451 1.7 christos
452 1.109 rillig if (f->sub_next + f->vars.len > f->items.len) {
453 1.43 dsl /* No more iterations */
454 1.109 rillig For_Free(f);
455 1.43 dsl return NULL;
456 1.43 dsl }
457 1.1 cgd
458 1.109 rillig Buf_Empty(&f->curBody);
459 1.7 christos
460 1.109 rillig cmd_cp = Buf_GetAll(&f->body, &cmd_len);
461 1.59 rillig body_end = cmd_cp + cmd_len;
462 1.43 dsl for (cp = cmd_cp; (cp = strchr(cp, '$')) != NULL;) {
463 1.95 rillig char ch, ech;
464 1.43 dsl ch = *++cp;
465 1.53 riastrad if ((ch == '(' && (ech = ')', 1)) || (ch == '{' && (ech = '}', 1))) {
466 1.43 dsl cp++;
467 1.43 dsl /* Check variable name against the .for loop variables */
468 1.109 rillig SubstVarLong(f, &cp, &cmd_cp, ech);
469 1.43 dsl continue;
470 1.43 dsl }
471 1.95 rillig if (ch == '\0')
472 1.43 dsl break;
473 1.97 rillig
474 1.109 rillig SubstVarShort(f, ch, &cp, &cmd_cp);
475 1.43 dsl }
476 1.109 rillig Buf_AddBytesBetween(&f->curBody, cmd_cp, body_end);
477 1.43 dsl
478 1.109 rillig *out_len = Buf_Len(&f->curBody);
479 1.109 rillig cmds_str = Buf_GetAll(&f->curBody, NULL);
480 1.89 rillig DEBUG1(FOR, "For: loop body:\n%s", cmds_str);
481 1.39 dsl
482 1.109 rillig f->sub_next += f->vars.len;
483 1.43 dsl
484 1.76 rillig return cmds_str;
485 1.43 dsl }
486 1.7 christos
487 1.60 rillig /* Run the for loop, imitating the actions of an include file. */
488 1.43 dsl void
489 1.43 dsl For_Run(int lineno)
490 1.54 rillig {
491 1.109 rillig For *f = accumFor;
492 1.43 dsl accumFor = NULL;
493 1.1 cgd
494 1.109 rillig if (f->items.len == 0) {
495 1.58 rillig /* Nothing to expand - possibly due to an earlier syntax error. */
496 1.109 rillig For_Free(f);
497 1.58 rillig return;
498 1.43 dsl }
499 1.54 rillig
500 1.109 rillig Parse_SetInput(NULL, lineno, -1, ForIterate, f);
501 1.1 cgd }
502