only gets better B)
ditched GNL for ft_getline in checker norm cleanup
This commit is contained in:
61
srcs/ps_clean.c
Normal file
61
srcs/ps_clean.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ps_clean.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/16 13:14:52 by tmaze #+# #+# */
|
||||
/* Updated: 2019/03/16 13:29:57 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
static void clean_push(t_psdata *data, t_list ***prec, t_list **it)
|
||||
{
|
||||
**prec = (*it)->next->next;
|
||||
ft_memdel(&((*it)->next->content));
|
||||
ft_memdel((void**)(&((*it)->next)));
|
||||
ft_memdel(&((*it)->content));
|
||||
ft_memdel((void**)it);
|
||||
*it = data->op;
|
||||
*prec = &(data->op);
|
||||
}
|
||||
|
||||
static void clean_swap(t_psdata *data, t_list ***prec, t_list **it)
|
||||
{
|
||||
**prec = (*it)->next;
|
||||
ft_strcpy((char*)((*it)->next->next->content), "sa");
|
||||
ft_memdel(&((*it)->content));
|
||||
ft_memdel((void**)it);
|
||||
*it = data->op;
|
||||
*prec = &(data->op);
|
||||
}
|
||||
|
||||
void clean_op(t_psdata *data)
|
||||
{
|
||||
t_list *it;
|
||||
t_list **prec;
|
||||
|
||||
it = data->op;
|
||||
prec = &(data->op);
|
||||
while (it && it->next)
|
||||
{
|
||||
if (((char*)(it->content))[0] == 'p'
|
||||
&& ((char*)(it->next->content))[0] == 'p'
|
||||
&& ((char*)(it->content))[1] != ((char*)(it->next->content))[1])
|
||||
clean_push(data, &prec, &it);
|
||||
else if (it->next->next && ((char*)(it->content))[0] == 'p'
|
||||
&& ((char*)(it->content))[1] == 'b'
|
||||
&& ((char*)(it->next->next->content))[0] == 'p'
|
||||
&& ((char*)(it->next->next->content))[1] == 'a'
|
||||
&& ft_strcmp((char*)(it->next->content), "rra") == 0)
|
||||
clean_swap(data, &prec, &it);
|
||||
else
|
||||
{
|
||||
prec = &(it->next);
|
||||
it = it->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user