47 lines
1.1 KiB
Markdown
47 lines
1.1 KiB
Markdown
|
|
# CgeArgs - CLI argument parsing
|
||
|
|
|
||
|
|
TODO
|
||
|
|
|
||
|
|
## Usage Example
|
||
|
|
|
||
|
|
```c
|
||
|
|
#include "CgeArgs.h"
|
||
|
|
#include <stdio.h>
|
||
|
|
|
||
|
|
int main(int argc, char **argv) {
|
||
|
|
int boolOption = 0, intOption = 0;
|
||
|
|
const char *strOption = "default";
|
||
|
|
float floatOption = 0;
|
||
|
|
double doubleOption = 0;
|
||
|
|
int i;
|
||
|
|
|
||
|
|
CgeArgs args[] = {
|
||
|
|
{'a', "a", CGE_ARGS_BOOL, &boolOption},
|
||
|
|
{'b', "b", CGE_ARGS_INT, &intOption},
|
||
|
|
{'c', "c", CGE_ARGS_STRING, &strOption},
|
||
|
|
{'d', "d", CGE_ARGS_FLOAT, &floatOption},
|
||
|
|
{'e', "e", CGE_ARGS_DOUBLE, &doubleOption},
|
||
|
|
};
|
||
|
|
|
||
|
|
i = CgeArgsParse(args, sizeof(args) / sizeof(CgeArgs), argc, argv);
|
||
|
|
if (i != -1) {
|
||
|
|
printf("bool: %d\n", boolOption);
|
||
|
|
printf("int: %d\n", intOption);
|
||
|
|
printf("str: %s\n", strOption);
|
||
|
|
printf("float: %f\n", floatOption);
|
||
|
|
printf("double: %lf\n", doubleOption);
|
||
|
|
|
||
|
|
for (; i < argc; i++) {
|
||
|
|
printf("free arg: %s\n", argv[i]);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
printf("unknown arg\n");
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
## License
|
||
|
|
|
||
|
|
0BSD - a permissive license with no attribution required.
|