for.c revision 1.144 1 1.144 rillig /* $NetBSD: for.c,v 1.144 2021/06/25 16:10:07 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.123 rillig * body is scanned for variable expressions, and those that match the variable
49 1.123 rillig * names are replaced with expressions of the form ${:U...} or $(:U...).
50 1.123 rillig * After 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.144 rillig MAKE_RCSID("$NetBSD: for.c,v 1.144 2021/06/25 16:10:07 rillig Exp $");
62 1.42 dsl
63 1.1 cgd
64 1.96 rillig /* One of the variables to the left of the "in" in a .for loop. */
65 1.96 rillig typedef struct ForVar {
66 1.118 rillig char *name;
67 1.123 rillig size_t nameLen;
68 1.96 rillig } ForVar;
69 1.96 rillig
70 1.136 rillig typedef struct ForLoop {
71 1.118 rillig Buffer body; /* Unexpanded body of the loop */
72 1.118 rillig Vector /* of ForVar */ vars; /* Iteration variables */
73 1.118 rillig Words items; /* Substitution items */
74 1.118 rillig Buffer curBody; /* Expanded body of the current iteration */
75 1.143 rillig /* Is any of the names 1 character long? If so, when the variable
76 1.143 rillig * values are substituted, the parser must handle $V expressions as
77 1.143 rillig * well, not only ${V} and $(V). */
78 1.142 rillig bool short_var;
79 1.118 rillig unsigned int sub_next; /* Where to continue iterating */
80 1.136 rillig } ForLoop;
81 1.1 cgd
82 1.137 rillig
83 1.143 rillig static ForLoop *accumFor; /* Loop being accumulated */
84 1.137 rillig static int forLevel = 0; /* Nesting level */
85 1.1 cgd
86 1.137 rillig
87 1.137 rillig static ForLoop *
88 1.137 rillig ForLoop_New(void)
89 1.96 rillig {
90 1.137 rillig ForLoop *f = bmake_malloc(sizeof *f);
91 1.137 rillig
92 1.137 rillig Buf_Init(&f->body);
93 1.137 rillig Vector_Init(&f->vars, sizeof(ForVar));
94 1.137 rillig f->items.words = NULL;
95 1.137 rillig f->items.freeIt = NULL;
96 1.137 rillig Buf_Init(&f->curBody);
97 1.142 rillig f->short_var = false;
98 1.137 rillig f->sub_next = 0;
99 1.137 rillig
100 1.137 rillig return f;
101 1.96 rillig }
102 1.96 rillig
103 1.96 rillig static void
104 1.136 rillig ForLoop_Free(ForLoop *f)
105 1.96 rillig {
106 1.139 rillig Buf_Done(&f->body);
107 1.96 rillig
108 1.118 rillig while (f->vars.len > 0) {
109 1.118 rillig ForVar *var = Vector_Pop(&f->vars);
110 1.118 rillig free(var->name);
111 1.118 rillig }
112 1.118 rillig Vector_Done(&f->vars);
113 1.96 rillig
114 1.118 rillig Words_Free(f->items);
115 1.139 rillig Buf_Done(&f->curBody);
116 1.96 rillig
117 1.118 rillig free(f);
118 1.43 dsl }
119 1.43 dsl
120 1.137 rillig static void
121 1.137 rillig ForLoop_AddVar(ForLoop *f, const char *name, size_t len)
122 1.137 rillig {
123 1.137 rillig ForVar *var = Vector_Push(&f->vars);
124 1.137 rillig var->name = bmake_strldup(name, len);
125 1.137 rillig var->nameLen = len;
126 1.137 rillig }
127 1.137 rillig
128 1.142 rillig static bool
129 1.138 rillig ForLoop_ParseVarnames(ForLoop *f, const char **pp)
130 1.138 rillig {
131 1.138 rillig const char *p = *pp;
132 1.138 rillig
133 1.138 rillig for (;;) {
134 1.138 rillig size_t len;
135 1.138 rillig
136 1.138 rillig cpp_skip_whitespace(&p);
137 1.138 rillig if (*p == '\0') {
138 1.138 rillig Parse_Error(PARSE_FATAL, "missing `in' in for");
139 1.142 rillig return false;
140 1.138 rillig }
141 1.138 rillig
142 1.138 rillig /*
143 1.138 rillig * XXX: This allows arbitrary variable names;
144 1.138 rillig * see directive-for.mk.
145 1.138 rillig */
146 1.138 rillig for (len = 1; p[len] != '\0' && !ch_isspace(p[len]); len++)
147 1.138 rillig continue;
148 1.138 rillig
149 1.138 rillig if (len == 2 && p[0] == 'i' && p[1] == 'n') {
150 1.138 rillig p += 2;
151 1.138 rillig break;
152 1.138 rillig }
153 1.138 rillig if (len == 1)
154 1.142 rillig f->short_var = true;
155 1.138 rillig
156 1.138 rillig ForLoop_AddVar(f, p, len);
157 1.138 rillig p += len;
158 1.138 rillig }
159 1.138 rillig
160 1.138 rillig if (f->vars.len == 0) {
161 1.138 rillig Parse_Error(PARSE_FATAL, "no iteration variables in for");
162 1.142 rillig return false;
163 1.138 rillig }
164 1.138 rillig
165 1.138 rillig *pp = p;
166 1.142 rillig return true;
167 1.138 rillig }
168 1.138 rillig
169 1.142 rillig static bool
170 1.138 rillig ForLoop_ParseItems(ForLoop *f, const char *p)
171 1.138 rillig {
172 1.138 rillig char *items;
173 1.138 rillig
174 1.138 rillig cpp_skip_whitespace(&p);
175 1.138 rillig
176 1.141 rillig if (Var_Subst(p, SCOPE_GLOBAL, VARE_WANTRES, &items) != VPR_OK) {
177 1.138 rillig Parse_Error(PARSE_FATAL, "Error in .for loop items");
178 1.142 rillig return false;
179 1.138 rillig }
180 1.138 rillig
181 1.142 rillig f->items = Str_Words(items, false);
182 1.138 rillig free(items);
183 1.138 rillig
184 1.138 rillig if (f->items.len == 1 && f->items.words[0][0] == '\0')
185 1.138 rillig f->items.len = 0; /* .for var in ${:U} */
186 1.138 rillig
187 1.138 rillig if (f->items.len != 0 && f->items.len % f->vars.len != 0) {
188 1.138 rillig Parse_Error(PARSE_FATAL,
189 1.138 rillig "Wrong number of words (%u) in .for "
190 1.138 rillig "substitution list with %u variables",
191 1.138 rillig (unsigned)f->items.len, (unsigned)f->vars.len);
192 1.142 rillig return false;
193 1.138 rillig }
194 1.138 rillig
195 1.142 rillig return true;
196 1.138 rillig }
197 1.138 rillig
198 1.142 rillig static bool
199 1.106 rillig IsFor(const char *p)
200 1.106 rillig {
201 1.118 rillig return p[0] == 'f' && p[1] == 'o' && p[2] == 'r' && ch_isspace(p[3]);
202 1.106 rillig }
203 1.106 rillig
204 1.142 rillig static bool
205 1.106 rillig IsEndfor(const char *p)
206 1.106 rillig {
207 1.118 rillig return p[0] == 'e' && strncmp(p, "endfor", 6) == 0 &&
208 1.118 rillig (p[6] == '\0' || ch_isspace(p[6]));
209 1.106 rillig }
210 1.106 rillig
211 1.122 rillig /*
212 1.122 rillig * Evaluate the for loop in the passed line. The line looks like this:
213 1.70 rillig * .for <varname...> in <value...>
214 1.1 cgd *
215 1.13 wiz * Input:
216 1.13 wiz * line Line to parse
217 1.13 wiz *
218 1.1 cgd * Results:
219 1.35 dsl * 0: Not a .for statement, parse the line
220 1.35 dsl * 1: We found a for loop
221 1.35 dsl * -1: A .for statement with a bad syntax error, discard.
222 1.1 cgd */
223 1.1 cgd int
224 1.73 rillig For_Eval(const char *line)
225 1.1 cgd {
226 1.136 rillig ForLoop *f;
227 1.118 rillig const char *p;
228 1.33 dsl
229 1.118 rillig p = line + 1; /* skip the '.' */
230 1.118 rillig cpp_skip_whitespace(&p);
231 1.43 dsl
232 1.118 rillig if (!IsFor(p)) {
233 1.118 rillig if (IsEndfor(p)) {
234 1.118 rillig Parse_Error(PARSE_FATAL, "for-less endfor");
235 1.118 rillig return -1;
236 1.118 rillig }
237 1.118 rillig return 0;
238 1.32 dsl }
239 1.118 rillig p += 3;
240 1.118 rillig
241 1.137 rillig f = ForLoop_New();
242 1.118 rillig
243 1.138 rillig if (!ForLoop_ParseVarnames(f, &p)) {
244 1.136 rillig ForLoop_Free(f);
245 1.118 rillig return -1;
246 1.118 rillig }
247 1.72 rillig
248 1.138 rillig if (!ForLoop_ParseItems(f, p)) {
249 1.138 rillig /* Continue parsing the .for loop, but don't iterate. */
250 1.138 rillig f->items.len = 0;
251 1.118 rillig }
252 1.118 rillig
253 1.118 rillig accumFor = f;
254 1.118 rillig forLevel = 1;
255 1.118 rillig return 1;
256 1.32 dsl }
257 1.7 christos
258 1.35 dsl /*
259 1.136 rillig * Add another line to the .for loop that is being built up.
260 1.142 rillig * Returns false when the matching .endfor is reached.
261 1.35 dsl */
262 1.142 rillig bool
263 1.73 rillig For_Accum(const char *line)
264 1.32 dsl {
265 1.140 rillig const char *p = line;
266 1.26 dsl
267 1.140 rillig if (*p == '.') {
268 1.140 rillig p++;
269 1.140 rillig cpp_skip_whitespace(&p);
270 1.118 rillig
271 1.140 rillig if (IsEndfor(p)) {
272 1.118 rillig DEBUG1(FOR, "For: end for %d\n", forLevel);
273 1.118 rillig if (--forLevel <= 0)
274 1.142 rillig return false;
275 1.140 rillig } else if (IsFor(p)) {
276 1.118 rillig forLevel++;
277 1.118 rillig DEBUG1(FOR, "For: new loop %d\n", forLevel);
278 1.118 rillig }
279 1.118 rillig }
280 1.118 rillig
281 1.118 rillig Buf_AddStr(&accumFor->body, line);
282 1.118 rillig Buf_AddByte(&accumFor->body, '\n');
283 1.142 rillig return true;
284 1.1 cgd }
285 1.1 cgd
286 1.42 dsl
287 1.59 rillig static size_t
288 1.45 dsl for_var_len(const char *var)
289 1.45 dsl {
290 1.118 rillig char ch, var_start, var_end;
291 1.118 rillig int depth;
292 1.118 rillig size_t len;
293 1.45 dsl
294 1.118 rillig var_start = *var;
295 1.118 rillig if (var_start == '\0')
296 1.118 rillig /* just escape the $ */
297 1.118 rillig return 0;
298 1.118 rillig
299 1.118 rillig if (var_start == '(')
300 1.118 rillig var_end = ')';
301 1.118 rillig else if (var_start == '{')
302 1.118 rillig var_end = '}';
303 1.118 rillig else
304 1.118 rillig return 1; /* Single char variable */
305 1.118 rillig
306 1.118 rillig depth = 1;
307 1.118 rillig for (len = 1; (ch = var[len++]) != '\0';) {
308 1.118 rillig if (ch == var_start)
309 1.118 rillig depth++;
310 1.118 rillig else if (ch == var_end && --depth == 0)
311 1.118 rillig return len;
312 1.118 rillig }
313 1.45 dsl
314 1.118 rillig /* Variable end not found, escape the $ */
315 1.118 rillig return 0;
316 1.45 dsl }
317 1.45 dsl
318 1.122 rillig /*
319 1.122 rillig * The .for loop substitutes the items as ${:U<value>...}, which means
320 1.122 rillig * that characters that break this syntax must be backslash-escaped.
321 1.122 rillig */
322 1.142 rillig static bool
323 1.140 rillig NeedsEscapes(const char *value, char endc)
324 1.115 rillig {
325 1.118 rillig const char *p;
326 1.115 rillig
327 1.140 rillig for (p = value; *p != '\0'; p++) {
328 1.144 rillig if (*p == ':' || *p == '$' || *p == '\\' || *p == endc ||
329 1.144 rillig *p == '\n')
330 1.142 rillig return true;
331 1.118 rillig }
332 1.142 rillig return false;
333 1.115 rillig }
334 1.115 rillig
335 1.122 rillig /*
336 1.122 rillig * While expanding the body of a .for loop, write the item in the ${:U...}
337 1.115 rillig * expression, escaping characters as needed.
338 1.115 rillig *
339 1.122 rillig * The result is later unescaped by ApplyModifier_Defined.
340 1.122 rillig */
341 1.42 dsl static void
342 1.127 rillig Buf_AddEscaped(Buffer *cmds, const char *item, char endc)
343 1.42 dsl {
344 1.118 rillig char ch;
345 1.118 rillig
346 1.127 rillig if (!NeedsEscapes(item, endc)) {
347 1.118 rillig Buf_AddStr(cmds, item);
348 1.118 rillig return;
349 1.118 rillig }
350 1.61 rillig
351 1.127 rillig /* Escape ':', '$', '\\' and 'endc' - these will be removed later by
352 1.118 rillig * :U processing, see ApplyModifier_Defined. */
353 1.118 rillig while ((ch = *item++) != '\0') {
354 1.118 rillig if (ch == '$') {
355 1.118 rillig size_t len = for_var_len(item);
356 1.118 rillig if (len != 0) {
357 1.118 rillig Buf_AddBytes(cmds, item - 1, len + 1);
358 1.118 rillig item += len;
359 1.118 rillig continue;
360 1.118 rillig }
361 1.118 rillig Buf_AddByte(cmds, '\\');
362 1.127 rillig } else if (ch == ':' || ch == '\\' || ch == endc)
363 1.118 rillig Buf_AddByte(cmds, '\\');
364 1.144 rillig else if (ch == '\n') {
365 1.144 rillig Parse_Error(PARSE_FATAL, "newline in .for value");
366 1.144 rillig ch = ' '; /* prevent newline injection */
367 1.144 rillig }
368 1.118 rillig Buf_AddByte(cmds, ch);
369 1.118 rillig }
370 1.42 dsl }
371 1.42 dsl
372 1.122 rillig /*
373 1.131 rillig * While expanding the body of a .for loop, replace the variable name of an
374 1.123 rillig * expression like ${i} or ${i:...} or $(i) or $(i:...) with ":Uvalue".
375 1.122 rillig */
376 1.97 rillig static void
377 1.136 rillig ForLoop_SubstVarLong(ForLoop *f, const char **pp, const char *bodyEnd,
378 1.136 rillig char endc, const char **inout_mark)
379 1.97 rillig {
380 1.118 rillig size_t i;
381 1.118 rillig const char *p = *pp;
382 1.97 rillig
383 1.118 rillig for (i = 0; i < f->vars.len; i++) {
384 1.143 rillig const ForVar *forVar = Vector_Get(&f->vars, i);
385 1.143 rillig const char *varname = forVar->name;
386 1.123 rillig size_t varnameLen = forVar->nameLen;
387 1.118 rillig
388 1.132 rillig if (varnameLen >= (size_t)(bodyEnd - p))
389 1.132 rillig continue;
390 1.123 rillig if (memcmp(p, varname, varnameLen) != 0)
391 1.118 rillig continue;
392 1.118 rillig /* XXX: why test for backslash here? */
393 1.127 rillig if (p[varnameLen] != ':' && p[varnameLen] != endc &&
394 1.123 rillig p[varnameLen] != '\\')
395 1.118 rillig continue;
396 1.118 rillig
397 1.131 rillig /*
398 1.131 rillig * Found a variable match. Skip over the variable name and
399 1.131 rillig * instead add ':U<value>' to the current body.
400 1.131 rillig */
401 1.118 rillig Buf_AddBytesBetween(&f->curBody, *inout_mark, p);
402 1.118 rillig Buf_AddStr(&f->curBody, ":U");
403 1.118 rillig Buf_AddEscaped(&f->curBody,
404 1.127 rillig f->items.words[f->sub_next + i], endc);
405 1.118 rillig
406 1.123 rillig p += varnameLen;
407 1.118 rillig *inout_mark = p;
408 1.131 rillig *pp = p;
409 1.131 rillig return;
410 1.118 rillig }
411 1.97 rillig }
412 1.97 rillig
413 1.122 rillig /*
414 1.122 rillig * While expanding the body of a .for loop, replace single-character
415 1.122 rillig * variable expressions like $i with their ${:U...} expansion.
416 1.122 rillig */
417 1.98 rillig static void
418 1.136 rillig ForLoop_SubstVarShort(ForLoop *f, const char *p, const char **inout_mark)
419 1.98 rillig {
420 1.123 rillig const char ch = *p;
421 1.143 rillig const ForVar *vars;
422 1.118 rillig size_t i;
423 1.118 rillig
424 1.130 rillig /* Skip $$ and stupid ones. */
425 1.130 rillig if (!f->short_var || strchr("}):$", ch) != NULL)
426 1.118 rillig return;
427 1.98 rillig
428 1.130 rillig vars = Vector_Get(&f->vars, 0);
429 1.118 rillig for (i = 0; i < f->vars.len; i++) {
430 1.130 rillig const char *varname = vars[i].name;
431 1.130 rillig if (varname[0] == ch && varname[1] == '\0')
432 1.130 rillig goto found;
433 1.130 rillig }
434 1.130 rillig return;
435 1.130 rillig
436 1.130 rillig found:
437 1.130 rillig /* Replace $<ch> with ${:U<value>} */
438 1.130 rillig Buf_AddBytesBetween(&f->curBody, *inout_mark, p), *inout_mark = p + 1;
439 1.130 rillig Buf_AddStr(&f->curBody, "{:U");
440 1.130 rillig Buf_AddEscaped(&f->curBody, f->items.words[f->sub_next + i], '}');
441 1.130 rillig Buf_AddByte(&f->curBody, '}');
442 1.98 rillig }
443 1.98 rillig
444 1.95 rillig /*
445 1.128 rillig * Compute the body for the current iteration by copying the unexpanded body,
446 1.128 rillig * replacing the expressions for the iteration variables on the way.
447 1.129 rillig *
448 1.129 rillig * Using variable expressions ensures that the .for loop can't generate
449 1.129 rillig * syntax, and that the later parsing will still see a variable.
450 1.129 rillig * This code assumes that the variable with the empty name will never be
451 1.129 rillig * defined, see unit-tests/varname-empty.mk for more details.
452 1.129 rillig *
453 1.140 rillig * The detection of substitutions of the loop control variables is naive.
454 1.140 rillig * Many of the modifiers use '\' to escape '$' (not '$'), so it is possible
455 1.129 rillig * to contrive a makefile where an unwanted substitution happens.
456 1.128 rillig */
457 1.128 rillig static void
458 1.136 rillig ForLoop_SubstBody(ForLoop *f)
459 1.128 rillig {
460 1.132 rillig const char *p, *bodyEnd;
461 1.128 rillig const char *mark; /* where the last replacement left off */
462 1.128 rillig
463 1.128 rillig Buf_Empty(&f->curBody);
464 1.128 rillig
465 1.128 rillig mark = f->body.data;
466 1.132 rillig bodyEnd = f->body.data + f->body.len;
467 1.128 rillig for (p = mark; (p = strchr(p, '$')) != NULL;) {
468 1.128 rillig if (p[1] == '{' || p[1] == '(') {
469 1.128 rillig p += 2;
470 1.136 rillig ForLoop_SubstVarLong(f, &p, bodyEnd,
471 1.136 rillig p[-1] == '{' ? '}' : ')', &mark);
472 1.128 rillig } else if (p[1] != '\0') {
473 1.136 rillig ForLoop_SubstVarShort(f, p + 1, &mark);
474 1.130 rillig p += 2;
475 1.128 rillig } else
476 1.128 rillig break;
477 1.128 rillig }
478 1.128 rillig
479 1.132 rillig Buf_AddBytesBetween(&f->curBody, mark, bodyEnd);
480 1.128 rillig }
481 1.128 rillig
482 1.128 rillig /*
483 1.129 rillig * Compute the body for the current iteration by copying the unexpanded body,
484 1.129 rillig * replacing the expressions for the iteration variables on the way.
485 1.95 rillig */
486 1.43 dsl static char *
487 1.119 rillig ForReadMore(void *v_arg, size_t *out_len)
488 1.1 cgd {
489 1.136 rillig ForLoop *f = v_arg;
490 1.118 rillig
491 1.124 rillig if (f->sub_next == f->items.len) {
492 1.118 rillig /* No more iterations */
493 1.136 rillig ForLoop_Free(f);
494 1.118 rillig return NULL;
495 1.118 rillig }
496 1.118 rillig
497 1.136 rillig ForLoop_SubstBody(f);
498 1.128 rillig DEBUG1(FOR, "For: loop body:\n%s", f->curBody.data);
499 1.133 rillig f->sub_next += (unsigned int)f->vars.len;
500 1.118 rillig
501 1.128 rillig *out_len = f->curBody.len;
502 1.128 rillig return f->curBody.data;
503 1.43 dsl }
504 1.7 christos
505 1.120 rillig /* Run the .for loop, imitating the actions of an include file. */
506 1.43 dsl void
507 1.43 dsl For_Run(int lineno)
508 1.54 rillig {
509 1.136 rillig ForLoop *f = accumFor;
510 1.118 rillig accumFor = NULL;
511 1.1 cgd
512 1.118 rillig if (f->items.len == 0) {
513 1.118 rillig /*
514 1.118 rillig * Nothing to expand - possibly due to an earlier syntax
515 1.118 rillig * error.
516 1.118 rillig */
517 1.136 rillig ForLoop_Free(f);
518 1.118 rillig return;
519 1.118 rillig }
520 1.54 rillig
521 1.119 rillig Parse_SetInput(NULL, lineno, -1, ForReadMore, f);
522 1.1 cgd }
523