[Autogen-users] A question about for loops
Brought to you by:
bkorb
|
From: Vivien K. <vi...@pl...> - 2018-08-31 10:26:12
|
Hello list,
I'm just starting to include autogen in my application. Everything went
smoothly, except for a few things: _Noreturn.h that I had to copy from
snippets/ to libopts/ after autoreconf, and changing the generated
include guard for the options which happens to match that of (and thus
shadowing) autoopts/options.h (AUTOOPTS_OPTIONS_H_GUARD). Did I miss
something?
Now my question about for loops.
Suppose I'd like to produce (I don't care about empty lines):
/* Now set up the first 5 items of bar */
bar[0] = 0;
bar[1] = 1;
bar[2] = 2;
bar[3] = 3;
bar[4] = 4;
when my definitions are:
autogen definitions example;
example = {
foo = "bar";
size = 5;
};
How should I proceed? I have tried:
[+ AutoGen5 template c +]
[+ for example +]
/* Now set up the first [+size+] items of [+foo+] */
[+ for i (for-from 0) (for-to (get "size")) +]
[+ foo +][[+i+]] = [+i+];
[+ endfor +]
[+ endfor +]
but the inner "i" loop is not processed.
The best thing I have come up so far is generate a shell script that
spits out the code:
[+ AutoGen5 template sh +]
[+ for example +]
echo "/* Now set up the first [+size+] items of [+foo+] */"
for i in $(seq 0 $(expr [+size+] - 1))
do
echo "[+foo+][$i] = $i;"
done
[+ endfor +]
But I'm not very proud of it. Is there a better way?
Best regards
Vivien
|