On Tue, Dec 25, 2007 at 02:17:20PM +0100, Alfred M. Szmidt wrote: > Attached is a patch which shows how genparse could be used for > command line parsing of the ping command of the inetutils. > > I doubt we will change any time soon from argp, argp is a standard > part of any GNU system variant, it also does somethings that genparse > does not, most notably leaving --help and --version entierly up to > argp and not to the maintainer (while still giving the maintainer > enough room to customise the output, see libinetutils/libinetutils.h).
genparse also has a default for --help and --version. If you don't specify --help or --version then genparse will automatically add its default implementation. As another option you could extract --help and --version into a seperate genparse (.gp) file. Below is help_version.gp which I wrote for the coreutils: NONE / help flag "display this help and exit__NEW_PRINT__" NONE / version flag "output version information and exit__NEW_PRINT__" The individual tools can then include help_version.gp. This way you can have a project wide customized version of --help and --version but keep the definition in 1 global genparse include file. > With genparse (from the little I saw) you must manually handle all > arguments that you wish to parse, building up a list of if-clauses > that handle each option. In the "argpified" version of ping (http://cvs.savannah.gnu.org/viewvc/*checkout*/inetutils/ping/ping.c?root=inetutils&revision=1.34&content-type=text%2Fplain) there is one big switch statement (in the function parse_opt) which maps the command line parsing results into global variables. In the genparse version of ping (http://genparse.sourceforge.net/examples/ping_clp.c) there is one big switch statement (in the genparse generated parser function Cmdline) which maps the command line parsing results into the parser struct which is also generated by genparse (the arg_t struct in http://genparse.sourceforge.net/examples/ping_clp.h). In my patch for using genparse for the ping command I added a second mapping stage (in the main function) which maps from the arg_t struct to the global variables which ping already has. I did it this way because I wanted to show how genparse works with a patch that is as simple and easy to understand as possible. You could as well define "struct arg_t cmdline" as a global variable and use it directly in your code. I didn't do that because then I would have had to change ping.c in too many places. Michael _______________________________________________ bug-inetutils mailing list [email protected] http://lists.gnu.org/mailman/listinfo/bug-inetutils
