Zappy - Year end project 2
This is a project that Epitech asked us to create in order to allow us to reveiw the notions of the current year.
Loading...
Searching...
No Matches
parameter_utils.c
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2023
3** my_zappy
4** File description:
5** check_arg_has_value.c
6*/
7
8#include <string.h>
9
10#include "arg_parse.h"
11
12int is_param(const char *str, const struct option_list_s *opt_list)
13{
14 for (int i = 0; i < NB_PARAM; ++i) {
15 if (strcmp(str, opt_list[i].option.name) == 0) {
16 return (i);
17 }
18 }
19 return (-1);
20}
21
22static int is_str_option(const char *str, int *nb_param)
23{
24 int tmp;
25
26 if (str[0] == '-') {
27 tmp = is_param(str, SERVER_OPTION);
28 if (tmp != -1)
29 ++(*nb_param);
30 else
31 return (-1);
32 } else {
33 return (1);
34 }
35 return (0);
36}
37
38int get_nb_parameter(int ac, const char **av)
39{
40 int nb_param = 0;
41
42 for (int i = 1; i < ac - 1; ++i) {
43 if (is_str_option(av[i], &nb_param) == -1)
44 return (-1);
45 }
46 return (nb_param);
47}
#define NB_PARAM
! PARSING CONSTANTS !!
Definition constants.h:20
int get_nb_parameter(int ac, const char **av)
Get the number of parameter passed to the program.
int is_param(const char *str, const struct option_list_s *opt_list)
Check if a string is a parameter.