for.c revision 1.184 1 1.184 rillig /* $NetBSD: for.c,v 1.184 2025/04/11 18:08:17 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.135 rillig /*
33 1.80 rillig * Handling of .for/.endfor loops in a makefile.
34 1.80 rillig *
35 1.123 rillig * For loops have the form:
36 1.80 rillig *
37 1.123 rillig * .for <varname...> in <value...>
38 1.123 rillig * # the body
39 1.123 rillig * .endfor
40 1.123 rillig *
41 1.123 rillig * When a .for line is parsed, the following lines are copied to the body of
42 1.123 rillig * the .for loop, until the corresponding .endfor line is reached. In this
43 1.123 rillig * phase, the body is not yet evaluated. This also applies to any nested
44 1.123 rillig * .for loops.
45 1.123 rillig *
46 1.123 rillig * After reaching the .endfor, the values from the .for line are grouped
47 1.123 rillig * according to the number of variables. For each such group, the unexpanded
48 1.177 rillig * body is scanned for expressions, and those that match the
49 1.149 rillig * variable names are replaced with expressions of the form ${:U...}. After
50 1.149 rillig * that, the body is treated like a file from an .include directive.
51 1.1 cgd *
52 1.1 cgd * Interface:
53 1.88 rillig * For_Eval Evaluate the loop in the passed line.
54 1.88 rillig *
55 1.1 cgd * For_Run Run accumulated loop
56 1.1 cgd */
57 1.1 cgd
58 1.112 rillig #include "make.h"
59 1.1 cgd
60 1.83 rillig /* "@(#)for.c 8.1 (Berkeley) 6/6/93" */
61 1.184 rillig MAKE_RCSID("$NetBSD: for.c,v 1.184 2025/04/11 18:08:17 rillig Exp $");
62 1.42 dsl
63 1.1 cgd
64 1.136 rillig typedef struct ForLoop {
65 1.155 rillig Vector /* of 'char *' */ vars; /* Iteration variables */
66 1.148 rillig SubstringWords items; /* Substitution items */
67 1.157 rillig Buffer body; /* Unexpanded body of the loop */
68 1.149 rillig unsigned int nextItem; /* Where to continue iterating */
69 1.136 rillig } ForLoop;
70 1.1 cgd
71 1.137 rillig
72 1.143 rillig static ForLoop *accumFor; /* Loop being accumulated */
73 1.1 cgd
74 1.137 rillig
75 1.172 rillig /* See LK_FOR_BODY. */
76 1.172 rillig static void
77 1.172 rillig skip_whitespace_or_line_continuation(const char **pp)
78 1.172 rillig {
79 1.172 rillig const char *p = *pp;
80 1.172 rillig for (;;) {
81 1.172 rillig if (ch_isspace(*p))
82 1.172 rillig p++;
83 1.172 rillig else if (p[0] == '\\' && p[1] == '\n')
84 1.172 rillig p += 2;
85 1.172 rillig else
86 1.172 rillig break;
87 1.172 rillig }
88 1.172 rillig *pp = p;
89 1.172 rillig }
90 1.172 rillig
91 1.137 rillig static ForLoop *
92 1.137 rillig ForLoop_New(void)
93 1.96 rillig {
94 1.137 rillig ForLoop *f = bmake_malloc(sizeof *f);
95 1.137 rillig
96 1.155 rillig Vector_Init(&f->vars, sizeof(char *));
97 1.148 rillig SubstringWords_Init(&f->items);
98 1.157 rillig Buf_Init(&f->body);
99 1.149 rillig f->nextItem = 0;
100 1.137 rillig
101 1.137 rillig return f;
102 1.96 rillig }
103 1.96 rillig
104 1.163 rillig void
105 1.136 rillig ForLoop_Free(ForLoop *f)
106 1.96 rillig {
107 1.155 rillig while (f->vars.len > 0)
108 1.155 rillig free(*(char **)Vector_Pop(&f->vars));
109 1.118 rillig Vector_Done(&f->vars);
110 1.96 rillig
111 1.148 rillig SubstringWords_Free(f->items);
112 1.157 rillig Buf_Done(&f->body);
113 1.96 rillig
114 1.118 rillig free(f);
115 1.43 dsl }
116 1.43 dsl
117 1.161 rillig char *
118 1.175 rillig ForLoop_Details(const ForLoop *f)
119 1.161 rillig {
120 1.163 rillig size_t i, n;
121 1.163 rillig const char **vars;
122 1.163 rillig const Substring *items;
123 1.161 rillig Buffer buf;
124 1.161 rillig
125 1.163 rillig n = f->vars.len;
126 1.163 rillig vars = f->vars.items;
127 1.163 rillig assert(f->nextItem >= n);
128 1.163 rillig items = f->items.words + f->nextItem - n;
129 1.163 rillig
130 1.161 rillig Buf_Init(&buf);
131 1.161 rillig for (i = 0; i < n; i++) {
132 1.161 rillig if (i > 0)
133 1.161 rillig Buf_AddStr(&buf, ", ");
134 1.161 rillig Buf_AddStr(&buf, vars[i]);
135 1.161 rillig Buf_AddStr(&buf, " = ");
136 1.175 rillig Buf_AddRange(&buf, items[i].start, items[i].end);
137 1.161 rillig }
138 1.161 rillig return Buf_DoneData(&buf);
139 1.161 rillig }
140 1.161 rillig
141 1.142 rillig static bool
142 1.173 rillig IsValidInVarname(char c)
143 1.173 rillig {
144 1.173 rillig return c != '$' && c != ':' && c != '\\' &&
145 1.173 rillig c != '(' && c != '{' && c != ')' && c != '}';
146 1.173 rillig }
147 1.173 rillig
148 1.174 rillig static void
149 1.138 rillig ForLoop_ParseVarnames(ForLoop *f, const char **pp)
150 1.138 rillig {
151 1.184 rillig const char *p = *pp, *start;
152 1.138 rillig
153 1.138 rillig for (;;) {
154 1.138 rillig cpp_skip_whitespace(&p);
155 1.138 rillig if (*p == '\0') {
156 1.138 rillig Parse_Error(PARSE_FATAL, "missing `in' in for");
157 1.184 rillig goto cleanup;
158 1.138 rillig }
159 1.138 rillig
160 1.184 rillig for (start = p; *p != '\0' && !ch_isspace(*p); p++)
161 1.184 rillig if (!IsValidInVarname(*p))
162 1.184 rillig goto invalid_variable_name;
163 1.138 rillig
164 1.184 rillig if (p - start == 2 && memcmp(start, "in", 2) == 0)
165 1.138 rillig break;
166 1.138 rillig
167 1.184 rillig *(char **)Vector_Push(&f->vars) = bmake_strsedup(start, p);
168 1.138 rillig }
169 1.138 rillig
170 1.138 rillig if (f->vars.len == 0) {
171 1.138 rillig Parse_Error(PARSE_FATAL, "no iteration variables in for");
172 1.174 rillig return;
173 1.138 rillig }
174 1.138 rillig
175 1.138 rillig *pp = p;
176 1.184 rillig return;
177 1.184 rillig
178 1.184 rillig invalid_variable_name:
179 1.184 rillig Parse_Error(PARSE_FATAL,
180 1.184 rillig "invalid character '%c' in .for loop variable name", *p);
181 1.184 rillig cleanup:
182 1.184 rillig while (f->vars.len > 0)
183 1.184 rillig free(*(char **)Vector_Pop(&f->vars));
184 1.138 rillig }
185 1.138 rillig
186 1.142 rillig static bool
187 1.138 rillig ForLoop_ParseItems(ForLoop *f, const char *p)
188 1.138 rillig {
189 1.138 rillig char *items;
190 1.183 rillig int parseErrorsBefore = parseErrors;
191 1.138 rillig
192 1.138 rillig cpp_skip_whitespace(&p);
193 1.138 rillig
194 1.181 rillig items = Var_Subst(p, SCOPE_GLOBAL, VARE_EVAL);
195 1.183 rillig f->items = Substring_Words(
196 1.183 rillig parseErrors == parseErrorsBefore ? items : "", false);
197 1.138 rillig free(items);
198 1.138 rillig
199 1.148 rillig if (f->items.len == 1 && Substring_IsEmpty(f->items.words[0]))
200 1.151 rillig f->items.len = 0; /* .for var in ${:U} */
201 1.138 rillig
202 1.157 rillig if (f->items.len % f->vars.len != 0) {
203 1.138 rillig Parse_Error(PARSE_FATAL,
204 1.138 rillig "Wrong number of words (%u) in .for "
205 1.138 rillig "substitution list with %u variables",
206 1.138 rillig (unsigned)f->items.len, (unsigned)f->vars.len);
207 1.142 rillig return false;
208 1.138 rillig }
209 1.138 rillig
210 1.142 rillig return true;
211 1.138 rillig }
212 1.138 rillig
213 1.142 rillig static bool
214 1.106 rillig IsFor(const char *p)
215 1.106 rillig {
216 1.118 rillig return p[0] == 'f' && p[1] == 'o' && p[2] == 'r' && ch_isspace(p[3]);
217 1.106 rillig }
218 1.106 rillig
219 1.142 rillig static bool
220 1.106 rillig IsEndfor(const char *p)
221 1.106 rillig {
222 1.118 rillig return p[0] == 'e' && strncmp(p, "endfor", 6) == 0 &&
223 1.118 rillig (p[6] == '\0' || ch_isspace(p[6]));
224 1.106 rillig }
225 1.106 rillig
226 1.122 rillig /*
227 1.122 rillig * Evaluate the for loop in the passed line. The line looks like this:
228 1.70 rillig * .for <varname...> in <value...>
229 1.1 cgd *
230 1.1 cgd * Results:
231 1.157 rillig * 0 not a .for directive
232 1.157 rillig * 1 found a .for directive
233 1.157 rillig * -1 erroneous .for directive
234 1.1 cgd */
235 1.1 cgd int
236 1.73 rillig For_Eval(const char *line)
237 1.1 cgd {
238 1.158 rillig const char *p;
239 1.136 rillig ForLoop *f;
240 1.33 dsl
241 1.118 rillig p = line + 1; /* skip the '.' */
242 1.172 rillig skip_whitespace_or_line_continuation(&p);
243 1.43 dsl
244 1.158 rillig if (IsFor(p)) {
245 1.158 rillig p += 3;
246 1.158 rillig
247 1.158 rillig f = ForLoop_New();
248 1.174 rillig ForLoop_ParseVarnames(f, &p);
249 1.174 rillig if (f->vars.len > 0 && !ForLoop_ParseItems(f, p))
250 1.158 rillig f->items.len = 0; /* don't iterate */
251 1.118 rillig
252 1.158 rillig accumFor = f;
253 1.158 rillig return 1;
254 1.158 rillig } else if (IsEndfor(p)) {
255 1.158 rillig Parse_Error(PARSE_FATAL, "for-less endfor");
256 1.118 rillig return -1;
257 1.158 rillig } else
258 1.158 rillig return 0;
259 1.32 dsl }
260 1.7 christos
261 1.35 dsl /*
262 1.136 rillig * Add another line to the .for loop that is being built up.
263 1.142 rillig * Returns false when the matching .endfor is reached.
264 1.35 dsl */
265 1.142 rillig bool
266 1.156 rillig For_Accum(const char *line, int *forLevel)
267 1.32 dsl {
268 1.140 rillig const char *p = line;
269 1.26 dsl
270 1.140 rillig if (*p == '.') {
271 1.140 rillig p++;
272 1.172 rillig skip_whitespace_or_line_continuation(&p);
273 1.118 rillig
274 1.140 rillig if (IsEndfor(p)) {
275 1.156 rillig DEBUG1(FOR, "For: end for %d\n", *forLevel);
276 1.157 rillig if (--*forLevel == 0)
277 1.142 rillig return false;
278 1.140 rillig } else if (IsFor(p)) {
279 1.156 rillig (*forLevel)++;
280 1.156 rillig DEBUG1(FOR, "For: new loop %d\n", *forLevel);
281 1.118 rillig }
282 1.118 rillig }
283 1.118 rillig
284 1.118 rillig Buf_AddStr(&accumFor->body, line);
285 1.118 rillig Buf_AddByte(&accumFor->body, '\n');
286 1.142 rillig return true;
287 1.1 cgd }
288 1.1 cgd
289 1.168 rillig /*
290 1.168 rillig * When the body of a '.for i' loop is prepared for an iteration, each
291 1.168 rillig * occurrence of $i in the body is replaced with ${:U...}, inserting the
292 1.177 rillig * value of the item. If this item contains a '$', it may be the start of an
293 1.177 rillig * expression. This expression is copied verbatim, its length is
294 1.168 rillig * determined here, in a rather naive way, ignoring escape characters and
295 1.168 rillig * funny delimiters in modifiers like ':S}from}to}'.
296 1.168 rillig */
297 1.59 rillig static size_t
298 1.148 rillig ExprLen(const char *s, const char *e)
299 1.45 dsl {
300 1.148 rillig char expr_open, expr_close;
301 1.118 rillig int depth;
302 1.148 rillig const char *p;
303 1.45 dsl
304 1.148 rillig if (s == e)
305 1.148 rillig return 0; /* just escape the '$' */
306 1.118 rillig
307 1.148 rillig expr_open = s[0];
308 1.147 rillig if (expr_open == '(')
309 1.147 rillig expr_close = ')';
310 1.147 rillig else if (expr_open == '{')
311 1.147 rillig expr_close = '}';
312 1.118 rillig else
313 1.118 rillig return 1; /* Single char variable */
314 1.118 rillig
315 1.118 rillig depth = 1;
316 1.148 rillig for (p = s + 1; p != e; p++) {
317 1.148 rillig if (*p == expr_open)
318 1.118 rillig depth++;
319 1.148 rillig else if (*p == expr_close && --depth == 0)
320 1.148 rillig return (size_t)(p + 1 - s);
321 1.118 rillig }
322 1.45 dsl
323 1.147 rillig /* Expression end not found, escape the $ */
324 1.118 rillig return 0;
325 1.45 dsl }
326 1.45 dsl
327 1.122 rillig /*
328 1.175 rillig * While expanding the body of a .for loop, write the item as a ${:U...}
329 1.166 rillig * expression, escaping characters as needed. The result is later unescaped
330 1.166 rillig * by ApplyModifier_Defined.
331 1.122 rillig */
332 1.42 dsl static void
333 1.157 rillig AddEscaped(Buffer *cmds, Substring item, char endc)
334 1.42 dsl {
335 1.148 rillig const char *p;
336 1.118 rillig char ch;
337 1.118 rillig
338 1.166 rillig for (p = item.start; p != item.end;) {
339 1.148 rillig ch = *p;
340 1.118 rillig if (ch == '$') {
341 1.148 rillig size_t len = ExprLen(p + 1, item.end);
342 1.118 rillig if (len != 0) {
343 1.147 rillig /*
344 1.147 rillig * XXX: Should a '\' be added here?
345 1.147 rillig * See directive-for-escape.mk, ExprLen.
346 1.147 rillig */
347 1.148 rillig Buf_AddBytes(cmds, p, 1 + len);
348 1.166 rillig p += 1 + len;
349 1.118 rillig continue;
350 1.118 rillig }
351 1.118 rillig Buf_AddByte(cmds, '\\');
352 1.127 rillig } else if (ch == ':' || ch == '\\' || ch == endc)
353 1.118 rillig Buf_AddByte(cmds, '\\');
354 1.144 rillig else if (ch == '\n') {
355 1.144 rillig Parse_Error(PARSE_FATAL, "newline in .for value");
356 1.144 rillig ch = ' '; /* prevent newline injection */
357 1.144 rillig }
358 1.118 rillig Buf_AddByte(cmds, ch);
359 1.166 rillig p++;
360 1.118 rillig }
361 1.42 dsl }
362 1.42 dsl
363 1.122 rillig /*
364 1.175 rillig * While expanding the body of a .for loop, replace the variable name of an
365 1.123 rillig * expression like ${i} or ${i:...} or $(i) or $(i:...) with ":Uvalue".
366 1.122 rillig */
367 1.97 rillig static void
368 1.164 rillig ForLoop_SubstVarLong(ForLoop *f, unsigned int firstItem, Buffer *body,
369 1.164 rillig const char **pp, char endc, const char **inout_mark)
370 1.97 rillig {
371 1.118 rillig size_t i;
372 1.155 rillig const char *start = *pp;
373 1.175 rillig const char **varnames = Vector_Get(&f->vars, 0);
374 1.97 rillig
375 1.118 rillig for (i = 0; i < f->vars.len; i++) {
376 1.155 rillig const char *p = start;
377 1.118 rillig
378 1.175 rillig if (!cpp_skip_string(&p, varnames[i]))
379 1.118 rillig continue;
380 1.118 rillig /* XXX: why test for backslash here? */
381 1.155 rillig if (*p != ':' && *p != endc && *p != '\\')
382 1.118 rillig continue;
383 1.118 rillig
384 1.131 rillig /*
385 1.131 rillig * Found a variable match. Skip over the variable name and
386 1.131 rillig * instead add ':U<value>' to the current body.
387 1.131 rillig */
388 1.175 rillig Buf_AddRange(body, *inout_mark, start);
389 1.153 rillig Buf_AddStr(body, ":U");
390 1.164 rillig AddEscaped(body, f->items.words[firstItem + i], endc);
391 1.118 rillig
392 1.118 rillig *inout_mark = p;
393 1.131 rillig *pp = p;
394 1.131 rillig return;
395 1.118 rillig }
396 1.97 rillig }
397 1.97 rillig
398 1.122 rillig /*
399 1.175 rillig * While expanding the body of a .for loop, replace single-character
400 1.177 rillig * expressions like $i with their ${:U...} expansion.
401 1.122 rillig */
402 1.98 rillig static void
403 1.164 rillig ForLoop_SubstVarShort(ForLoop *f, unsigned int firstItem, Buffer *body,
404 1.153 rillig const char *p, const char **inout_mark)
405 1.98 rillig {
406 1.178 rillig char ch = *p;
407 1.155 rillig const char **vars;
408 1.118 rillig size_t i;
409 1.118 rillig
410 1.130 rillig /* Skip $$ and stupid ones. */
411 1.146 rillig if (ch == '}' || ch == ')' || ch == ':' || ch == '$')
412 1.118 rillig return;
413 1.98 rillig
414 1.130 rillig vars = Vector_Get(&f->vars, 0);
415 1.118 rillig for (i = 0; i < f->vars.len; i++) {
416 1.155 rillig const char *varname = vars[i];
417 1.130 rillig if (varname[0] == ch && varname[1] == '\0')
418 1.130 rillig goto found;
419 1.130 rillig }
420 1.130 rillig return;
421 1.130 rillig
422 1.130 rillig found:
423 1.175 rillig Buf_AddRange(body, *inout_mark, p);
424 1.147 rillig *inout_mark = p + 1;
425 1.147 rillig
426 1.130 rillig /* Replace $<ch> with ${:U<value>} */
427 1.153 rillig Buf_AddStr(body, "{:U");
428 1.164 rillig AddEscaped(body, f->items.words[firstItem + i], '}');
429 1.153 rillig Buf_AddByte(body, '}');
430 1.98 rillig }
431 1.98 rillig
432 1.95 rillig /*
433 1.128 rillig * Compute the body for the current iteration by copying the unexpanded body,
434 1.128 rillig * replacing the expressions for the iteration variables on the way.
435 1.129 rillig *
436 1.177 rillig * Using expressions ensures that the .for loop can't generate
437 1.175 rillig * syntax, and that the later parsing will still see an expression.
438 1.175 rillig * This code assumes that the variable with the empty name is never defined,
439 1.175 rillig * see unit-tests/varname-empty.mk.
440 1.129 rillig *
441 1.140 rillig * The detection of substitutions of the loop control variables is naive.
442 1.147 rillig * Many of the modifiers use '\$' instead of '$$' to escape '$', so it is
443 1.147 rillig * possible to contrive a makefile where an unwanted substitution happens.
444 1.175 rillig * See unit-tests/directive-for-escape.mk.
445 1.128 rillig */
446 1.128 rillig static void
447 1.164 rillig ForLoop_SubstBody(ForLoop *f, unsigned int firstItem, Buffer *body)
448 1.128 rillig {
449 1.153 rillig const char *p, *end;
450 1.146 rillig const char *mark; /* where the last substitution left off */
451 1.128 rillig
452 1.159 rillig Buf_Clear(body);
453 1.128 rillig
454 1.128 rillig mark = f->body.data;
455 1.153 rillig end = f->body.data + f->body.len;
456 1.128 rillig for (p = mark; (p = strchr(p, '$')) != NULL;) {
457 1.128 rillig if (p[1] == '{' || p[1] == '(') {
458 1.146 rillig char endc = p[1] == '{' ? '}' : ')';
459 1.128 rillig p += 2;
460 1.164 rillig ForLoop_SubstVarLong(f, firstItem, body,
461 1.164 rillig &p, endc, &mark);
462 1.179 rillig } else {
463 1.164 rillig ForLoop_SubstVarShort(f, firstItem, body,
464 1.164 rillig p + 1, &mark);
465 1.130 rillig p += 2;
466 1.179 rillig }
467 1.128 rillig }
468 1.128 rillig
469 1.175 rillig Buf_AddRange(body, mark, end);
470 1.128 rillig }
471 1.128 rillig
472 1.128 rillig /*
473 1.129 rillig * Compute the body for the current iteration by copying the unexpanded body,
474 1.129 rillig * replacing the expressions for the iteration variables on the way.
475 1.95 rillig */
476 1.154 rillig bool
477 1.154 rillig For_NextIteration(ForLoop *f, Buffer *body)
478 1.1 cgd {
479 1.163 rillig if (f->nextItem == f->items.len)
480 1.154 rillig return false;
481 1.118 rillig
482 1.164 rillig f->nextItem += (unsigned int)f->vars.len;
483 1.164 rillig ForLoop_SubstBody(f, f->nextItem - (unsigned int)f->vars.len, body);
484 1.176 rillig if (DEBUG(FOR)) {
485 1.176 rillig char *details = ForLoop_Details(f);
486 1.176 rillig debug_printf("For: loop body with %s:\n%s",
487 1.176 rillig details, body->data);
488 1.176 rillig free(details);
489 1.176 rillig }
490 1.154 rillig return true;
491 1.43 dsl }
492 1.7 christos
493 1.170 rillig /* Break out of the .for loop. */
494 1.170 rillig void
495 1.170 rillig For_Break(ForLoop *f)
496 1.170 rillig {
497 1.170 rillig f->nextItem = (unsigned int)f->items.len;
498 1.170 rillig }
499 1.170 rillig
500 1.120 rillig /* Run the .for loop, imitating the actions of an include file. */
501 1.43 dsl void
502 1.167 rillig For_Run(unsigned headLineno, unsigned bodyReadLines)
503 1.54 rillig {
504 1.154 rillig Buffer buf;
505 1.136 rillig ForLoop *f = accumFor;
506 1.118 rillig accumFor = NULL;
507 1.1 cgd
508 1.154 rillig if (f->items.len > 0) {
509 1.154 rillig Buf_Init(&buf);
510 1.160 rillig Parse_PushInput(NULL, headLineno, bodyReadLines, buf, f);
511 1.154 rillig } else
512 1.136 rillig ForLoop_Free(f);
513 1.1 cgd }
514