mise en place des fichiers

This commit is contained in:
hugogogo
2021-06-11 19:32:36 +02:00
parent 64363aeb18
commit 9ddf8ab304
11 changed files with 94 additions and 37 deletions

View File

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

BIN
builds/algo.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
builds/stop.o Normal file

Binary file not shown.

View File

@@ -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();
*/
/*

BIN
pushswap

Binary file not shown.

12
srcs/algo.c Normal file
View File

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

View File

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

View File

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

28
srcs/stop.c Normal file
View File

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