gestion erreurs et leaks en cours de debug
This commit is contained in:
14
srcs/algo.c
14
srcs/algo.c
@@ -102,7 +102,7 @@ void send_sublist_to_a(t_stack **a, t_stack **b, t_list *solution)
|
||||
mark_step(solution, "send_sublist_to_a");
|
||||
}
|
||||
|
||||
void recursif_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
void hugo_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
{
|
||||
if (sublist_size(*a) > 4)
|
||||
divide_a(a, b, solution);
|
||||
@@ -119,16 +119,6 @@ void recursif_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
else
|
||||
return ;
|
||||
}
|
||||
recursif_sort(a, b, solution);
|
||||
}
|
||||
|
||||
void hugo_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
{
|
||||
if (sublist_size(*a) <= 3)
|
||||
special_sort_3(a, solution);
|
||||
else if (sublist_size(*a) <= 5)
|
||||
special_sort_5(a, b, solution);
|
||||
else
|
||||
recursif_sort(a, b, solution);
|
||||
hugo_sort(a, b, solution);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
void is_valid(int ac, char **av)
|
||||
{
|
||||
if (ac < 2)
|
||||
ps_stop(NULL, NULL, 1);
|
||||
ps_stop(NULL, 1);
|
||||
(void)av;
|
||||
}
|
||||
|
||||
@@ -28,14 +28,23 @@ int check_flag(int *ac, char ***av)
|
||||
t_stack *fill_stack(t_stack *list, char *nb)
|
||||
{
|
||||
t_stack *new;
|
||||
long nbl;
|
||||
|
||||
new = ft_calloc(1, sizeof(t_stack));
|
||||
if (!new)
|
||||
ps_stop(NULL, NULL, 2);
|
||||
new->n = ft_atoi(nb);
|
||||
ps_stop((t_list *)list, 2);
|
||||
|
||||
/*
|
||||
if (ft_isnumber(nb) == 0)
|
||||
ps_stop((t_list *)list, 2);
|
||||
nbl = ft_atol(nb);
|
||||
if (nbl < INT_MIN || nbl > INT_MAX)
|
||||
ps_stop((t_list *)list, 2);
|
||||
new->n = nbl;
|
||||
new->limit = 0;
|
||||
new->next = list;
|
||||
list = new;
|
||||
*/
|
||||
return (list);
|
||||
}
|
||||
|
||||
@@ -76,8 +85,13 @@ t_list *launch_algo(t_stack **a, t_stack **b, int flag)
|
||||
fill_solution(solution, "start");
|
||||
mark_step(solution, "start");
|
||||
}
|
||||
hugo_sort(a, b, solution);
|
||||
// bubble_sort(a, b, solution);
|
||||
if (sublist_size(*a) <= 3)
|
||||
special_sort_3(a, solution);
|
||||
else if (sublist_size(*a) <= 5)
|
||||
special_sort_5(a, b, solution);
|
||||
else
|
||||
hugo_sort(a, b, solution);
|
||||
// bubble_sort_luke(a, b, solution);
|
||||
return (solution);
|
||||
}
|
||||
|
||||
@@ -94,6 +108,6 @@ int main(int ac, char **av)
|
||||
b = NULL;
|
||||
solution = launch_algo(&a, &b, flag);
|
||||
print_result(solution, flag);
|
||||
ps_stop(NULL, solution, 0);
|
||||
ps_stop(solution, 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
27
srcs/stop.c
27
srcs/stop.c
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user