「🏗️」 wip: polished a little the prints and fix short opt not working
This commit is contained in:
@ -58,3 +58,5 @@ void print_parse_err(error_t err, char *opt);
|
|||||||
void print_help(void);
|
void print_help(void);
|
||||||
|
|
||||||
void print_usage(void);
|
void print_usage(void);
|
||||||
|
|
||||||
|
void print_version(void);
|
||||||
|
25
src/help.c
25
src/help.c
@ -56,15 +56,14 @@ void print_help(void) {
|
|||||||
|
|
||||||
void print_parse_err(error_t err, char *opt) {
|
void print_parse_err(error_t err, char *opt) {
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case MISSING_HOST:
|
case MISSING_HOST:
|
||||||
printf("%s: missing host operand\n", exec_name);
|
printf("%s: missing host operand\n", exec_name);
|
||||||
break;
|
break;
|
||||||
case INVALID_OPT:
|
case INVALID_OPT:
|
||||||
printf("%s: invalid option -- %s\n", exec_name, opt);
|
printf("%s: invalid option -- %s\n", exec_name, opt);
|
||||||
break;
|
break;
|
||||||
case NEED_ARG:
|
case NEED_ARG:
|
||||||
printf("%s: option '--%s' requires an argument\n", exec_name, opt);
|
printf("%s: option '--%s' requires an argument\n", exec_name, opt);
|
||||||
|
|
||||||
}
|
}
|
||||||
printf("Try 'ping --help' or 'ping --usage' for more information.\n");
|
printf("Try 'ping --help' or 'ping --usage' for more information.\n");
|
||||||
}
|
}
|
||||||
@ -77,3 +76,11 @@ void print_usage(void) {
|
|||||||
}
|
}
|
||||||
printf("HOST ...\n");
|
printf("HOST ...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_version(void) {
|
||||||
|
printf("adjoly's ft_ping: v%s\n", FT_PING_V);
|
||||||
|
printf(
|
||||||
|
"This is free software: you are free to change and redistribute it.\n");
|
||||||
|
printf("There is NO WARRANTY, to the extent permitted by law.\n\n");
|
||||||
|
printf("License MIT: Copyright (C) 2025 Adam\n");
|
||||||
|
}
|
||||||
|
10
src/main.c
10
src/main.c
@ -12,9 +12,9 @@ void init_args_t(args_t *args) {
|
|||||||
OPT_WHILE {
|
OPT_WHILE {
|
||||||
args->opts[i] = false;
|
args->opts[i] = false;
|
||||||
args->arg[i] = NULL;
|
args->arg[i] = NULL;
|
||||||
args->hosts = NULL;
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
args->hosts = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int handle_options(args_t *args, char **av) {
|
int handle_options(args_t *args, char **av) {
|
||||||
@ -25,7 +25,7 @@ int handle_options(args_t *args, char **av) {
|
|||||||
print_usage();
|
print_usage();
|
||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
} else if (args->opts[2]) {
|
} else if (args->opts[2]) {
|
||||||
printf("adjoly's %s: v%s\n", *av, FT_PING_V);
|
print_version();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
} else if (args->opts[1]) {
|
} else if (args->opts[1]) {
|
||||||
print_help();
|
print_help();
|
||||||
@ -46,12 +46,10 @@ int main(int ac, char **av) {
|
|||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
free(args.hosts);
|
free(args.hosts);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
} else if (ret != EXIT_SUCCESS) {
|
||||||
else if (ret != EXIT_SUCCESS) {
|
|
||||||
free(args.hosts);
|
free(args.hosts);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ret = handle_options(&args, av);
|
ret = handle_options(&args, av);
|
||||||
free(args.hosts);
|
free(args.hosts);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -39,12 +39,13 @@ int opt_parse(char **av, args_t *args) {
|
|||||||
OPT_WHILE {
|
OPT_WHILE {
|
||||||
if (opt == options[i].opt) {
|
if (opt == options[i].opt) {
|
||||||
OPT_HANDLE(i)
|
OPT_HANDLE(i)
|
||||||
} else {
|
|
||||||
print_parse_err(INVALID_OPT, a);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
if (i == OPT_NB) {
|
||||||
|
print_parse_err(INVALID_OPT, a);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (args->hosts == NULL) {
|
if (args->hosts == NULL) {
|
||||||
|
Reference in New Issue
Block a user