Push the final version
This commit is contained in:
commit
d0fe1fb2fb
28 changed files with 1459 additions and 0 deletions
97
sources/validation.c
Executable file
97
sources/validation.c
Executable file
|
|
@ -0,0 +1,97 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* validation.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/push_swap.h"
|
||||
|
||||
static int ft_contains(int num, char **argv, int i)
|
||||
{
|
||||
i++;
|
||||
while (argv[i])
|
||||
{
|
||||
if (ft_atoi(argv[i]) == num)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int ft_isnum(char *num)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (num[0] == '-' || num[0] == '+')
|
||||
i++;
|
||||
if ((num[0] == '-' || num[0] == '+') && !num[1])
|
||||
return (0);
|
||||
while (num[i])
|
||||
{
|
||||
if (!ft_isdigit(num[i]))
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
void ft_check_args_utils(int i, char **args)
|
||||
{
|
||||
long tmp;
|
||||
|
||||
tmp = 0;
|
||||
if (i == 0)
|
||||
{
|
||||
while (args[i] != NULL)
|
||||
{
|
||||
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))
|
||||
error_message("overflow heap", NULL, NULL, args);
|
||||
if (tmp < -2147483648 || tmp > 2147483647)
|
||||
error_message("over int heap", NULL, NULL, args);
|
||||
i++;
|
||||
}
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void check_args(char **argv)
|
||||
{
|
||||
int i;
|
||||
char **args;
|
||||
|
||||
if (argv[2] == NULL)
|
||||
{
|
||||
args = ft_split(argv[1]);
|
||||
i = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
args = argv;
|
||||
i = 1;
|
||||
}
|
||||
ft_check_args_utils(i, args);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue