GNU gengetopt takes a simple description of arguments and generates a C function that uses the GNU getopt_long(3) function to parse and validate the options. It is perfect if you are too lazy to write all that is required to call getopt_long(3), or need to use many options. The generated code also works with autoconf or automake.
| Tags | Software Development Utilities |
|---|---|
| Licenses | GPL |
| Operating Systems | OS Independent |
| Implementation | C C++ |
Recent releases


Changes: Further compilation warnings for generated files were removed. A compilation problem for files generated with --include-getopt with some versions of stdlib.h was fixed. The dependency on the flex library (which generated problems in compilation in Open Solaris) was removed. PACKAGE_NAME, if defined, is used for printing help and version. The configure option --docdir is now used, if specified for installing documentation.


Changes: Compilation warnings for generated files were removed. A bug with --long-help and enum options was fixed and the output of --help and output of --show-help now correspond. A compilation problem in generated output with mode options was fixed.


Changes: The generated code was highly refactored in order to be cleaner and easier to understand. Many bugs were fixed. A list of possible values can have types (instead of only strings). Options can be given more details. Mode options were added: mutually exclusive groups of options.


Changes: This release fixes some bugs when --include-getopt is specified. In help output, a section is not generated if all its options are hidden. The option --default-optional, which allows specifying that all options are by default optional, was added. A bug corrupting memory when using args entry in the .ggo file was fixed.


Changes: Compilation problems that could make 'make check' fail on some systems lacking getopt_long were fixed along with a test problem when not using GNU sed. In strings, # comments are now not considered.
- All comments
Recent commentsRe: Almost...
>
> % we aren't running Linux so we
> % don't have the GNU C library, and so
> we
> % don't have getopt_long. That,
>
>
> I just grabbed a netbsd libc and pulled
> getopt_long from that. Its a bit of
> work to remove all the references to the
> libc build framework common bits, bit a
> heck of a lot easier than writing a
> generator.
>
> I think pretty much any *BSD libc will
> do - most include the code from netbsd
> as far as I know.
>
> You should be able to use the CVS
> viewers to get the code without having a
> full distro handy.
>
gengetopt comes with a version of getopt.h getopt.c and getopt1.c and they are all you need to use getopt_long if it doesn't come with libc.
Also, in the manual, there's a chapter explaining how to deal with missing getopt_long.
Hope it helps.
Re: Almost...
> we aren't running Linux so we
> don't have the GNU C library, and so we
> don't have getopt_long. That,
I just grabbed a netbsd libc and pulled getopt_long from that. Its a bit of work to remove all the references to the libc build framework common bits, bit a heck of a lot easier than writing a generator.
I think pretty much any *BSD libc will do - most include the code from netbsd as far as I know.
You should be able to use the CVS viewers to get the code without having a full distro handy.
Almost...
This is almost exactly what I was about to write myself. I haven't seen
the code, just the homepage. The only thing that makes it unsuitable for
use on my systems is that (heinous sin) we aren't running Linux so we
don't have the GNU C library, and so we don't have getopt_long. That,
and modifying main() isn't what I had in mind...
If I end up writing another option generator, I'll mention this one in the
documentation as an alternative that supports getopt_long.