Submitted by Bernd Petrovitsch on Mon, 28 May 2001
20:26:11 +0200
Hi all !
I use e.g.
---- snip ----
{foreach macro sort}
{if first }
<section id="macros">
<title>Macros</title>
<variablelist>
{endif}
<varlistentry> =
<term>{type}</term>
<listitem>
<para>{args}</para>
<para>{brief}</para>
</listitem>
</varlistentry> =
{if last}
</variablelist>
</section>
{endif}
{next}
---- snip ----
to generate the list of all macros (or nothing if
no macros are defined). Now the bug is if there is
exactly on element in the list. In this case the
{if first} ... {endif} is ignored. Looking in the
source (around line 1043), there is the sequence
---- snip ----
(($arg[1] eq "first") && $ord=3D=3D0) ||
(($arg[1] eq "last") && $ord=3D=3D-1) ||
---- snip ----
which shows the problem. In case of a one-element
list $ord always -1 (which basically is correct).
I attached a patch which fixes two problems:
-) I added ".sgml" similar to ".html" wrt
escaping of < and >.
-) I fixed above bug quite crude : Instead of -1 in
the last iteration -$index (i.e. -$#group). So I
have "-0" if there is exacly one element in the
list and "0" (on the first iteration) if there are
more than one element. Don't ask me if this
behaviour is actually defined by perl or not.
Bernd