33 lines
755 B
C
33 lines
755 B
C
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
#include <args/args.h>
|
|
#include <string/conv.h>
|
|
#include <string/string.h>
|
|
#include <uprintf.h>
|
|
|
|
int32_t parse_args(char **argv, size_t argc, Arg *defs) {
|
|
for (size_t i = 0; i < argc; i++) {
|
|
if (argv[i][0] == '-' && argv[i][1] != '\0') {
|
|
char *optname = argv[i];
|
|
size_t j = 0;
|
|
while (!defs[j].end) {
|
|
Arg *def = &defs[j];
|
|
if (string_strcmp(def->shortname, optname) == 0) {
|
|
if (i < argc - 1) {
|
|
switch (def->expected_value) {
|
|
case ARG_STRING:
|
|
*((char **)def->ptr) = argv[i+1];
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
j++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return ARGP_OK;
|
|
}
|