mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 00:41:57 +00:00
finish the bonus just need to verify some files i guess
This commit is contained in:
50
check_error/check_error.c
Normal file
50
check_error/check_error.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_error.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/01/09 09:31:50 by mteriier #+# #+# */
|
||||
/* Updated: 2026/01/09 09:31:51 by mteriier ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "check_error.h"
|
||||
#include "parsing.h"
|
||||
|
||||
int verif_is_number(char **tab)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = len_split(tab);
|
||||
if (tab[len - 1][0] == '-' && !ft_isdigit(tab[len - 1][1]))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int check_error_bonus(char **tab)
|
||||
{
|
||||
if (!verif_is_digit(tab, 0))
|
||||
return (0);
|
||||
if (!verif_overflow(tab, 0))
|
||||
return (0);
|
||||
if (!verif_double(tab, 0))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int check_error(char **tab, int mod)
|
||||
{
|
||||
if (!verif_flag(tab, mod))
|
||||
return (0);
|
||||
if (!verif_is_digit(tab, mod))
|
||||
return (0);
|
||||
if (!verif_overflow(tab, mod))
|
||||
return (0);
|
||||
if (!verif_double(tab, mod))
|
||||
return (0);
|
||||
if (!verif_is_number(tab))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
47
check_error/verif_double.c
Normal file
47
check_error/verif_double.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* verif_double.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/01/09 10:41:42 by mteriier #+# #+# */
|
||||
/* Updated: 2026/01/09 10:41:43 by mteriier ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
#include "check_error.h"
|
||||
|
||||
static int is_double_in_tab(char **tab, int nb, int pos)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = pos;
|
||||
while (tab[i])
|
||||
{
|
||||
if (nb == ft_atoi(tab[i]))
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int verif_double(char **tab, int mod)
|
||||
{
|
||||
int i;
|
||||
int tmp;
|
||||
|
||||
i = wich_mod(mod);
|
||||
while (tab[i])
|
||||
{
|
||||
if (tab[i + 1])
|
||||
{
|
||||
tmp = ft_atoi(tab[i]);
|
||||
if (!is_double_in_tab(tab, tmp, i + 1))
|
||||
return (0);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
61
check_error/verif_flag.c
Normal file
61
check_error/verif_flag.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* verif_flag.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/01/09 09:51:11 by mteriier #+# #+# */
|
||||
/* Updated: 2026/01/09 09:51:12 by mteriier ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
|
||||
static int is_exist_flag(char **tab, int pos)
|
||||
{
|
||||
int verif;
|
||||
|
||||
verif = 0;
|
||||
if (ft_strncmp(tab[pos], "--bench", 30)
|
||||
|| ft_strncmp(tab[pos], "--simple", 30)
|
||||
|| ft_strncmp(tab[pos], "--medium", 30)
|
||||
|| ft_strncmp(tab[pos], "--adaptive", 30)
|
||||
|| ft_strncmp(tab[pos], "--complex", 30))
|
||||
verif = 1;
|
||||
return (verif);
|
||||
}
|
||||
|
||||
static int verif_exist_flag(char **tab, int mod)
|
||||
{
|
||||
int verif;
|
||||
|
||||
verif = 0;
|
||||
if (mod == 1)
|
||||
verif = (is_exist_flag(tab, 1));
|
||||
else if (mod == 2)
|
||||
{
|
||||
if (is_exist_flag(tab, 1) && is_exist_flag(tab, 2))
|
||||
verif = 1;
|
||||
}
|
||||
return (verif);
|
||||
}
|
||||
|
||||
static int verif_double_flag(char **tab, int mod)
|
||||
{
|
||||
int verif;
|
||||
|
||||
verif = 1;
|
||||
if (mod == 2 && ft_strncmp(tab[1], tab[2], 9))
|
||||
verif = 0;
|
||||
return (verif);
|
||||
}
|
||||
|
||||
int verif_flag(char **tab, int mod)
|
||||
{
|
||||
if (mod == 0)
|
||||
return (1);
|
||||
if (verif_double_flag(tab, mod) && verif_exist_flag(tab, mod))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
44
check_error/verif_is_digit.c
Normal file
44
check_error/verif_is_digit.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* verif_is_digit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/01/09 10:25:23 by mteriier #+# #+# */
|
||||
/* Updated: 2026/01/09 10:25:24 by mteriier ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
|
||||
int scan_str_is_digit(char *tab)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (tab[i])
|
||||
{
|
||||
if ((tab[i] == '+' || tab[i] == '-') && ft_isdigit(tab[i + 1])
|
||||
&& tab[i + 1])
|
||||
i++;
|
||||
if (!ft_isdigit(tab[i]))
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int verif_is_digit(char **tab, int mod)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = wich_mod(mod);
|
||||
while (tab[i])
|
||||
{
|
||||
if (!scan_str_is_digit(tab[i]))
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
53
check_error/verif_overflow.c
Normal file
53
check_error/verif_overflow.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* verif_overflow.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/01/09 10:30:39 by mteriier #+# #+# */
|
||||
/* Updated: 2026/01/09 10:30:40 by mteriier ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
|
||||
static int verif_atoi(const char *nptr)
|
||||
{
|
||||
size_t i;
|
||||
int tmp;
|
||||
int before;
|
||||
|
||||
i = 0;
|
||||
tmp = 0;
|
||||
before = 0;
|
||||
if (ft_strncmp(nptr, "-2147483648", 15))
|
||||
return (1);
|
||||
while ((nptr[i] >= 9 && nptr[i] <= 13) || nptr[i] == ' ')
|
||||
i++;
|
||||
if (nptr[i] == '-' || nptr[i] == '+')
|
||||
i++;
|
||||
while (nptr[i] >= '0' && nptr[i] <= '9')
|
||||
{
|
||||
before = tmp;
|
||||
tmp = tmp * 10 + nptr[i] - '0';
|
||||
if (before > tmp)
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int verif_overflow(char **tab, int mod)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = wich_mod(mod);
|
||||
while (tab[i])
|
||||
{
|
||||
if (!verif_atoi(tab[i]))
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
Reference in New Issue
Block a user