finish the checker error

This commit is contained in:
Maoake Teriierooiterai
2026-01-09 11:59:44 +01:00
parent 0e5ef61de7
commit 90d45b07ae
12 changed files with 277 additions and 19 deletions

View File

@@ -18,6 +18,8 @@ COMPLEX_DIR = radix
FLAGS_DIR = flags FLAGS_DIR = flags
CHECKER_DIR = checker
INCLUDES = headers INCLUDES = headers
#============================ #============================
@@ -33,6 +35,8 @@ FLAGS_FILES = algorithms_sort.c flag.c bench.c
PARSING = ft_atoi.c parsing.c ft_strncmp.c ft_split.c ft_strlen.c ft_substr.c checker.c ft_itoa.c ft_isdigit.c \ PARSING = ft_atoi.c parsing.c ft_strncmp.c ft_split.c ft_strlen.c ft_substr.c checker.c ft_itoa.c ft_isdigit.c \
ft_strjoin.c ft_strlcat.c ft_strlcpy.c parsing_2.c ft_strjoin.c ft_strlcat.c ft_strlcpy.c parsing_2.c
CHECKER_FILES = check_error.c verif_flag.c verif_is_digit.c verif_overflow.c verif_double.c
STACK_UTILS = push.c rev_rotate.c rotate.c stack_add.c stack_remove.c stacks_len.c swap.c print_stacks.c STACK_UTILS = push.c rev_rotate.c rotate.c stack_add.c stack_remove.c stacks_len.c swap.c print_stacks.c
MEDIUM_ALGO = utils_medium.c utils_struct_tab.c utils_medium_two.c sort_utils.c sort_utils_two.c medium_algo.c MEDIUM_ALGO = utils_medium.c utils_struct_tab.c utils_medium_two.c sort_utils.c sort_utils_two.c medium_algo.c
@@ -48,7 +52,7 @@ ALGO_UTILS = check_order.c compare.c iterate.c pre_sort.c
ALL_FILES = $(SRC) $(STACK_UTILS_DIR)/$(STACK_UTILS) $(PARS_DIR)/$(PARSING) \ ALL_FILES = $(SRC) $(STACK_UTILS_DIR)/$(STACK_UTILS) $(PARS_DIR)/$(PARSING) \
$(ALGO_DIR)/$(MEDIUM_DIR)/$(MEDIUM_ALGO) $(ALGO_UTILS_DIR)/$(ALGO_UTILS) \ $(ALGO_DIR)/$(MEDIUM_DIR)/$(MEDIUM_ALGO) $(ALGO_UTILS_DIR)/$(ALGO_UTILS) \
$(INSERT_DIR)/$(INSERTION) $(ALGO_DIR)/$(COMPLEX_DIR)/$(COMPLEX_ALGO) \ $(INSERT_DIR)/$(INSERTION) $(ALGO_DIR)/$(COMPLEX_DIR)/$(COMPLEX_ALGO) \
$(FLAGS_DIR)/$(FLAGS_FILES) $(FLAGS_DIR)/$(FLAGS_FILES) $(CHECKER_DIR)/$(CHECKER_FILES)
OBJ_DIR = obj OBJ_DIR = obj
@@ -95,6 +99,9 @@ $(OBJ_DIR)/%.o: $(ALGO_UTILS_DIR)/%.c | $(OBJ_DIR)
$(OBJ_DIR)/%.o: $(FLAGS_DIR)/%.c | $(OBJ_DIR) $(OBJ_DIR)/%.o: $(FLAGS_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@ $(CC) $(CFLAGS) -MMD -MP -c $< -o $@
$(OBJ_DIR)/%.o: $(CHECKER_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR) $(OBJ_DIR)/%.o: %.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@ $(CC) $(CFLAGS) -MMD -MP -c $< -o $@

28
checker/check_error.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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"
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);
return (1);
}

47
checker/verif_double.c Normal file
View 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);
}

60
checker/verif_flag.c Normal file
View File

@@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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", 7)
|| ft_strncmp(tab[pos], "--simple", 8)
|| ft_strncmp(tab[pos], "--medium", 8)
|| ft_strncmp(tab[pos], "--complex", 9))
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);
}

41
checker/verif_is_digit.c Normal file
View File

@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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"
static int scan_str_is_digit(char *tab)
{
int i;
i = 0;
while (tab[i])
{
if (!ft_isdigit(tab[i]) && (tab[i] == '-' && !ft_isdigit(tab[i + 1])))
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);
}

51
checker/verif_overflow.c Normal file
View File

@@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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;
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);
}

22
headers/check_error.h Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_error.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/09 10:16:35 by mteriier #+# #+# */
/* Updated: 2026/01/09 10:16:37 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
#ifndef CHECK_ERROR_H
# define CHECK_ERROR_H
int verif_flag(char **tab, int mod);
int check_error(char **tab, int mod);
int verif_is_digit(char **tab, int mod);
int verif_overflow(char **tab, int mod);
int verif_double(char **tab, int mod);
#endif

View File

@@ -17,6 +17,7 @@
# include "push_swap.h" # include "push_swap.h"
int ft_atoi(const char *nptr); int ft_atoi(const char *nptr);
int wich_mod(int mod);
t_stacks *init_stacks(int argc, char **argv, int mod); t_stacks *init_stacks(int argc, char **argv, int mod);
int ft_strncmp(const char *s1, const char *s2, int n); int ft_strncmp(const char *s1, const char *s2, int n);
size_t ft_strlen(const char *s); size_t ft_strlen(const char *s);

View File

@@ -79,7 +79,7 @@ int check_order(t_stack *stack);
void insertion(t_stacks *stacks, int len); void insertion(t_stacks *stacks, int len);
int test2(char **argv); int test2(char **argv);
/* TEST FILE */ /* TEST FILE */
int test1(int argc, char **argv); int test1(char **tab, int len, int mod);
/* RADIX */ /* RADIX */
void radix(t_stacks *stacks); void radix(t_stacks *stacks);

23
main.c
View File

@@ -12,16 +12,25 @@
#include "push_swap.h" #include "push_swap.h"
#include "parsing.h" #include "parsing.h"
#include "check_error.h"
#include "flags.h"
#include <unistd.h> #include <unistd.h>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
// if (!checker(argc, argv)) char **tab;
// { int mod;
// write(2, "Error !\n", 8); int len;
// return (1);
// } tab = split_all(join_all(argc, argv));
if (argc > 1) if (!tab)
test1(argc, argv); return (0);
len = len_split(tab);
mod = calcul_mod(len, tab);
if (check_error(tab, mod))
test1(tab, len, mod);
else
write(2, "Error\n", 7);
free_tab(tab);
return (0); return (0);
} }

View File

@@ -14,7 +14,7 @@
#include "parsing.h" #include "parsing.h"
#include <stdlib.h> #include <stdlib.h>
static int wich_mod(int mod) int wich_mod(int mod)
{ {
if (mod == 0) if (mod == 0)
return (1); return (1);

View File

@@ -16,19 +16,11 @@
#include "medium_headers.h" #include "medium_headers.h"
#include <stdlib.h> #include <stdlib.h>
int test1(int argc, char **argv) int test1(char **tab, int len, int mod)
{ {
t_stacks *stacks; t_stacks *stacks;
int mod;
char **tab;
int len;
stacks = NULL; stacks = NULL;
tab = split_all(join_all(argc, argv));
if (!tab)
return (0);
len = len_split(tab);
mod = calcul_mod(len, tab);
if (mod == -1) if (mod == -1)
return (0); return (0);
stacks = init_stacks(len, tab, mod); stacks = init_stacks(len, tab, mod);