-
Notifications
You must be signed in to change notification settings - Fork 0
Generating C parser
When run with --name <name> --generate cparser
options Yoda generates two files (header and .c one) with
- A structure with options. The structure name is
<name>_yopts
, each option/argument described in the .yoda file has a respective member on it.
Member name is the long option name or the opt_<short_name>
one if the long one is absent. Dashes are changed with underscores.
Types correspond to .yoda file -- int are mapped to int, string and path to char *, bool to bool. If an option is string and has choices, the member named <name>_code
is generated which is filled with YOPT_...
constants.
If an option is pile-d the member is a pointer on an array of respective types and the number of elements in it is put in the <name>_nr
member.
- A parsing routine called
<name>_yopts_parse
. When called with argc and argv reports on of codes:
YOPTS_PARSE_OK
means that parsing was successful,
YOPTS_PARSE_ERR
means there was an error parsing options,
YOPTS_PARSE_SPECIAL
means, that some special option was given in the command line (--help or --version).
The help text is printed automatically.
You can declare your own functions names yopt_print
and yopt_realloc
to provide to this .c file your way of printing messages or reallocating memory. By default libc's printf
and realloc
are used.