gestion erreur parsing

This commit is contained in:
Hugo LAMY
2022-01-26 18:01:39 +01:00
parent eec1a73786
commit 232684b73a
3 changed files with 91 additions and 18 deletions

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/26 15:30:34 by hulamy #+# #+# */
/* Updated: 2022/01/26 16:29:38 by hulamy ### ########.fr */
/* Updated: 2022/01/26 17:55:34 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -57,22 +57,29 @@ static t_philo *init_chain_philo(t_params *params, t_global *global)
static t_params *init_params(int ac, char **av)
{
t_params *params;
int i;
if (ac == 5 || ac == 6)
{
params = malloc(sizeof(t_params));
if (!params)
return (NULL);
params->n_phi = ft_atoi(av[1]);
params->t_die = ft_atoi(av[2]);
params->t_eat = ft_atoi(av[3]);
params->t_slp = ft_atoi(av[4]);
params->n_eat = -1;
if (ac == 6)
params->n_eat = ft_atoi(av[5]);
}
else
if (ac < 5 || ac > 6)
return (NULL);
if (!ft_isdigit_2d_arr(av + 1))
return (NULL);
i = 0;
while (av[i])
{
if (ft_int_overflow(av[i]))
return (NULL);
i++;
}
params = malloc(sizeof(t_params));
if (!params)
return (NULL);
params->n_phi = ft_atoi(av[1]);
params->t_die = ft_atoi(av[2]);
params->t_eat = ft_atoi(av[3]);
params->t_slp = ft_atoi(av[4]);
params->n_eat = -1;
if (ac == 6)
params->n_eat = ft_atoi(av[5]);
return (params);
}