Re: BUG : mutiple and argoptional option fail to fill <opt>_args[0] with default value

Frédéric Heitzmann <[email protected]> Fri, 19 Oct 2012 16:00:35 +0200
Newsgroups gmane.comp.gnu.gengetopt.general
Message-ID <CALeToSW8=0wKVseEiMG8cmwuD0nkGrSyLPzjB7AHwUWGM7QSNA@mail.gmail.com>
--===============6050631543228188032==
Content-Type: multipart/alternative; boundary=e89a8f503838f9d92d04cc69ef4e

--e89a8f503838f9d92d04cc69ef4e
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Lorenzo,

It __would__ make sense if this behaviour was consistent with the 'non
multiple option' behaviour.
Let me show you :

option "unique" - "set a 'unique' option" string typestr=3D"STR" optional
argoptional default=3D"unique_default"
option "multiple" - "set a 'multiple' option" string typestr=3D"STR" option=
al
argoptional default=3D"multiple_default" multiple

Using a small test program (code below), I see :

$ ./ggotest
unique: unique_arg=3Dunique_default unique_orig=3D(null) unique_given=3D0
multiple: multiple_given=3D0 multiple_arg[0]=3Dmultiple_default
multiple_orig[0]=3D(null)

>> excepted

$ ./ggotest --unique --multiple
unique: *unique_arg=3Dunique_default* unique_orig=3D(null) unique_given=3D1
multiple: multiple_given=3D0 *multiple_arg[0]=3D(null)* multiple_orig[0]=3D=
(null)

>> oops ! I expected to see the same argument for both options.
According to you, maybe it is the --unique option which should have a
(null) argument.
Either way, the current behaviour seems inconsistent, and unaligned with
the documentation :
*"If it is known that a multiple option has a default value, then it can be
safely assumed that the first element of generated array <option>_arg| is
always set."*

What do you think ?

--
Fred

On 19 October 2012 12:54, Lorenzo Bettini <[email protected]> wrote:

> Hi
>
> since you also specify that 'argoptional' then the default value is not
> set if you specify no argument to --foo, since the argument is optional,
> so that option --foo is meant to be able to deal also with no argument
> at all... that's how I interpreted the semantics when I implemented it.
>
> Does it make sense?
>
> hope to hear from you soon
> cheers
>         Lorenzo
>
> P.S. please take a look at the current open (and closed) bugs to make
> sure that this issue has already been raised.
>
> On 10/19/2012 10:57 AM, Fr=C3=A9d=C3=A9ric Heitzmann wrote:
> > Hi all,
> >
> > I defined and option like this :
> >
> > option "foo" - "bla bla bla" string typestr=3D"STR" default=3D"default_=
foo"
> > argoptional multiple optional
> >
> > If I call with --foo, the default value is not added to foo_args[0].
> > Actually, foo_args[0] is a NULL pointer, while I expected that
> > foo_args[0] would be string "default_foo".
> >
> > If I remove 'default', and set --foo without any argument, this time
> > foo_args[0] is set to "default_foo".
> >
> > The documentation says :
> > "If it is known that a multiple option has a default value, then it can
> > be safely assumed that the first element of generated array
> > |<option>_arg| is always set. "
> >
> > so it really looks like a bug to me.
> >
> > Can someone confirm ?
> > I may work on a patch if it helps.
>
>
> --
> Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
> ICQ# lbetto, 16080134     (GNU/Linux User # 158233)
> HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
> http://www.myspace.com/supertrouperabba
> BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com
> http://www.gnu.org/software/src-highlite
> http://www.gnu.org/software/gengetopt
> http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
>
> _______________________________________________
> Help-gengetopt mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/help-gengetopt
>

--e89a8f503838f9d92d04cc69ef4e
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Lorenzo,<br><br>It __would__ make sense if this behaviour was consistent wi=
th the &#39;non multiple option&#39; behaviour.<br>Let me show you :<br><br=
><div style=3D"margin-left:40px">option &quot;unique&quot; - &quot;set a &#=
39;unique&#39; option&quot; string typestr=3D&quot;STR&quot; optional argop=
tional default=3D&quot;unique_default&quot;<br>

</div><div style=3D"margin-left:40px">option &quot;multiple&quot; - &quot;s=
et a &#39;multiple&#39; option&quot; string typestr=3D&quot;STR&quot; optio=
nal argoptional default=3D&quot;multiple_default&quot; multiple<br></div><b=
r>

Using a small test program (code below), I see :<br><br>$ ./ggotest<br>uniq=
ue: unique_arg=3Dunique_default unique_orig=3D(null) unique_given=3D0<br>mu=
ltiple: multiple_given=3D0 multiple_arg[0]=3Dmultiple_default multiple_orig=
[0]=3D(null)<br>

