Gopt is small set of C functions for parsing POSIX and GNU style command line arguments.
Gopt has a far more simple interface than any of the library functions typically used to perform this task, such as
To see how simple Gopt is, look the sample program, gopt-usage.c.
The documentation is provided as comments in the header file, gopt.h.
Gopt is written in pure C. Gopt is free standing; it has no dependencies other than the C library.
- No loop required in main(), just a single function call.
- Short (POSIX/Unix) style options, like mkdir -p
- Long (GNU) style options, like cp --remove-destination
- Short option names are matched case-sensitively, long names are matched case-insesnsitively.
- Automatic recognition of abbreviated long options, like cp --rem
- Option arguments, like --ignore=tmp, --ignore tmp, -Itmp or -I tmp
- Automatic counting of repeatable options.
- End of options delimiting with --
- Options and option arguments are removed from the argument vector (argv), leaving only true operands.
- Corrected operand count returned to argc.
There is an optional function (in gopt-errors.c) which provides:
- Error messages to stderr for unknown or ambiguous options.
- Error messages to stderr for option arguments which are missing or forbidden.
- Program termination on error.
The following limitations are by design:
- No support for negative numeric operands (ie: -7 is option 7, not argument minus 7).
- No recording of the order in which options or arguments were specified.
- No automatic handling of --help or --version
The optional error handling function provides messages in English only, but if the rest of your application provides translation
then it would be easy to incorporate.
Download gopt-10.0.txz, or:
This is truly free software.