「🏗️」 wip: parsing kinda working
This commit is contained in:
@ -4,36 +4,48 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sysexits.h>
|
||||
|
||||
int handle_long_args(char **av, args_t *args) {
|
||||
OPT_WHILE {
|
||||
if (strncmp((*av) + 2, options[i].name, strlen(options[i].name)) == 0) {
|
||||
OPT_HANDLE(i)
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int opt_parse(char **av, args_t *args) {
|
||||
char *exec_name = *av;
|
||||
|
||||
(void)args;
|
||||
while (*av != NULL) {
|
||||
char *a = *av;
|
||||
|
||||
if (*a == '-') {
|
||||
switch ((char)*(a + 1)) {
|
||||
case '-':
|
||||
break;
|
||||
case '?':
|
||||
print_help();
|
||||
return -1;
|
||||
case 'v':
|
||||
printf("verboseeee");
|
||||
break;
|
||||
};
|
||||
char opt = *(a + 1);
|
||||
if (!opt) {
|
||||
print_no_host(exec_name);
|
||||
return EX_USAGE;
|
||||
} else if (opt == '-') {
|
||||
int ret = handle_long_args(av, args);
|
||||
if (ret == EX_USAGE) {
|
||||
print_no_host(exec_name);
|
||||
return EX_USAGE;
|
||||
}
|
||||
} else {
|
||||
OPT_WHILE {
|
||||
if (opt == options[i].opt) {
|
||||
OPT_HANDLE(i)
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
av++;
|
||||
}
|
||||
|
||||
if (av) {
|
||||
print_no_host(exec_name);
|
||||
return EX_USAGE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user