diff --git a/includes/help.h b/includes/help.h index d7cf224..07a7653 100644 --- a/includes/help.h +++ b/includes/help.h @@ -1,7 +1,7 @@ #pragma once #include -struct options{ +struct options { char *name; char opt; char *doc; diff --git a/src/parsing/opt_parse.c b/src/parsing/opt_parse.c index 38298cf..226f80f 100644 --- a/src/parsing/opt_parse.c +++ b/src/parsing/opt_parse.c @@ -7,14 +7,29 @@ #include #include -int handle_long_args(char **av, args_t *args) { +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); + if (strncmp((**av) + 2, options[i].name, strlen(options[i].name)) == + 0) { + if (options[i].arg_nb == 1) { + if (!(*av + 1) || !*(*av + 1)) { + print_parse_err(NEED_ARG, (**av) + 1); + return EX_USAGE; + } + int n = atoi(*(*av + 1)); + if (n == 0) { + print_parse_err(ERR_ARG, (**av) + 1); + return EX_USAGE; + } + args->arg[i] = n; + (*av)++; + } + args->opts[i] = true; + return EXIT_SUCCESS; } i++; } - print_parse_err(INVALID_OPT, (*av) + 2); + print_parse_err(INVALID_OPT, (**av) + 2); return EXIT_FAILURE; } @@ -29,7 +44,7 @@ int opt_parse(char **av, args_t *args) { print_parse_err(MISSING_HOST, 0); return EX_USAGE; } else if (opt == '-') { - int ret = handle_long_args(av, args); + int ret = handle_long_args(&av, args); if (ret != EXIT_SUCCESS) { if (ret == EX_USAGE) print_parse_err(NEED_ARG, (*av) + 2); @@ -39,6 +54,9 @@ int opt_parse(char **av, args_t *args) { OPT_WHILE { if (opt == options[i].opt) { OPT_HANDLE(i) + if (options[i].arg_nb == 1) { + av++; + } } i++; } diff --git a/src/utils.c b/src/utils.c index fc927b3..f80c396 100644 --- a/src/utils.c +++ b/src/utils.c @@ -72,7 +72,7 @@ void print_stats(void) { bool check_for_count(options_t opt) { if (opt.count == -1) return false; - if (tx_count > opt.count) + if (tx_count >= opt.count) return true; return false; }