normed out most files still need to split functions accordingly still need to check for hidden norm errors
86 lines
2.1 KiB
C
86 lines
2.1 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ps_stktools2.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/02/25 12:44:08 by tmaze #+# #+# */
|
|
/* Updated: 2019/03/15 15:36:06 by tmaze ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "push_swap.h"
|
|
|
|
void ps_initdata(t_psdata *data)
|
|
{
|
|
data->a = NULL;
|
|
data->b = NULL;
|
|
data->size_a = 0;
|
|
data->size_b = 0;
|
|
data->op = NULL;
|
|
data->viz = '\0';
|
|
}
|
|
|
|
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) && ft_atois(in, ret))
|
|
return (1);
|
|
return (0);
|
|
}
|
|
|
|
int get_params(t_psdata *data, int ac, char **av, int viz)
|
|
{
|
|
t_stack *new;
|
|
int nb;
|
|
int i;
|
|
|
|
i = ac;
|
|
nb = 0;
|
|
while (--i > 0)
|
|
{
|
|
if (i == 1 && viz && ft_strcmp(av[i], "-v") == 0)
|
|
data->viz = 'a';
|
|
else if (check_input(av[i], &nb) && (new = ps_stknew(nb)) != NULL)
|
|
{
|
|
new->ind = 0;
|
|
ps_stkpsh(data, 'a', new);
|
|
}
|
|
else
|
|
{
|
|
ft_putendl_fd("Error", 2);
|
|
ps_stkclean(data);
|
|
return (0);
|
|
}
|
|
}
|
|
return (1);
|
|
}
|
|
|
|
int is_op(char *buff)
|
|
{
|
|
static char ops[11][4] = {"sa\0", "sb\0", "ss\0", "pa\0", "pb\0", "ra\0",
|
|
"rb\0", "rr\0", "rra\0", "rrb\0", "rrr\0"};
|
|
size_t i;
|
|
|
|
i = 0;
|
|
while (i < 11 && ft_strcmp(buff, ops[i]) != 0)
|
|
i++;
|
|
return (i < 11);
|
|
}
|
|
|
|
t_list *add_op(t_psdata *data, char *op)
|
|
{
|
|
t_list *new;
|
|
|
|
if ((new = ft_lstnew(op, 4)) != NULL)
|
|
ft_lstaddend(&(data->op), new);
|
|
return (new);
|
|
}
|