Re: how to deal with shared parameters for multiple programs?
Lorenzo Bettini <[email protected]> Sun, 02 Jan 2011 16:39:30 +0100
| Newsgroups | gmane.comp.gnu.gengetopt.general |
|---|---|
| Message-ID | <[email protected]> |
On 01/02/2011 04:12 PM, Erik Sj=F6lund wrote:
> Hi,
> Suppose you have two different programs that share a subset of the
> command line parameters. For instance
>
> option "num1" f "some info" float
> option "num2" f "some info" float
>
> The shared command line parameters are used by a function that both
> programs use.
> One (somewhat sketchy) solution could be:
>
> struct CommonFlags {
> float my_num1;
> float my_num2;
> };
>
> void myFunction(struct commonFlags *common_flags) {
> }
>
> struct gengetopt_args_info args_info;
> if(cmdline_parser(argc2, argv2,&args_info) !=3D 0) {
> exit(1);
> }
>
> CommonFlags common_flags;
> common_flags.my_num1 =3D args_info.num1;
> common_flags.my_num2 =3D args_info.num2;
> myFunction(&common_flags);
>
>
> But it would be nicer if I would not have to define my own struct Commo=
nFlags.
>
> I could avoid that if the two different
> struct gengetopt_args_info
> that are generated for the two different programs could have some
> common struct as a member.
> (That common struct would contain the common flags).
>
> I guess this is not possible with the current version of gengetopt.
> cheers,
> Erik
>
Hi Erik
I think a possible solution is to allow a .ggo file to include another=20
one, which is something is still to be implemented in gengetopt...
however, this would have the same semantics of C include, and would only=20
copy the contents of the included .ggo file.
implementation of such include feature would be quite easy...
otherwise, that include, in order to have what you need, should have a=20
semantics similar to C++ inheritance which is not possible in C...
or, as you suggest, to have pointer to the common struct... that=20
semantics of include would require a more involved implementation=20
though... I guess at least...
do you have other ideas?
Note, however, that the generated struct passed to the generated parser=20
is not thought to be used by other functions... but only to collect=20
command line arguments and values... those values are better to be=20
copied into your own variables
hope to hear from you soon
Lorenzo
--=20
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