This commit is contained in:
Raphaël 2024-04-22 11:11:20 +02:00
parent d0fe1fb2fb
commit 2ecc64f778
3 changed files with 35 additions and 18 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View file

@ -6,12 +6,25 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)