「🔨」 fix: fixed issue with init and cleaned help print
This commit is contained in:
@ -26,9 +26,9 @@ static options_t options[] = {
|
|||||||
#undef GRP
|
#undef GRP
|
||||||
};
|
};
|
||||||
|
|
||||||
#define OPT_NB 5
|
#define OPT_NB 7
|
||||||
|
|
||||||
#define FT_PING_V 0.1
|
#define FT_PING_V "0.1"
|
||||||
|
|
||||||
#define OPT_WHILE \
|
#define OPT_WHILE \
|
||||||
int i = 0; \
|
int i = 0; \
|
||||||
|
39
src/help.c
39
src/help.c
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
void print_help(void) {
|
void print_help(void) {
|
||||||
printf("Usage: ping [OPTION...] HOST ...\n");
|
printf("Usage: ping [OPTION...] HOST ...\n");
|
||||||
@ -9,24 +10,40 @@ void print_help(void) {
|
|||||||
|
|
||||||
printf(" All the mandatory options : \n");
|
printf(" All the mandatory options : \n");
|
||||||
OPT_WHILE {
|
OPT_WHILE {
|
||||||
if (options[i].grp == 1)
|
if (options[i].grp == 1) {
|
||||||
printf(" -%c, --%s:\t %s\n", options[i].opt, options[i].name,
|
if (strlen(options[i].name) > 5)
|
||||||
options[i].doc);
|
printf(" -%c, --%s:\t %s\n", options[i].opt, options[i].name,
|
||||||
|
options[i].doc);
|
||||||
|
else
|
||||||
|
printf(" -%c, --%s:\t\t %s\n", options[i].opt, options[i].name,
|
||||||
|
options[i].doc);
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
printf("\n All the bonuses options : \n");
|
||||||
i = 0;
|
i = 0;
|
||||||
printf(" All the bonuses options : \n");
|
|
||||||
while (i < OPT_NB) {
|
while (i < OPT_NB) {
|
||||||
if (options[i].grp == 2)
|
if (options[i].grp == 2) {
|
||||||
printf(" -%c, --%s:\t %s\n", options[i].opt, options[i].name,
|
if (strlen(options[i].name) > 5)
|
||||||
options[i].doc);
|
printf(" -%c, --%s:\t %s\n", options[i].opt, options[i].name,
|
||||||
|
options[i].doc);
|
||||||
|
else
|
||||||
|
printf(" -%c, --%s:\t\t %s\n", options[i].opt, options[i].name,
|
||||||
|
options[i].doc);
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
printf(" All the prints and help function : \n");
|
printf("\n All the prints and help function : \n");
|
||||||
|
i = 0;
|
||||||
while (i < OPT_NB) {
|
while (i < OPT_NB) {
|
||||||
if (options[i].grp == 0)
|
if (options[i].grp == 0) {
|
||||||
printf(" -%c, --%s:\t %s\n", options[i].opt, options[i].name,
|
if (strlen(options[i].name) > 5)
|
||||||
options[i].doc);
|
printf(" -%c, --%s:\t %s\n", options[i].opt, options[i].name,
|
||||||
|
options[i].doc);
|
||||||
|
else
|
||||||
|
printf(" -%c, --%s:\t\t %s\n", options[i].opt, options[i].name,
|
||||||
|
options[i].doc);
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
printf(
|
printf(
|
||||||
|
17
src/main.c
17
src/main.c
@ -10,15 +10,28 @@ 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;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_options(args_t *args) {
|
int handle_options(args_t *args, char **av) {
|
||||||
// TODO: need to make this function D:
|
// 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);
|
||||||
|
return EX_USAGE;
|
||||||
|
} else if (args->opts[2]) {
|
||||||
|
printf("adjoly's %s: v%s\n", *av, FT_PING_V);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char **av) {
|
int main(int ac, char **av) {
|
||||||
args_t args;
|
args_t args;
|
||||||
|
init_args_t(&args);
|
||||||
if (ac > 1) {
|
if (ac > 1) {
|
||||||
int ret = opt_parse(av, &args);
|
int ret = opt_parse(av, &args);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
@ -26,7 +39,7 @@ int main(int ac, char **av) {
|
|||||||
else if (ret != EXIT_SUCCESS)
|
else if (ret != EXIT_SUCCESS)
|
||||||
return ret;
|
return ret;
|
||||||
else
|
else
|
||||||
handle_options(&args);
|
return handle_options(&args, av);
|
||||||
} else {
|
} else {
|
||||||
print_no_host(*av);
|
print_no_host(*av);
|
||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
|
Reference in New Issue
Block a user