ajout flag -P de debug
This commit is contained in:
43
srcs/print.c
43
srcs/print.c
@@ -1,5 +1,31 @@
|
||||
#include "push_swap.h"
|
||||
|
||||
char *fill_line(t_stack *list, char *stack)
|
||||
{
|
||||
while (list != NULL)
|
||||
{
|
||||
if (list->limit == 1)
|
||||
stack = ft_strjoinfree(ft_strdup("]"), stack);
|
||||
stack = ft_strjoinfree(ft_itoa(list->n), stack);
|
||||
if (list->limit == 1)
|
||||
stack = ft_strjoinfree(ft_strdup("["), stack);
|
||||
stack = ft_strjoinfree(ft_strdup(" "), stack);
|
||||
list = list->next;
|
||||
}
|
||||
return (stack);
|
||||
}
|
||||
|
||||
void mark_step(t_list *solution)
|
||||
{
|
||||
char *line;
|
||||
|
||||
while (solution->next != NULL)
|
||||
solution = solution->next;
|
||||
line = solution->content;
|
||||
line = ft_strjoinfree(line, ft_strdup("!1"));
|
||||
solution->content = line;
|
||||
}
|
||||
|
||||
/*
|
||||
** this function is called by actions like sa()
|
||||
** it fills a new str element on the chained list like this :
|
||||
@@ -29,19 +55,9 @@ void fill_solution(t_list *solution, char *sp)
|
||||
a = *(t_stack **)(solution->content);
|
||||
b = *(t_stack **)(solution->next->content);
|
||||
stack = ft_strjoinfree(ft_strdup("!"), ft_strdup(sp));
|
||||
while (a != NULL)
|
||||
{
|
||||
stack = ft_strjoinfree(ft_itoa(a->n), stack);
|
||||
stack = ft_strjoinfree(ft_strdup(" "), stack);
|
||||
a = a->next;
|
||||
}
|
||||
stack = fill_line(a, stack);
|
||||
stack = ft_strjoinfree(ft_strdup("!a:"), stack);
|
||||
while (b != NULL)
|
||||
{
|
||||
stack = ft_strjoinfree(ft_itoa(b->n), stack);
|
||||
stack = ft_strjoinfree(ft_strdup(" "), stack);
|
||||
b = b->next;
|
||||
}
|
||||
stack = fill_line(b, stack);
|
||||
stack = ft_strjoinfree(ft_strdup("b:"), stack);
|
||||
ft_lstadd_back(&solution, ft_lstnew(stack));
|
||||
}
|
||||
@@ -58,7 +74,7 @@ void print_result(t_list *result, int flag)
|
||||
i++;
|
||||
part = ft_split(result->content, '!');
|
||||
ft_printf("%s\n", part[2]);
|
||||
if (flag)
|
||||
if (flag == 1 || (flag == 2 && part[3] != NULL))
|
||||
{
|
||||
ft_printf(" %s\n", part[1]);
|
||||
ft_printf(" %s\n", part[0]);
|
||||
@@ -67,6 +83,7 @@ void print_result(t_list *result, int flag)
|
||||
free(part[0]);
|
||||
free(part[1]);
|
||||
free(part[2]);
|
||||
free(part[3]);
|
||||
free(part);
|
||||
}
|
||||
if (flag)
|
||||
|
||||
Reference in New Issue
Block a user