by majika · 10y ago · 0 comments
I've been working on libargs for the past year; it's a declarative argument-parsing library for C: https://github.com/mcinglis/libargs
The main idea is that each argument is by default parsed and stored as a string, or you can optionally specify a function of the type `void f(char * name, char * arg, void * dest)` to parse the argument string and store it in a well-typed destination. This way, you can have an `int` argument by passing `int__argparse` as the parser, and if the user passes a value outside the range of `int`, then an appropriate out-of-range error is printed to the console. Similarly with `uchar__argparse` or something like `point__argparse` (e.g. taking some format like `{x,y}`).
libargs is quite flexible and has worked well for me so far. Automatic help text generation can be added in future while maintaining (non-ABI) backwards compatibility.
The main disadvantage is that it depends on other libraries I've developed that are essentially Jinja-templated C source files that function as makeshift generic types / typeclasses in C. Your inclination towards this approach depends on taste; personally I much prefer deferring the pain to the build system, as opposed to the source code.
>All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
I doubt the library is usable in C++ though, since longjmp doesn't play well with the destruction of local objects.
That's one of the reasons I use it, actually. For simple utilities it may be adequate to set flags and store values for command-line parameters, but sometimes you need the flexibility of being able to run whatever code you need when an option arrives.
Okay, but why?
Ask the FSF how long it took them to finally sort out all the legal issues and prepare new forms.
CLA to non-profit > CLA to indidual > CLA to company