diff --git a/Makefile b/Makefile index 712b583..ca342cd 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ LIBS = $(_LIBS:lib%.a=%) SRCS = pushswap.c \ algo.c \ + print.c \ stop.c ODIR = ./builds @@ -52,7 +53,6 @@ clean: /bin/rm -f $(OBJS) fclean: clean - make fclean -C $(LDIR) /bin/rm -rf $(ODIR) /bin/rm -f $(NAME) /bin/rm -rf a.out a.out.dSYM diff --git a/builds/algo.o b/builds/algo.o index 1a7a024..0999852 100644 Binary files a/builds/algo.o and b/builds/algo.o differ diff --git a/builds/print.o b/builds/print.o new file mode 100644 index 0000000..5e01507 Binary files /dev/null and b/builds/print.o differ diff --git a/builds/pushswap.o b/builds/pushswap.o index ad292ed..77f8165 100644 Binary files a/builds/pushswap.o and b/builds/pushswap.o differ diff --git a/builds/stop.o b/builds/stop.o index e70f53f..812c4e8 100644 Binary files a/builds/stop.o and b/builds/stop.o differ diff --git a/includes/pushswap.h b/includes/pushswap.h index 946b7f8..ab00aef 100644 --- a/includes/pushswap.h +++ b/includes/pushswap.h @@ -15,22 +15,27 @@ typedef struct s_stack /* ** pushswap.c */ -void is_valid(int ac, char **av) -t_stack *init_stack(int ac, char **av) -void print_stack(t_stack *stack) +void is_valid(int ac, char **av); +t_stack *init_stack(int ac, char **av); /* ** stop.c */ void ps_usage(void); void ps_error(int err); -void stop(t_stack *stb, t_stack *sta, t_list *lst, int i); +void ps_stop(t_stack *stb, t_stack *sta, t_list *lst, int i); /* ** algo.c */ t_list *sort_algo(t_stack *stack); +/* +** print.c +*/ +void print_stack(t_stack *stack); + + /* ** swap */ diff --git a/pushswap b/pushswap index 487e881..7b15bce 100755 Binary files a/pushswap and b/pushswap differ diff --git a/srcs/algo.c b/srcs/algo.c index ab1f744..8bd20a5 100644 --- a/srcs/algo.c +++ b/srcs/algo.c @@ -7,6 +7,6 @@ t_list *sort_algo(t_stack *stack) (void)stack; t_list *lst; - lst = ft_lstnew("solution"); + lst = ft_lstnew(ft_strdup("solution")); return (lst); } diff --git a/srcs/print.c b/srcs/print.c new file mode 100644 index 0000000..ee38810 --- /dev/null +++ b/srcs/print.c @@ -0,0 +1,16 @@ + +#include "pushswap.h" + +void print_stack(t_stack *stack) +{ + ft_putstr("["); + while (stack) + { + ft_printf("%i", stack->n); + stack = stack->next; + if (stack) + ft_putstr("; "); + } + ft_putstr("]\n"); +} + diff --git a/srcs/pushswap.c b/srcs/pushswap.c index f20ddd6..5ec7549 100644 --- a/srcs/pushswap.c +++ b/srcs/pushswap.c @@ -4,7 +4,7 @@ void is_valid(int ac, char **av) { if (ac < 2) - ps_error(1); + ps_stop(NULL, NULL, NULL, 1); (void)av; // check more error } @@ -18,7 +18,7 @@ t_stack *init_stack(int ac, char **av) while (--ac) { if (!(start = ft_calloc(1, sizeof(t_stack)))) - ps_clean(start, 2); + ps_stop(start, NULL, NULL, 2); start->n = ft_atoi(av[ac]); start->next = tmp; tmp = start; @@ -26,19 +26,6 @@ t_stack *init_stack(int ac, char **av) return (start); } -void print_stack(t_stack *stack) -{ - ft_putstr("["); - while (stack) - { - ft_printf("%i", stack->n); - stack = stack->next; - if (stack) - ft_putstr("; "); - } - ft_putstr("]\n"); -} - int main(int ac, char **av) { t_stack *stack; @@ -49,6 +36,6 @@ int main(int ac, char **av) print_stack(stack); result = sort_algo(stack); ft_printf("%s\n", result->content); - ps_clean(stack, 1); + ps_stop(stack, NULL, result, 0); return(0); } diff --git a/srcs/stop.c b/srcs/stop.c index bf27e54..6f00162 100644 --- a/srcs/stop.c +++ b/srcs/stop.c @@ -15,12 +15,12 @@ void ps_error(int err) exit(0); } -void stop(t_stack *stack_a, t_stack *stack_b, t_list *solution, int err) +void ps_stop(t_stack *stack_a, t_stack *stack_b, t_list *solution, int err) { if (stack_a) - ft_lstclear((t_list)&stack_a, NULL); + ft_lstclear((t_list **)&stack_a, NULL); if (stack_b) - ft_lstclear((t_list)&stack_b, NULL); + ft_lstclear((t_list **)&stack_b, NULL); if (solution) ft_lstclear(&solution, free); ps_error(err);