|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
gengetopt: initialization of args_info_help[]Hi Lorenzo,
Here's a question about the initialization of the args_info_help[] array created by gengetopt: In my application I'm using several commandline parsers, all generated by gengetopt. I'm trying to implement a kind of complete help that ties together all the help texts of the individual parsers. That looks like an easy thing to do given that each parser's header file contains entries of the form extern const char *xxx_args_info_help[]; and extern const char *xxx_args_info_detailed_help[]; So one just has to do loop over all parsers and over all lines in the corresponding xxx_args_info_help array. Similarly for the detailed help. Right? To my surprise, this approach works just fine for the detailed help but fails for the short help. By looking at the generated code, the reason becomes clear: The array for the detailed help is being initialized directly by using string literals while the short help is defined as a subarray of the detailed_help array. This subarray is extracted and initialized by the init_help_array() function: static void init_help_array(void) { xxx_args_info_help[0] = xxx_info_detailed_help[0]; xxx_args_info_help[1] = xxx_info_detailed_help[1]; xxx_args_info_help[2] = xxx_info_detailed_help[2]; xxx_args_info_help[3] = xxx_info_detailed_help[3]; xxx_args_info_help[4] = xxx_info_detailed_help[5]; xxx_args_info_help[0] = 0; } (in this example xxx_info_detailed_help[4] is not contained in the short help) Before that function gets called, the contents of xxx_args_info_help will be undefined. Since init_help_array() is a static function, it is not possible to call it directly from the application that uses gengetopt. The only way to get an initialized xxx_args_info_help array is to call xxx_cmdline_parser_init() which implicitly calls init_help_array(). So for N parsers, I have to allocate N args_info structures and call N init functions even in the case I just want to print the short help. Is this behaviour intended? An alternative would be to initialize also the short help by using string literals, just like the detailed help. The duplicated strings would not increase code size because the compiler should be smart enough to put identical strings into memory only once. Regards Andre -- The only person who always got his work done by Friday was Robinson Crusoe _______________________________________________ Help-gengetopt mailing list Help-gengetopt@... http://lists.gnu.org/mailman/listinfo/help-gengetopt |
|
|
Re: gengetopt: initialization of args_info_help[]Andre Noll wrote:
> Hi Lorenzo, > Hi Andre <SNIP> > > Before that function gets called, the contents of xxx_args_info_help > will be undefined. Since init_help_array() is a static function, it > is not possible to call it directly from the application that uses > gengetopt. The only way to get an initialized xxx_args_info_help > array is to call xxx_cmdline_parser_init() which implicitly calls > init_help_array(). > > So for N parsers, I have to allocate N args_info structures and call > N init functions even in the case I just want to print the short help. > Is this behaviour intended? > I never thought about such a situation actually; I think that that init help function might be made public and callable from outside > An alternative would be to initialize also the short help by using > string literals, just like the detailed help. The duplicated strings > would not increase code size because the compiler should be smart > enough to put identical strings into memory only once. please, do not ask for that ;-) ;-) this behavior was requested by other users and it was quite a nightmare to implement it, so I wouldn't want to go back ;-) I'll try to handle this matter soon. thanks for the feedback cheers 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: gengetopt: initialization of args_info_help[]On 09:30, Lorenzo Bettini wrote:
> >So for N parsers, I have to allocate N args_info structures and call > >N init functions even in the case I just want to print the short help. > >Is this behaviour intended? > > > > I never thought about such a situation actually; I think that that init > help function might be made public and callable from outside Yes, that would be easiest, one just has to remove the static keyword in the .c file and add the function prototype to the .h file. Alternativly one could change the cmdline_parser_init function so that it just calls init_help() if called with a NULL pointer. Currently, such a usage would lead to a segfault. > >An alternative would be to initialize also the short help by using > >string literals, just like the detailed help. The duplicated strings > >would not increase code size because the compiler should be smart > >enough to put identical strings into memory only once. > > please, do not ask for that ;-) ;-) > this behavior was requested by other users and it was quite a nightmare > to implement it, so I wouldn't want to go back ;-) OK, so I won't argue for this alternative any more :) But out of curiosity, what were the problems in inplementing it this way? Andre -- The only person who always got his work done by Friday was Robinson Crusoe _______________________________________________ Help-gengetopt mailing list Help-gengetopt@... http://lists.gnu.org/mailman/listinfo/help-gengetopt |
|
|
Re: gengetopt: initialization of args_info_help[]Andre Noll wrote:
> On 09:30, Lorenzo Bettini wrote: >>> So for N parsers, I have to allocate N args_info structures and call >>> N init functions even in the case I just want to print the short help. >>> Is this behaviour intended? >>> >> I never thought about such a situation actually; I think that that init >> help function might be made public and callable from outside > > Yes, that would be easiest, one just has to remove the static > keyword in the .c file and add the function prototype to the .h file. > > Alternativly one could change the cmdline_parser_init function so that > it just calls init_help() if called with a NULL pointer. Currently, > such a usage would lead to a segfault. > mh... probably the first alternative has a cleaner semantics >>> An alternative would be to initialize also the short help by using >>> string literals, just like the detailed help. The duplicated strings >>> would not increase code size because the compiler should be smart >>> enough to put identical strings into memory only once. >> please, do not ask for that ;-) ;-) >> this behavior was requested by other users and it was quite a nightmare >> to implement it, so I wouldn't want to go back ;-) > > OK, so I won't argue for this alternative any more :) But out of > curiosity, what were the problems in inplementing it this way? actually, I don't remember all the details now, but the problem was in the generation of code and keeping tracking of all kinds of options and performing the right assignments... cheers 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: gengetopt: initialization of args_info_help[]On 12:49, Lorenzo Bettini wrote:
> >Yes, that would be easiest, one just has to remove the static > >keyword in the .c file and add the function prototype to the .h file. > > > >Alternativly one could change the cmdline_parser_init function so that > >it just calls init_help() if called with a NULL pointer. Currently, > >such a usage would lead to a segfault. > > > > mh... probably the first alternative has a cleaner semantics Sure that's cleaner. The advantage of the second alternative is that the public interface needs no extention. Making functions public (by putting them into the .h file) means that the interface is fixed from now on. I don't have a strong opinion about this, so feel free to implement what you feel is most appropriate :) Thanks Andre -- The only person who always got his work done by Friday was Robinson Crusoe _______________________________________________ Help-gengetopt mailing list Help-gengetopt@... http://lists.gnu.org/mailman/listinfo/help-gengetopt |
| Free embeddable forum powered by Nabble | Forum Help |