13static void get_multiple_value(
const char **av,
int idx,
struct arg_s *arg)
18 while (av[idx + i][0] !=
'-') {
23 if (arg->
value == NULL)
26 for (
size_t j = 0; j < arg->
nb_value; ++j) {
27 tmp[j] = strdup(av[idx + 1 + j]);
35static int param_has_mul_val(
int idx,
struct arg_s *arg,
const char **av,
38 if (strcmp(av[idx], param->
name) == 0) {
40 get_multiple_value(av, idx, arg);
43 arg->
value = strdup(av[idx + 1]);
53 (*arg) = malloc(
sizeof(
struct arg_s) * 1);
56 (*arg)->name = strdup(param->
name);
58 if ((*arg)->name == NULL) {
62 for (
int i = 0; i < ac; ++i) {
63 if (param_has_mul_val(i, *arg, av, param) == 0)
71static int *get_set_param(
int ac,
const char **av,
int nb_param)
74 int *param = malloc(
sizeof(
int) * nb_param);
79 for (
int i = 1; i < ac - 1 && count < nb_param; ++i) {
80 tmp =
is_param(av[i], SERVER_OPTION);
93 int *to_get = get_set_param(ac, av, nb_param);
94 struct arg_s **args = malloc(
sizeof(
struct arg_s *) * (nb_param + 1));
101 for (
int i = 0; i < nb_param; ++i) {
102 if (
get_arg_value(ac, av, &opt_l[to_get[i]].option, &args[i]) == -1) {
110 args[nb_param] = NULL;
int get_arg_value(int ac, const char **av, const struct option_s *param, struct arg_s **arg)
Get the variables of a parameter and store it in arg_s structure.
struct arg_s ** get_zappy_args(int ac, const char **av, const struct option_list_s *opt_l)
The principal function to get every arguments.
int get_nb_parameter(int ac, const char **av)
Get the number of parameter passed to the program.
int check_mandatory_set(int ac, const char **av, int nb_param, const struct option_list_s *opt_list)
Check if there's every mandatory options in the arguments passed to the program.
int is_param(const char *str, const struct option_list_s *opt_list)
Check if a string is a parameter.
void free_args(struct arg_s **args, const size_t size)
Free struct args_s of lenght size.
int write_error_msg(const char *str)
! WRITTER !!