<br>&gt;&gt; excepted<br><br>$ ./ggotest --unique --multiple<br>unique: <b>=
unique_arg=3Dunique_default</b> unique_orig=3D(null) unique_given=3D1<br>mu=
ltiple: multiple_given=3D0 <b>multiple_arg[0]=3D(null)</b> multiple_orig[0]=
=3D(null)<br>

<br>&gt;&gt; oops ! I expected to see the same argument for both options.<b=
r>According to you, maybe it is the --unique option which should have a (nu=
ll) argument.<br>Either way, the current behaviour seems inconsistent, and =
unaligned with the documentation :<br>

<i>&quot;If it is known that a multiple option has a default value, then it=
 can be safely assumed that the first element of generated array &lt;option=
&gt;_arg| is always set.&quot;</i><br><br>What do you think ?<br><br>--<br>

Fred<br><br><div class=3D"gmail_quote">On 19 October 2012 12:54, Lorenzo Be=
ttini <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>&gt;</span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">

Hi<br>
<br>
since you also specify that &#39;argoptional&#39; then the default value is=
 not<br>
set if you specify no argument to --foo, since the argument is optional,<br=
>
so that option --foo is meant to be able to deal also with no argument<br>
at all... that&#39;s how I interpreted the semantics when I implemented it.=
<br>
<br>
Does it make sense?<br>
<br>
hope to hear from you soon<br>
cheers<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Lorenzo<br>
<br>
P.S. please take a look at the current open (and closed) bugs to make<br>
sure that this issue has already been raised.<br>
<div><div class=3D"h5"><br>
On 10/19/2012 10:57 AM, Fr=C3=A9d=C3=A9ric Heitzmann wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt; I defined and option like this :<br>
&gt;<br>
&gt; option &quot;foo&quot; - &quot;bla bla bla&quot; string typestr=3D&quo=
t;STR&quot; default=3D&quot;default_foo&quot;<br>
&gt; argoptional multiple optional<br>
&gt;<br>
&gt; If I call with --foo, the default value is not added to foo_args[0].<b=
r>
&gt; Actually, foo_args[0] is a NULL pointer, while I expected that<br>
&gt; foo_args[0] would be string &quot;default_foo&quot;.<br>
&gt;<br>
&gt; If I remove &#39;default&#39;, and set --foo without any argument, thi=
s time<br>
&gt; foo_args[0] is set to &quot;default_foo&quot;.<br>
&gt;<br>
&gt; The documentation says :<br>
&gt; &quot;If it is known that a multiple option has a default value, then =
it can<br>
&gt; be safely assumed that the first element of generated array<br>
&gt; |&lt;option&gt;_arg| is always set. &quot;<br>
&gt;<br>
&gt; so it really looks like a bug to me.<br>
&gt;<br>
&gt; Can someone confirm ?<br>
&gt; I may work on a patch if it helps.<br>
<br>
<br>
--<br>
</div></div>Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino<br>
ICQ# lbetto, 16080134 =C2=A0 =C2=A0 (GNU/Linux User # 158233)<br>
HOME: <a href=3D"http://www.lorenzobettini.it" target=3D"_blank">http://www=
.lorenzobettini.it</a> MUSIC: <a href=3D"http://www.purplesucker.com" targe=
t=3D"_blank">http://www.purplesucker.com</a><br>
<a href=3D"http://www.myspace.com/supertrouperabba" target=3D"_blank">http:=
//www.myspace.com/supertrouperabba</a><br>
BLOGS: <a href=3D"http://tronprog.blogspot.com" target=3D"_blank">http://tr=
onprog.blogspot.com</a> =C2=A0<a href=3D"http://longlivemusic.blogspot.com"=
 target=3D"_blank">http://longlivemusic.blogspot.com</a><br>
<a href=3D"http://www.gnu.org/software/src-highlite" target=3D"_blank">http=
://www.gnu.org/software/src-highlite</a><br>
<a href=3D"http://www.gnu.org/software/gengetopt" target=3D"_blank">http://=
www.gnu.org/software/gengetopt</a><br>
<a href=3D"http://www.gnu.org/software/gengen" target=3D"_blank">http://www=
.gnu.org/software/gengen</a> <a href=3D"http://doublecpp.sourceforge.net" t=
arget=3D"_blank">http://doublecpp.sourceforge.net</a><br>
<br>
_______________________________________________<br>
Help-gengetopt mailing list<br>
<a href=3D"mailto:[email protected]">[email protected]</a><br>
<a href=3D"https://lists.gnu.org/mailman/listinfo/help-gengetopt" target=3D=
"_blank">https://lists.gnu.org/mailman/listinfo/help-gengetopt</a><br>
</blockquote></div><br>

--e89a8f503838f9d92d04cc69ef4e--


--===============6050631543228188032==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Help-gengetopt mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-gengetopt

--===============6050631543228188032==--