From ac8e8638e944c342ba509d9593fdf6e6223db38c Mon Sep 17 00:00:00 2001 From: adjoly Date: Sat, 16 Aug 2025 19:18:09 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20fixed?= =?UTF-8?q?=20issue=20with=20parsing=20not=20working=20properly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/help.h | 2 +- src/parsing/opt_parse.c | 28 +++++++++++++++++++++++----- src/utils.c | 2 +- 3 files changed, 25 insertions(+), 7 deletions(-) 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; }