ps_stop fonctionne

This commit is contained in:
hugogogo
2021-06-11 20:56:15 +02:00
parent 9ddf8ab304
commit 1993a9a85d
11 changed files with 33 additions and 25 deletions

View File

@@ -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

Binary file not shown.

BIN
builds/print.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -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
*/

BIN
pushswap

Binary file not shown.

View File

@@ -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);
}

16
srcs/print.c Normal file
View File

@@ -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");
}

View File

@@ -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);
}

View File

@@ -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);