Re: [Autogen-users] A question about for loops
Brought to you by:
bkorb
|
From: Vivien K. <vi...@pl...> - 2018-08-31 17:35:14
|
Bruce Korb writes:
> Clearly, you were not using the version I released two days ago. ;)
Exactly. I discovered the package a few days ago from @fs...@st...'s
toot, but I had still an older version.
OK so compiling the new version... I get a -Werror=format-overflow in
getdefs.c:451:29, where sprintf writes up to 255 bytes in a 253-byte
region. If you add 4 to MAXNAMELEN for def_bf in line 377 (for the
storage of the indentation, the ' and the final NUL), gcc does not
complain anymore. Anyway, the tests pass.
>> Now my question about for loops.
>
> Take a peek at line 186 in autoopts/tpl/bits.tpl and look for the loop:
> FOR bit (for-from 0) (for-by 1) =][=
>
> "bit" is a sparse structured value. It contains a value for "b-name"
> for every valid entry. By checking for existence, it is checking to
> see if there is the current index for "bit" is valid. But you don't care
> about validity of "i", so:
>
> [=FOR i (for-from 0) (for-by 1) (for-to (get "size")) \=]
> [=foo=][[=(for-index)=]] = [=(for-index)=];
> [=ENDFOR=]
>
> and never reference "i" because "i" is not defined.
Are we talking about the same thing? For autogen version 5.18.16, given
example.def:
autogen definitions example;
example = {
foo = "bar";
size = 5;
};
Given example.tpl:
[=AutoGen5 template c =]
[=FOR example=]
/* Now set up the first [=size=] items of [=foo=] */
[=FOR i (for-from 0) (for-by 1) (for-to (get "size")) \=]
[=foo=][[=(for-index)=]] = [=(for-index)=];
[=ENDFOR=]
[=ENDFOR=]
I still get example.c from `/usr/local/bin/autogen example.def`:
/* Now set up the first 5 items of bar */
and that's all. No loops. If I define i = 0 in the .def, then I get
only one line for i = 0.
> NOTE: this will go from 0 thru 5, yielding *six* results.
You're spoiling the fun I intended to have debugging easy things!
Best regards,
Vivien
|