push_swap/srcs/checker.c
Tanguy MAZE 7a2037c046 i hate mondays
rework of checker parser to accomodate for string arguments
update of libft
debuged push & pop functions
still need to check for overflow arg
2019-02-25 17:42:47 +01:00

72 lines
1.8 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/23 13:35:15 by tmaze #+# #+# */
/* Updated: 2019/02/25 17:04:05 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int check_input(char *in, int *ret)
{
int i;
i = 0;
if (in[i] && ft_issign(in[i]))
i++;
while (in[i] && ft_isdigit(in[i]))
i++;
if (in[i] == '\0' && ft_hasdigit(in))
*ret = ft_atoi(in);
return (in[i] == '\0' && ft_hasdigit(in));
}
int main(int ac, char **av)
{
int i;
int nb;
t_stack *new;
t_psdata data;
char **tab;
int j;
i = ac;
nb = 0;
ps_initdata(&data);
while (--i > 0)
{
if ((tab = ft_strsplitwhitespace(av[i])) != NULL && !(j = 0))
{
while (tab[j])
j++;
while (--j >= 0)
{
if (check_input(tab[j], &nb) && (new = ps_stknew(nb)) != NULL)
ps_stkpsh(&data, 'a', new);
else
{
ft_putendl_fd("Error", 2);
ps_stkclean(&data);
return (2);
}
}
ft_del_words_tables(&tab);
}
}
new = data.a;
if (new == NULL)
ft_putendl("Empty");
while (new != NULL)
{
ft_putnbr(new->nb);
ft_putchar('\n');
new = new->next;
}
ps_stkclean(&data);
}