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
arg_parse.h
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2023
3** my_zappy
4** File description:
5** arg_parse.h
6*/
7
8#ifndef ZAPPY_ARG_PARSE_H
9 #define ZAPPY_ARG_PARSE_H
10
11 #include <stdlib.h>
12 #include <stdbool.h>
13
14 #include "constants.h"
15
16struct arg_s {
17 char *name;
18 size_t nb_value;
19 void *value;
20};
21
22struct option_s {
23 char *name;
24 bool has_arg;
26 char *help;
29};
30
33};
34
35static const struct option_list_s SERVER_OPTION[NB_PARAM] = {
36 { {"-p", true, false, "port number", true, NULL } },
37 { {"-x", true, false, "width of the world", true, NULL } },
38 { {"-y", true, false, "height of the world", true, NULL} },
39 { {"-n", true, true, "name of the team", true, NULL} },
40 { {"-c", true, false, CLIENTS_NB_PARAM, true, NULL} },
41 { {"-f", true, false, FREQUENCE_PARAM, false, (void *) 100} },
42};
43
49int get_nb_mandatory_option(const struct option_list_s *opt_list);
50
60int check_mandatory_set(int ac, const char **av, int nb_param,
61 const struct option_list_s *opt_list);
62
69int is_param(const char *str, const struct option_list_s *opt_list);
70
77int get_nb_parameter(int ac, const char **av);
78
88int get_arg_value(int ac, const char **av,
89 const struct option_s *param, struct arg_s **arg);
90
99struct arg_s **get_zappy_args(int ac, const char **av,
100 const struct option_list_s *opt_l);
101
109int check_values_validity(const struct arg_s **arguments, const size_t size);
110
111#endif //ZAPPY_ARG_PARSE_H
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 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.
Definition arg_parse.c:50
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.
Definition arg_parse.c:89
int is_param(const char *str, const struct option_list_s *opt_list)
Check if a string is a parameter.
int check_values_validity(const struct arg_s **arguments, const size_t size)
Check if the values of the parameters are correct.
int get_nb_mandatory_option(const struct option_list_s *opt_list)
Get the number of mandatory options needed for the server.
#define CLIENTS_NB_PARAM
Definition constants.h:21
#define FREQUENCE_PARAM
Definition constants.h:22
#define NB_PARAM
! PARSING CONSTANTS !!
Definition constants.h:20
char * name
Definition arg_parse.h:17
void * value
Definition arg_parse.h:19
size_t nb_value
Definition arg_parse.h:18
struct option_s option
Definition arg_parse.h:32
bool has_multiple_arg
Definition arg_parse.h:25
char * name
Definition arg_parse.h:23
bool mandatory
Definition arg_parse.h:27
bool has_arg
Definition arg_parse.h:24
char * help
Definition arg_parse.h:26
void * default_value
Definition arg_parse.h:28