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 'non multiple option' behaviour.<br>Let me show you :<br><br= ><div style=3D"margin-left:40px">option "unique" - "set a &#= 39;unique' option" string typestr=3D"STR" optional argop= tional default=3D"unique_default"<br> </div><div style=3D"margin-left:40px">option "multiple" - "s= et a 'multiple' option" string typestr=3D"STR" optio= nal argoptional default=3D"multiple_default" 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>>> 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>>> 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>"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."</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"><<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a>></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 'argoptional' 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'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> > Hi all,<br> ><br> > I defined and option like this :<br> ><br> > option "foo" - "bla bla bla" string typestr=3D&quo= t;STR" default=3D"default_foo"<br> > argoptional multiple optional<br> ><br> > If I call with --foo, the default value is not added to foo_args[0].<b= r> > Actually, foo_args[0] is a NULL pointer, while I expected that<br> > foo_args[0] would be string "default_foo".<br> ><br> > If I remove 'default', and set --foo without any argument, thi= s time<br> > foo_args[0] is set to "default_foo".<br> ><br> > The documentation says :<br> > "If it is known that a multiple option has a default value, then = it can<br> > be safely assumed that the first element of generated array<br> > |<option>_arg| is always set. "<br> ><br> > so it really looks like a bug to me.<br> ><br> > Can someone confirm ?<br> > 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==--