From 2ecc64f7781c0351b8a4ccac2ef7140c7261e43f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Mon, 22 Apr 2024 11:11:20 +0200 Subject: [PATCH] Message --- includes/push_swap.h | 3 ++- libft/ft_strlen.c | 15 ++++++++++++++- sources/validation.c | 35 +++++++++++++++++++---------------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/includes/push_swap.h b/includes/push_swap.h index 4ea800c..b12e3d3 100755 --- a/includes/push_swap.h +++ b/includes/push_swap.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 11:11:07 by rparodi #+# #+# */ -/* Updated: 2024/04/18 14:51:13 by rparodi ### ########.fr */ +/* Updated: 2024/04/22 10:28:15 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,6 +60,7 @@ void simple_sort(t_list **stack_a, t_list **stack_b); void radix_sort(t_list **stack_a, t_list **stack_b); size_t ft_strlcpy(char *dst, const char *src, size_t size); size_t ft_len(const char *str); +size_t chk_len(const char *str); t_list *ft_lstnew(int content); t_list *ft_lstlast(t_list *head); diff --git a/libft/ft_strlen.c b/libft/ft_strlen.c index ce79ec8..99eb729 100644 --- a/libft/ft_strlen.c +++ b/libft/ft_strlen.c @@ -6,12 +6,25 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/07 16:56:24 by rparodi #+# #+# */ -/* Updated: 2024/04/17 19:42:58 by rparodi ### ########.fr */ +/* Updated: 2024/04/22 10:35:54 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/push_swap.h" +size_t chk_len(const char *str) +{ + size_t i; + + if (str[0] == '-') + i = 1; + else + i = 0; + while (str[i] != '\0' && (str[i] == '0')) + i++; + return (ft_len(str + i)); +} + size_t ft_len(const char *s) { size_t i; diff --git a/sources/validation.c b/sources/validation.c index c2b5338..4712fd7 100755 --- a/sources/validation.c +++ b/sources/validation.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/13 12:08:16 by rparodi #+# #+# */ -/* Updated: 2024/04/18 15:20:44 by rparodi ### ########.fr */ +/* Updated: 2024/04/22 11:02:15 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,9 +42,24 @@ static int ft_isnum(char *num) return (1); } +void ft_stack_utils(int i, long tmp, char **args) +{ + while (args[i] != NULL) + { + tmp = ft_atoi(args[i]); + if (!ft_isnum(args[i]) || *args[i] == '\0') + error_message("not number stack", NULL, NULL, NULL); + if (ft_contains(tmp, args, i) == 1 || (chk_len(args[i]) > 11)) + error_message("overflow stack", NULL, NULL, NULL); + if (tmp < -2147483648 || tmp > 2147483647) + error_message("over int stack", NULL, NULL, NULL); + i++; + } +} + void ft_check_args_utils(int i, char **args) { - long tmp; + long tmp; tmp = 0; if (i == 0) @@ -54,7 +69,7 @@ void ft_check_args_utils(int i, char **args) tmp = ft_atoi(args[i]); if (!ft_isnum(args[i]) || *args[i] == '\0') error_message("not number heap", NULL, NULL, args); - if (ft_contains(tmp, args, i) == 1 || (ft_len(args[i]) > 11)) + if (ft_contains(tmp, args, i) == 1 || (chk_len(args[i]) > 11)) error_message("overflow heap", NULL, NULL, args); if (tmp < -2147483648 || tmp > 2147483647) error_message("over int heap", NULL, NULL, args); @@ -63,19 +78,7 @@ void ft_check_args_utils(int i, char **args) free_string(args); } else - { - while (args[i] != NULL) - { - tmp = ft_atoi(args[i]); - if (!ft_isnum(args[i]) || *args[i] == '\0') - error_message("not number stack", NULL, NULL, NULL); - if (ft_contains(tmp, args, i) == 1 || (ft_len(args[i]) > 11)) - error_message("overflow stack", NULL, NULL, NULL); - if (tmp < -2147483648 || tmp > 2147483647) - error_message("over int stack", NULL, NULL, NULL); - i++; - } - } + ft_stack_utils(i, tmp, args); } void check_args(char **argv)