|
htils 1
A small set of utilities for C programming.
|
#include <htils/arena.h>#include <htils/basictypes.h>#include <htils/darray.h>#include <htils/string.h>Go to the source code of this file.
Data Structures | |
| struct | cli_option |
| A cli option. More... | |
| struct | cli |
| The cli state thats used during parsing. More... | |
Typedefs | |
| typedef struct cli_option | htils_cli_option_t |
| A cli option. | |
| typedef struct cli | htils_cli_t |
| The cli state thats used during parsing. | |
Functions | |
| htils_cli_t * | cli_new (arena_t *arena, i64 argc, cstr **argv, const string *name, const string *desc) |
| Create a new cli. | |
| void | cli_add (htils_cli_t *cli, const string *name, const string *desc, b32 requires_arg) |
| Add an option to the cli. | |
| i16 | parse_cli (htils_cli_t *cli) |
| Parse the next CLI argument. | |
| typedef struct cli_option htils_cli_option_t |
A cli option.
| name | The name of the option |
| desc | The description of the option |
| cli_short | The short cli arg of the option |
| cli_long | The long cli arg of the option |
| cli_short_short | The short short cli arg of the option |
| has_arg | Whether the option has another argument |
| typedef struct cli htils_cli_t |
The cli state thats used during parsing.
| argc | The number of arguments |
| argv | The arguments |
| cli_name | The name of the cli |
| cli_desc | The description of the cli |
| options | The options of the cli |
| arena | The arena to use for allocating memory in the cli parser. |
| usage | The usage function to use when printing the usage of the cli. |
| optidx | The index of the current option being parsed. |
| next_char | The next character to parse. |
| optarg | The argument of the current option being parsed. |
| optopt | The option of the current option being parsed. |
| void cli_add | ( | htils_cli_t * | cli, |
| const string * | name, | ||
| const string * | desc, | ||
| b32 | requires_arg ) |
Add an option to the cli.
This will generate short and long option based on the name, and provides a description for the option in the usage command, allowing marking a option as having a required arg.
| cli | The cli to add the option to. |
| name | The name of the option. |
| desc | The description of the option. |
| requires_arg | Whether the option requires another argument afterwards. |
cli, name, and desc must be valid and not null. | htils_cli_t * cli_new | ( | arena_t * | arena, |
| i64 | argc, | ||
| cstr ** | argv, | ||
| const string * | name, | ||
| const string * | desc ) |
Create a new cli.
Allocates a new htils_cli_t struct and initializes default values.
arena, argv, name, and desc must be valid and not null.argc must be greater than 1.| arena | The arena to use for allocating memory in the cli parser. |
| argc | The number of arguments |
| argv | The arguments |
| name | The name of the cli |
| desc | The description of the cli |
| i16 parse_cli | ( | htils_cli_t * | cli | ) |
Parse the next CLI argument.
Intended to be called in a while loop with a switch on the return. Returns the matched argument's code, or one of the error codes: '?' for an unknown argument, ':' when a required argument was missing, and ';' when an argument unexpectedly needs one.
cli must be valid and not null.| cli | The cli to parse. |