diff --git a/Makefile b/Makefile index 89f5759..712b583 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,8 @@ _LIBS = libft.a LIBS = $(_LIBS:lib%.a=%) SRCS = pushswap.c \ - error.c + algo.c \ + stop.c ODIR = ./builds OBJS = $(SRCS:%.c=$(ODIR)/%.o) diff --git a/builds/algo.o b/builds/algo.o new file mode 100644 index 0000000..1a7a024 Binary files /dev/null and b/builds/algo.o differ diff --git a/builds/error.o b/builds/error.o deleted file mode 100644 index cfffd51..0000000 Binary files a/builds/error.o and /dev/null differ diff --git a/builds/pushswap.o b/builds/pushswap.o index a13f70c..ad292ed 100644 Binary files a/builds/pushswap.o and b/builds/pushswap.o differ diff --git a/builds/stop.o b/builds/stop.o new file mode 100644 index 0000000..e70f53f Binary files /dev/null and b/builds/stop.o differ diff --git a/includes/pushswap.h b/includes/pushswap.h index 4794109..946b7f8 100644 --- a/includes/pushswap.h +++ b/includes/pushswap.h @@ -9,20 +9,36 @@ typedef struct s_stack { int n; - struct s_list *next; + struct s_stack *next; } t_stack; -void ps_error(int i); -void ps_clean(t_stack *stack, int i); +/* +** pushswap.c +*/ +void is_valid(int ac, char **av) +t_stack *init_stack(int ac, char **av) +void print_stack(t_stack *stack) + +/* +** stop.c +*/ +void ps_usage(void); +void ps_error(int err); +void stop(t_stack *stb, t_stack *sta, t_list *lst, int i); + +/* +** algo.c +*/ +t_list *sort_algo(t_stack *stack); /* ** swap */ /* int swap(t_list **list); -int sa(); -int sb(); -int ss(); +void sa(); +void sb(); +void ss(); */ /* diff --git a/pushswap b/pushswap index edf43a7..487e881 100755 Binary files a/pushswap and b/pushswap differ diff --git a/srcs/algo.c b/srcs/algo.c new file mode 100644 index 0000000..ab1f744 --- /dev/null +++ b/srcs/algo.c @@ -0,0 +1,12 @@ + + +#include "pushswap.h" + +t_list *sort_algo(t_stack *stack) +{ + (void)stack; + t_list *lst; + + lst = ft_lstnew("solution"); + return (lst); +} diff --git a/srcs/error.c b/srcs/error.c deleted file mode 100644 index 9cfaea6..0000000 --- a/srcs/error.c +++ /dev/null @@ -1,22 +0,0 @@ - -#include "pushswap.h" - -void ps_clean(t_stack *stack, int err) -{ - (void)stack; - ps_error(err); -} - -void ps_usage(void) -{ - ft_printf("usage\n"); -} - -void ps_error(int err) -{ - if (err == 1) - ps_usage(); - if (err == 2) - ft_printf("error\n"); - exit(0); -} diff --git a/srcs/pushswap.c b/srcs/pushswap.c index b8bb68b..f20ddd6 100644 --- a/srcs/pushswap.c +++ b/srcs/pushswap.c @@ -6,27 +6,49 @@ void is_valid(int ac, char **av) if (ac < 2) ps_error(1); (void)av; + // check more error } t_stack *init_stack(int ac, char **av) { - (void)ac; - (void)av; t_stack *start; + t_stack *tmp; - if (!(start = ft_calloc(1, sizeof(t_stack)))) - ps_clean(start, 2); + tmp = NULL; + while (--ac) + { + if (!(start = ft_calloc(1, sizeof(t_stack)))) + ps_clean(start, 2); + start->n = ft_atoi(av[ac]); + start->next = tmp; + tmp = start; + } 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; - //t_list *result; + t_list *result; is_valid(ac, av); // check if usage and list are correct - stack = init_stack(ac, av); - // result = sort_algo(stack); + stack = init_stack(ac, av); // create the list from av[] + print_stack(stack); + result = sort_algo(stack); + ft_printf("%s\n", result->content); + ps_clean(stack, 1); return(0); } - diff --git a/srcs/stop.c b/srcs/stop.c new file mode 100644 index 0000000..bf27e54 --- /dev/null +++ b/srcs/stop.c @@ -0,0 +1,28 @@ + +#include "pushswap.h" + +void ps_usage(void) +{ + ft_printf("usage\n"); +} + +void ps_error(int err) +{ + if (err == 1) + ps_usage(); + if (err == 2) + ft_printf("error\n"); + exit(0); +} + +void stop(t_stack *stack_a, t_stack *stack_b, t_list *solution, int err) +{ + if (stack_a) + ft_lstclear((t_list)&stack_a, NULL); + if (stack_b) + ft_lstclear((t_list)&stack_b, NULL); + if (solution) + ft_lstclear(&solution, free); + ps_error(err); + exit(0); +}