gestion erreurs et leaks en cours de debug
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+15
-13
@@ -5,6 +5,8 @@
|
||||
# include <unistd.h> // read(), write(), sleep()
|
||||
# include <stdlib.h> // malloc(), free(), exit(), atoi()
|
||||
|
||||
# define INT_MAX 2147483647
|
||||
# define INT_MIN -2147483648
|
||||
|
||||
typedef struct s_stack
|
||||
{
|
||||
@@ -32,7 +34,7 @@ t_list *launch_algo(t_stack **a, t_stack **b, int i);
|
||||
void print_test(t_list *lst, char *s);
|
||||
void ps_usage(void);
|
||||
void ps_error(int i);
|
||||
void ps_stop(t_stack *stack, t_list *lst, int i);
|
||||
void ps_stop(t_list *lst, int i);
|
||||
|
||||
/*
|
||||
** algo.c // sort.c
|
||||
@@ -42,7 +44,7 @@ int find_pivot(t_stack *list, int size);
|
||||
int divide_a(t_stack **a, t_stack **b, t_list *solution);
|
||||
int divide_b(t_stack **a, t_stack **b, t_list *solution);
|
||||
void send_sublist_to_a(t_stack **a, t_stack **b, t_list *solution);
|
||||
void hugo_sort(t_stack **a, t_stack **b, t_list *lst);
|
||||
void hugo_sort(t_stack **a, t_stack **b, t_list *solution);
|
||||
|
||||
/*
|
||||
** sort_recursif.c
|
||||
@@ -95,28 +97,28 @@ void print_result(t_list *lst, int i);
|
||||
/*
|
||||
** swap
|
||||
*/
|
||||
t_list *sa(t_stack **a, t_list **lst);
|
||||
t_list *sb(t_stack **b, t_list **lst);
|
||||
t_list *ss(t_stack **a, t_stack **b, t_list **lst);
|
||||
t_list *sa(t_stack **a, t_list **solution);
|
||||
t_list *sb(t_stack **b, t_list **solution);
|
||||
t_list *ss(t_stack **a, t_stack **b, t_list **solution);
|
||||
|
||||
/*
|
||||
** push
|
||||
*/
|
||||
t_list *pa(t_stack **dst, t_stack **src, t_list **lst);
|
||||
t_list *pb(t_stack **dst, t_stack **src, t_list **lst);
|
||||
t_list *pa(t_stack **a, t_stack **b, t_list **solution);
|
||||
t_list *pb(t_stack **b, t_stack **a, t_list **solution);
|
||||
|
||||
/*
|
||||
** rotate
|
||||
*/
|
||||
t_list *ra(t_stack **stack, t_list **lst);
|
||||
t_list *rb(t_stack **stack, t_list **lst);
|
||||
t_list *rr(t_stack **a, t_stack **b, t_list **lst);
|
||||
t_list *ra(t_stack **a, t_list **solution);
|
||||
t_list *rb(t_stack **b, t_list **solution);
|
||||
t_list *rr(t_stack **a, t_stack **b, t_list **solution);
|
||||
|
||||
/*
|
||||
** reverse rotate
|
||||
*/
|
||||
t_list *rra(t_stack **stack, t_list **lst);
|
||||
t_list *rrb(t_stack **stack, t_list **lst);
|
||||
t_list *rrr(t_stack **a, t_stack **b, t_list **lst);
|
||||
t_list *rra(t_stack **a, t_list **solution);
|
||||
t_list *rrb(t_stack **b, t_list **solution);
|
||||
t_list *rrr(t_stack **a, t_stack **b, t_list **solution);
|
||||
|
||||
#endif
|
||||
|
||||
+2
-12
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+20
-6
@@ -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);
|
||||
}
|
||||
|
||||
+12
-15
@@ -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