🏗️」 wip: parsing should be good

This commit is contained in:
2025-08-12 12:37:05 +02:00
parent 4add0312bc
commit 577563da37
6 changed files with 88 additions and 23 deletions

View File

@ -6,42 +6,58 @@
#include <stdio.h>
#include <stdlib.h>
char *exec_name;
void init_args_t(args_t *args) {
OPT_WHILE {
args->opts[i] = false;
args->arg[i] = NULL;
args->hosts = NULL;
i++;
}
}
int handle_options(args_t *args, char **av) {
// TODO: need to make this function D:
if (args->opts[1]) {
print_help();
return EXIT_SUCCESS;
} else if (args->opts[0]) {
print_no_host(*av);
print_usage();
return EX_USAGE;
} else if (args->opts[2]) {
printf("adjoly's %s: v%s\n", *av, FT_PING_V);
return EXIT_SUCCESS;
} else if (args->opts[1]) {
print_help();
return EXIT_SUCCESS;
} else {
for (int i = 0; args->hosts[i] != NULL; ++i)
printf("%s\n", args->hosts[i]);
}
return EXIT_SUCCESS;
}
int main(int ac, char **av) {
exec_name = *av;
args_t args;
init_args_t(&args);
if (ac > 1) {
int ret = opt_parse(av, &args);
if (ret == -1)
if (ret == -1) {
free(args.hosts);
return EXIT_SUCCESS;
else if (ret != EXIT_SUCCESS)
}
else if (ret != EXIT_SUCCESS) {
free(args.hosts);
return ret;
else
return handle_options(&args, av);
}
else {
ret = handle_options(&args, av);
free(args.hosts);
return ret;
}
} else {
print_no_host(*av);
print_parse_err(MISSING_HOST, NULL);
return EX_USAGE;
}
return EXIT_SUCCESS;