gestion erreurs et leaks en cours de debug

This commit is contained in:
hugogogo
2021-09-27 11:12:48 +02:00
parent 6a93eda973
commit 7f8d114b99
19 changed files with 49 additions and 46 deletions

View File

@@ -1,28 +1,27 @@
#include "push_swap.h"
void ps_usage(void)
{
ft_printf("usage :\n");
ft_printf("launch executable : ./push_swap [flag -p] nb nb nb nb nb ...\n");
}
void ps_error(int err)
{
if (err == 1)
ps_usage();
ft_printf("usage :\nlaunch executable : ./push_swap [flag -p] nb nb nb nb nb ...\n");
if (err == 2)
ft_printf("error\n");
ft_putstr_fd("Error\n", 2);
exit(0);
}
void ps_stop(t_stack *stack, t_list *lst, int err)
/*
** if err < 0, the parameter list is just a t_stack *list
** if err = 0, the list are freed but the program doesn't stop
** if err > 0, a message is printed and the program stop
*/
void ps_stop(t_list *lst, int err)
{
t_stack **a;
t_stack **b;
if (stack)
ft_lstclear((t_list **)&stack, NULL);
if (lst)
if (err < 0)
ft_lstclear(&lst, NULL);
else if (lst)
{
a = lst->content;
b = lst->next->content;
@@ -32,8 +31,6 @@ void ps_stop(t_stack *stack, t_list *lst, int err)
lst->next->content = NULL;
ft_lstclear(&lst, free);
}
if (err < 0)
return ;
else if (err > 0)
if (err > 0)
ps_error(err);
}