「🔨」 fix: fixed issue with parsing not working properly
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
struct options{
|
struct options {
|
||||||
char *name;
|
char *name;
|
||||||
char opt;
|
char opt;
|
||||||
char *doc;
|
char *doc;
|
||||||
|
@ -7,14 +7,29 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
|
|
||||||
int handle_long_args(char **av, args_t *args) {
|
int handle_long_args(char ***av, args_t *args) {
|
||||||
OPT_WHILE {
|
OPT_WHILE {
|
||||||
if (strncmp((*av) + 2, options[i].name, strlen(options[i].name)) == 0) {
|
if (strncmp((**av) + 2, options[i].name, strlen(options[i].name)) ==
|
||||||
OPT_HANDLE(i);
|
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++;
|
i++;
|
||||||
}
|
}
|
||||||
print_parse_err(INVALID_OPT, (*av) + 2);
|
print_parse_err(INVALID_OPT, (**av) + 2);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +44,7 @@ int opt_parse(char **av, args_t *args) {
|
|||||||
print_parse_err(MISSING_HOST, 0);
|
print_parse_err(MISSING_HOST, 0);
|
||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
} else if (opt == '-') {
|
} else if (opt == '-') {
|
||||||
int ret = handle_long_args(av, args);
|
int ret = handle_long_args(&av, args);
|
||||||
if (ret != EXIT_SUCCESS) {
|
if (ret != EXIT_SUCCESS) {
|
||||||
if (ret == EX_USAGE)
|
if (ret == EX_USAGE)
|
||||||
print_parse_err(NEED_ARG, (*av) + 2);
|
print_parse_err(NEED_ARG, (*av) + 2);
|
||||||
@ -39,6 +54,9 @@ 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)
|
||||||
|
if (options[i].arg_nb == 1) {
|
||||||
|
av++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ void print_stats(void) {
|
|||||||
bool check_for_count(options_t opt) {
|
bool check_for_count(options_t opt) {
|
||||||
if (opt.count == -1)
|
if (opt.count == -1)
|
||||||
return false;
|
return false;
|
||||||
if (tx_count > opt.count)
|
if (tx_count >= opt.count)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user