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
This commit is contained in:
Tanguy MAZE
2019-02-25 17:42:47 +01:00
parent 62764dc5e7
commit 7a2037c046
6 changed files with 64 additions and 55 deletions

View File

@@ -6,48 +6,21 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/23 13:35:15 by tmaze #+# #+# */
/* Updated: 2019/02/24 15:38:10 by tmaze ### ########.fr */
/* Updated: 2019/02/25 17:04:05 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int ft_issign(char c)
{
return (c == '+' || c == '-');
}
int ft_iswhitespace(char c)
{
return (c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f'
|| c == '\r');
}
int ft_hasdigit(char *s)
{
int i;
i = 0;
while (s[i] && !ft_isdigit(s[i]))
i++;
return (ft_isdigit(s[i]));
}
int check_input(char *in, int *ret)
{
int i;
i = 0;
while (in[i] && ft_iswhitespace(in[i]))
i++;
if (in[i] && ft_issign(in[i]))
i++;
while (in[i] && ft_iswhitespace(in[i]))
i++;
while (in[i] && ft_isdigit(in[i]))
i++;
while (in[i] && ft_iswhitespace(in[i]))
i++;
if (in[i] == '\0' && ft_hasdigit(in))
*ret = ft_atoi(in);
return (in[i] == '\0' && ft_hasdigit(in));
@@ -59,18 +32,40 @@ int main(int ac, char **av)
int nb;
t_stack *new;
t_psdata data;
char **tab;
int j;
i = ac;
nb = 0;
ps_initdata(&data);
while (--i > 0)
{
if (check_input(av[i], &nb) && (new = ps_stknew(nb)) != NULL)
ps_stkpsh(&data, 'a', new);
else
if ((tab = ft_strsplitwhitespace(av[i])) != NULL && !(j = 0))
{
ft_putendl_fd("Error", 2);
ps_stkclean(&data);
return (2);
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);
}