|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
how to deal with shared parameters for multiple programs?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 _______________________________________________ Help-gengetopt mailing list Help-gengetopt@... http://lists.gnu.org/mailman/listinfo/help-gengetopt |
|
|
Re: how to deal with shared parameters for multiple programs?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 _______________________________________________ Help-gengetopt mailing list Help-gengetopt@... http://lists.gnu.org/mailman/listinfo/help-gengetopt |
|
|
Re: how to deal with shared parameters for multiple programs?Hi Lorenzo,
> 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... Yes, I read about the plans. Before that is being implemented it is always possible to use cmake or some other tool to generate out the .ggo files. > 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... You understood me perfectly. > do you have other ideas? Not really. > 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 Yes, you are probably right. I think I will use my own struct instead. If I for instance later want to publish an open source library, there better be no dependencies on gengetopt in the functions of the library. cheers, Erik _______________________________________________ Help-gengetopt mailing list Help-gengetopt@... http://lists.gnu.org/mailman/listinfo/help-gengetopt |
|
|
Re: how to deal with shared parameters for multiple programs?On Sun, Jan 2, 2011 at 5:21 PM, Erik Sjölund <erik.sjolund@...> wrote:
> Hi Lorenzo, > >> 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... > > Yes, I read about the plans. Before that is being implemented it is > always possible to use > cmake or some other tool to generate out the .ggo files. I got an idea. If in addition to cmdline_parser (argc, argv, &args_info) there would also be a cmdline_parser_allow_unknown_flags(argc, argv, &args_info) and if there also would be an include directive in gengetopt configuration files, a program could first let gengetopt parse all the flags of the program (implemented with includes and cmdline_parser(argc, argv, &args_info)). After that the program would run the function cmdline_parser_allow_unknown_flags(argc, argv, &args_info2) that was generated out of only the common flags. Advantage: If you have multiple programs that have common flags, you avoid duplicating code. Drawbacks: This solution would mean that argv would be parsed twice. Also group options would be troublesome. cheers, Erik Sjölund _______________________________________________ Help-gengetopt mailing list Help-gengetopt@... https://lists.gnu.org/mailman/listinfo/help-gengetopt |
| Free embeddable forum powered by Nabble | Forum Help |