carg-parse/README.md

38 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

2023-05-11 13:52:22 +00:00
# carg-parse
Basic C library to easily parse arguments
# Usage
for a full example of usage look at test.c
Call
`carg_parse(int argc, char** argv)`
2023-05-12 08:56:20 +00:00
it will return `carg_parse_data*` containing:
2023-05-11 19:50:16 +00:00
```c
2023-05-11 13:52:22 +00:00
typedef struct
{
char* exec_name;
uint32_t values_len;
char** values;
uint32_t lv_len;
char** lv_labels;
2023-07-29 12:33:34 +00:00
char** lv_values;
2023-07-29 12:28:55 +00:00
2023-07-29 12:33:34 +00:00
uint32_t flags_len;
char** flags;
2023-05-11 13:52:22 +00:00
} carg_parse_data;
```
Values is an array of all of the free standing arguments passed in
LV is a dictionary, labels in lv_labels and values in lv_values, it contains any labeled arguments '-a b', if a value is not provided lv_value will point to NULL
2023-07-29 12:28:55 +00:00
values, lv_values and flags all point to argv, lv_labels points to argv + 1, as to ignore the dash ('-'), and flags does the same except + 2 as to ignore the double dash ('--')
2023-05-11 13:52:22 +00:00
when done with the data, call
2023-05-11 13:56:10 +00:00
`carg_parse_free(carg_parse_data* data)`
2023-05-15 12:08:35 +00:00
to free the data, it does not free the individual values and labels, as these just point to the values in argv, so if you have moved / modified these pointers, you will have to free them yourself. this has the benifit as well, of allowing you to free carg, even if you have values pointing to strings passed in.