Friday, September 29, 2006

GNU Gengetopt 2.18

I released few days ago the new version of GNU Gengetopt, http://www.gnu.org/software/gengetopt, a GNU program I'm the maintainer of.

Gengetopt is a generator of parsers of command line options.

It generates a C function that uses getopt_long function to parse the command line options, to validate them and fills a struct. Thus your program can handle options such as:

myprog --input foo.c -o foo.o --no-tabs -i 100 *.class
And both long options (those that start with --) and short options (start with - and consist of only one character) can be handled. For standards about short and long options you may want to take a look at the GNU Coding Standards.

Command line options are an important feature of every non trivial programs. The getopt functions already do a good job in parsing them, but a lot of programming is still require... Gengetopt will do this additional programming for you, and you simply have to provide a file with the specification of the options your program accepts.

I refer the interested programmers to gengetopt's documentation.

7 comments:

daniele said...

This is the very first comment to your blog.
Good job.


Ma untiriesce miha!

daniele

betto said...

thanks!

eciprovo! :-)

Anonymous said...

Hi,

I see you use both gengetopt and kdevelop. I do too, but I don't know how to combine them.
I let kdevelop take care of makefiles, which works fine, but how do I let kdevelop know that I use gengetopt?
I.e. how do I get kdevelop to run:
gengetop < somefile.ggo
(when needed) automatically when I hit build or type make?

Currently I run
gengetop < somefile.ggo
manually when I need to....

Cheers,
Sam

betto said...

I don't know how to add such functionality to kdevelop.
What I do is to put, in the Makefile.am, a line such as:

%.c: %.ggo
gengetopt --input=$<

this way, when you modify the .ggo file, the make system will take care of this.
Please let me know whether this solves your problem.

betto said...

of course the second line should be preceeded by a tab (following the make file syntax)

%.c: %.ggo
gengetopt --input=$<

but the blog system seems to remove the tab :-)

Anonymous said...

Thanks for the quick response.

When I followed your suggestion, I got the gengetopt command to run always, which is not so good.
But if I hard-coded file names (and used the .h file), I got it too work.

cmdline.h: emmy.ggo
gengetopt < emmy.ggo

My knowledge of autotools is limited, as you may have expected.
Curiously, the following didn't work.
%.h:%.ggo


I'm quite satisfied with this solution anyway.

Thanks!

/Sam

betto said...

that's pretty strange: the %.h:%.ggo solution should work...

however, also the explicit one is correct, so if it works that's fine :-)