[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [help-gengetopt] how to deal with shared parameters for multiple pro
From: |
Lorenzo Bettini |
Subject: |
Re: [help-gengetopt] how to deal with shared parameters for multiple programs? |
Date: |
Sun, 02 Jan 2011 16:39:30 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7 |
On 01/02/2011 04:12 PM, Erik Sjölund 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) != 0) {
exit(1);
}
CommonFlags common_flags;
common_flags.my_num1 = args_info.num1;
common_flags.my_num2 = args_info.num2;
myFunction(&common_flags);
But it would be nicer if I would not have to define my own struct CommonFlags.
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
one, which is something is still to be implemented in gengetopt...
however, this would have the same semantics of C include, and would only
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
semantics similar to C++ inheritance which is not possible in C...
or, as you suggest, to have pointer to the common struct... that
semantics of include would require a more involved implementation
though... I guess at least...
do you have other ideas?
Note, however, that the generated struct passed to the generated parser
is not thought to be used by other functions... but only to collect
command line arguments and values... those values are better to be
copied into your own variables
hope to hear from you soon
Lorenzo
--
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