Actually it might be OK =)
normed out most files still need to split functions accordingly still need to check for hidden norm errors
This commit is contained in:
parent
3d54238d24
commit
079902b834
17
Makefile
17
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2019/02/23 14:30:57 by tmaze #+# #+# #
|
# Created: 2019/02/23 14:30:57 by tmaze #+# #+# #
|
||||||
# Updated: 2019/03/06 11:37:28 by tmaze ### ########.fr #
|
# Updated: 2019/03/15 16:39:08 by tmaze ### ########.fr #
|
||||||
# #
|
# #
|
||||||
#******************************************************************************#
|
#******************************************************************************#
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ endif
|
|||||||
|
|
||||||
# Compilator
|
# Compilator
|
||||||
CC = gcc
|
CC = gcc
|
||||||
FLAGS = -Wall -Wextra -g
|
FLAGS = -Wall -Wextra -Werror
|
||||||
|
|
||||||
# Folders
|
# Folders
|
||||||
LIBDIR = libft
|
LIBDIR = libft
|
||||||
@ -60,7 +60,7 @@ OBJP = $(addprefix $(OBJDIR)/, $(SRC:.c=.o))
|
|||||||
OBJP1 = $(addprefix $(OBJDIR)/, $(MAIN1:.c=.o))
|
OBJP1 = $(addprefix $(OBJDIR)/, $(MAIN1:.c=.o))
|
||||||
OBJP2 = $(addprefix $(OBJDIR)/, $(MAIN2:.c=.o))
|
OBJP2 = $(addprefix $(OBJDIR)/, $(MAIN2:.c=.o))
|
||||||
INCP = $(foreach dir, $(INCDIR), -I$(dir))
|
INCP = $(foreach dir, $(INCDIR), -I$(dir))
|
||||||
OBJS_DIRS = $(sort $(dir $(OBJP)))
|
|
||||||
# Default Rule
|
# Default Rule
|
||||||
DRULE = all
|
DRULE = all
|
||||||
|
|
||||||
@ -72,17 +72,14 @@ default :
|
|||||||
|
|
||||||
all : $(NAME1) $(NAME2)
|
all : $(NAME1) $(NAME2)
|
||||||
|
|
||||||
re : fclean default
|
|
||||||
|
|
||||||
# Compilation rules
|
# Compilation rules
|
||||||
|
|
||||||
$(OBJDIR)/%.o : $(SRCDIR)/%.c $(OBJDIR)
|
$(OBJDIR)/%.o : $(SRCDIR)/%.c $(OBJDIR)
|
||||||
$(CC) $(FLAGS) -c -o $@ $< $(INCP)
|
$(CC) $(FLAGS) -c -o $@ $< $(INCP)
|
||||||
|
|
||||||
$(OBJDIR) :
|
$(OBJDIR) :
|
||||||
@echo -e "$(YEL)===> $(GRE)$(NAME) : $(YEL) Objects Compilation <===$(DEF)"
|
@echo -e "$(YEL)===> $(GRE)$(NAME) : $(YEL) Directory Creation <===$(DEF)"
|
||||||
@mkdir -p $(OBJDIR)
|
mkdir -p $(OBJDIR)
|
||||||
@mkdir -p $(OBJS_DIRS)
|
|
||||||
|
|
||||||
$(LIBDIR)/$(LIBFILE) :
|
$(LIBDIR)/$(LIBFILE) :
|
||||||
@echo -e "$(YEL)===> $(GRE)$(NAME) : $(YEL) Librairy Compilation <===$(DEF)"
|
@echo -e "$(YEL)===> $(GRE)$(NAME) : $(YEL) Librairy Compilation <===$(DEF)"
|
||||||
@ -105,8 +102,10 @@ fclean : clean
|
|||||||
@echo -e "$(RED)===> $(GRE)$(NAME) : $(RED) Delete Binary File <===$(DEF)"
|
@echo -e "$(RED)===> $(GRE)$(NAME) : $(RED) Delete Binary File <===$(DEF)"
|
||||||
@rm -f $(NAME1) $(NAME2)
|
@rm -f $(NAME1) $(NAME2)
|
||||||
|
|
||||||
|
re : fclean default
|
||||||
|
|
||||||
# Phony
|
# Phony
|
||||||
.PHONY = default all re clean fclean $(OBJDIR) $(NAME)
|
.PHONY = default all re clean fclean
|
||||||
# Color
|
# Color
|
||||||
DEF = \033[0m
|
DEF = \033[0m
|
||||||
BLA = \033[30m
|
BLA = \033[30m
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/21 14:13:53 by tmaze #+# #+# */
|
/* Created: 2019/02/21 14:13:53 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/10 12:14:19 by tmaze ### ########.fr */
|
/* Updated: 2019/03/15 15:33:18 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,8 +17,6 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
|
|
||||||
# include <stdio.h>
|
|
||||||
|
|
||||||
typedef struct s_stack
|
typedef struct s_stack
|
||||||
{
|
{
|
||||||
int nb;
|
int nb;
|
||||||
@ -33,11 +31,9 @@ typedef struct s_psdata
|
|||||||
size_t size_a;
|
size_t size_a;
|
||||||
size_t size_b;
|
size_t size_b;
|
||||||
t_list *op;
|
t_list *op;
|
||||||
|
char viz;
|
||||||
} t_psdata;
|
} t_psdata;
|
||||||
|
|
||||||
char **ft_strsplitwhitespace(char *s);
|
|
||||||
int ft_iswhitespace(char c);
|
|
||||||
|
|
||||||
t_stack *ps_stknew(int nb);
|
t_stack *ps_stknew(int nb);
|
||||||
void ps_stkpsh(t_psdata *data, char c, t_stack *new);
|
void ps_stkpsh(t_psdata *data, char c, t_stack *new);
|
||||||
t_stack *ps_stkpop(t_psdata *data, char c);
|
t_stack *ps_stkpop(t_psdata *data, char c);
|
||||||
@ -54,7 +50,7 @@ void ps_rrerot(t_psdata *data);
|
|||||||
|
|
||||||
int is_op(char *buff);
|
int is_op(char *buff);
|
||||||
t_list *add_op(t_psdata *data, char *op);
|
t_list *add_op(t_psdata *data, char *op);
|
||||||
int get_params(t_psdata *data, int ac, char **av);
|
int get_params(t_psdata *data, int ac, char **av, int viz);
|
||||||
int check_input(char *in, int *ret);
|
int check_input(char *in, int *ret);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,36 +6,36 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/23 13:35:15 by tmaze #+# #+# */
|
/* Created: 2019/02/23 13:35:15 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/11 13:41:27 by tmaze ### ########.fr */
|
/* Updated: 2019/03/15 16:52:54 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
|
|
||||||
#define VISU_SPEED 100000
|
#define VISU_SPEED 500000
|
||||||
|
|
||||||
void debug(t_psdata *data, char *com)
|
void debug(t_psdata *data, char *com)
|
||||||
{
|
{
|
||||||
t_stack *as;
|
t_stack *as;
|
||||||
t_stack *bs;
|
t_stack *bs;
|
||||||
|
|
||||||
as = data->a;
|
as = data->a;
|
||||||
bs = data->b;
|
bs = data->b;
|
||||||
ft_printf(FT_CLEAR);
|
ft_printf(FT_CLEAR);
|
||||||
ft_printf("============== %4s ==============\n", com);
|
ft_printf("============== %4s ==============\n", com);
|
||||||
while (as || bs)
|
while (as || bs)
|
||||||
{
|
{
|
||||||
if (as && bs)
|
if (as && bs)
|
||||||
ft_printf("%5d || %5d\n", as->nb, bs->nb);
|
ft_printf("%5d || %5d\n", as->nb, bs->nb);
|
||||||
else if (!as && bs)
|
else if (!as && bs)
|
||||||
ft_printf("%5c || %5d\n", ' ', bs->nb);
|
ft_printf("%5c || %5d\n", ' ', bs->nb);
|
||||||
else if (as && !bs)
|
else if (as && !bs)
|
||||||
ft_printf("%5d || %5c\n", as->nb, ' ');
|
ft_printf("%5d || %5c\n", as->nb, ' ');
|
||||||
as = (as) ? as->next : as;
|
as = (as) ? as->next : as;
|
||||||
bs = (bs) ? bs->next : bs;
|
bs = (bs) ? bs->next : bs;
|
||||||
}
|
}
|
||||||
ft_printf("==================================\n");
|
ft_printf("==================================\n");
|
||||||
usleep(VISU_SPEED);
|
usleep(VISU_SPEED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void exec_actions(t_psdata *data)
|
void exec_actions(t_psdata *data)
|
||||||
@ -46,24 +46,22 @@ void exec_actions(t_psdata *data)
|
|||||||
nop = data->op;
|
nop = data->op;
|
||||||
while (nop && (buff = (char*)nop->content))
|
while (nop && (buff = (char*)nop->content))
|
||||||
{
|
{
|
||||||
if (ft_strlen(buff) == 2)
|
if (ft_strcmp(buff, "rra") == 0 || ft_strcmp(buff, "rrn") == 0)
|
||||||
{
|
|
||||||
if (buff[0] == 's' && buff[1] != 's')
|
|
||||||
ps_swap(data, buff[1]);
|
|
||||||
else if (buff[0] == 's' && buff[1] == 's')
|
|
||||||
ps_sswap(data);
|
|
||||||
else if (buff[0] == 'r' && buff[1] != 'r')
|
|
||||||
ps_rot(data, buff[1]);
|
|
||||||
else if (buff[0] == 'r' && buff[1] == 'r')
|
|
||||||
ps_rrot(data);
|
|
||||||
else if (buff[0] == 'p')
|
|
||||||
ps_push(data, buff[1]);
|
|
||||||
}
|
|
||||||
else if (buff[2] != 'r')
|
|
||||||
ps_rerot(data, buff[2]);
|
ps_rerot(data, buff[2]);
|
||||||
else if (buff[2] == 'r')
|
else if (ft_strcmp(buff, "rrr") == 0)
|
||||||
ps_rrerot(data);
|
ps_rrerot(data);
|
||||||
// debug(data, buff);
|
else if (buff[0] == 's' && buff[1] != 's')
|
||||||
|
ps_swap(data, buff[1]);
|
||||||
|
else if (buff[0] == 's' && buff[1] == 's')
|
||||||
|
ps_sswap(data);
|
||||||
|
else if (buff[0] == 'r' && buff[1] != 'r')
|
||||||
|
ps_rot(data, buff[1]);
|
||||||
|
else if (buff[0] == 'r' && buff[1] == 'r')
|
||||||
|
ps_rrot(data);
|
||||||
|
else if (buff[0] == 'p')
|
||||||
|
ps_push(data, buff[1]);
|
||||||
|
if (data->viz)
|
||||||
|
debug(data, buff);
|
||||||
nop = nop->next;
|
nop = nop->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,10 +75,10 @@ int read_ops(t_psdata *data)
|
|||||||
buff = NULL;
|
buff = NULL;
|
||||||
while ((ret = get_next_line(0, &buff)) > 0)
|
while ((ret = get_next_line(0, &buff)) > 0)
|
||||||
{
|
{
|
||||||
if (ft_strlen(buff) > 4 || !is_op(buff) || (nop = ft_lstnew(buff, 4)) == NULL)
|
if (ft_strlen(buff) > 4 || !is_op(buff)
|
||||||
|
|| (nop = ft_lstnew(buff, 4)) == NULL)
|
||||||
{
|
{
|
||||||
ft_printf("'%s' %d %d %d\n", buff, ft_strlen(buff) > 4, !is_op(buff), nop == NULL);
|
ft_putendl_fd("Error", 2);
|
||||||
ft_putendl_fd("Error 2", 2);
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
ft_lstaddend(&(data->op), nop);
|
ft_lstaddend(&(data->op), nop);
|
||||||
@ -117,11 +115,11 @@ int main(int ac, char **av)
|
|||||||
|
|
||||||
ps_initdata(&data);
|
ps_initdata(&data);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if (!get_params(&data, ac, av))
|
if (!get_params(&data, ac, av, 1))
|
||||||
return (0);
|
return (0);
|
||||||
new = data.a;
|
new = data.a;
|
||||||
if (new == NULL)
|
if (new == NULL)
|
||||||
ft_putendl("Empty");
|
ft_putendl_fd("Error", 2);
|
||||||
if (new == NULL || read_ops(&data))
|
if (new == NULL || read_ops(&data))
|
||||||
{
|
{
|
||||||
ps_stkclean(&data);
|
ps_stkclean(&data);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/25 12:44:08 by tmaze #+# #+# */
|
/* Created: 2019/02/25 12:44:08 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/10 12:27:41 by tmaze ### ########.fr */
|
/* Updated: 2019/03/15 15:36:06 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -19,6 +19,7 @@ void ps_initdata(t_psdata *data)
|
|||||||
data->size_a = 0;
|
data->size_a = 0;
|
||||||
data->size_b = 0;
|
data->size_b = 0;
|
||||||
data->op = NULL;
|
data->op = NULL;
|
||||||
|
data->viz = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_input(char *in, int *ret)
|
int check_input(char *in, int *ret)
|
||||||
@ -35,34 +36,30 @@ int check_input(char *in, int *ret)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_params(t_psdata *data, int ac, char **av)
|
int get_params(t_psdata *data, int ac, char **av, int viz)
|
||||||
{
|
{
|
||||||
t_stack *new;
|
t_stack *new;
|
||||||
char **tab;
|
|
||||||
int nb;
|
int nb;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
|
||||||
|
|
||||||
i = ac;
|
i = ac;
|
||||||
nb = 0;
|
nb = 0;
|
||||||
while (--i > 0 && !(j = 0))
|
while (--i > 0)
|
||||||
if ((tab = ft_strsplitwhitespace(av[i])) != NULL)
|
{
|
||||||
|
if (i == 1 && viz && ft_strcmp(av[i], "-v") == 0)
|
||||||
|
data->viz = 'a';
|
||||||
|
else if (check_input(av[i], &nb) && (new = ps_stknew(nb)) != NULL)
|
||||||
{
|
{
|
||||||
while (tab[j])
|
new->ind = 0;
|
||||||
j++;
|
ps_stkpsh(data, 'a', new);
|
||||||
while (--j >= 0)
|
|
||||||
{
|
|
||||||
if (check_input(tab[j], &nb) && (new = ps_stknew(nb)) != NULL)
|
|
||||||
ps_stkpsh(data, 'a', new);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ft_putendl_fd("Error 1", 2);
|
|
||||||
ps_stkclean(data);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ft_del_words_tables(&tab);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ft_putendl_fd("Error", 2);
|
||||||
|
ps_stkclean(data);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
149
srcs/push_swap.c
149
srcs/push_swap.c
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/03 11:41:49 by tmaze #+# #+# */
|
/* Created: 2019/03/03 11:41:49 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/11 16:30:23 by tmaze ### ########.fr */
|
/* Updated: 2019/03/15 16:17:37 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -90,11 +90,9 @@ void sortfor5(t_psdata *data)
|
|||||||
data->a->next->next->ind = 2;
|
data->a->next->next->ind = 2;
|
||||||
while (data->a->ind == 2 || data->size_b > 0)
|
while (data->a->ind == 2 || data->size_b > 0)
|
||||||
{
|
{
|
||||||
if (data->a->ind != 2
|
if (data->a->ind != 2 || (data->b && data->b->nb < data->a->nb))
|
||||||
|| (data->size_b > 0 && data->b->nb < data->a->nb))
|
|
||||||
ft_printf("pa\n");
|
ft_printf("pa\n");
|
||||||
if (data->a->ind != 2
|
if (data->a->ind != 2 || (data->b && data->b->nb < data->a->nb))
|
||||||
|| (data->size_b > 0 && data->b->nb < data->a->nb))
|
|
||||||
ps_push(data, 'a');
|
ps_push(data, 'a');
|
||||||
data->a->ind = 3;
|
data->a->ind = 3;
|
||||||
ft_printf("ra\n");
|
ft_printf("ra\n");
|
||||||
@ -173,6 +171,52 @@ int get_nb_groups(t_psdata *data)
|
|||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int join_lists(t_psdata *data, t_stack **last, int inds, int inds2)
|
||||||
|
{
|
||||||
|
while ((*last)->ind == inds2 || data->size_b > 0)
|
||||||
|
if (((*last)->ind != inds2 && data->size_b > 0)
|
||||||
|
|| (data->size_b > 0 && data->b->nb > (*last)->nb))
|
||||||
|
{
|
||||||
|
if (add_op(data, "pa\0") == NULL)
|
||||||
|
return (0);
|
||||||
|
ps_push(data, 'a');
|
||||||
|
data->a->ind = inds;
|
||||||
|
}
|
||||||
|
else if (data->size_b == 0 || data->b->nb < (*last)->nb)
|
||||||
|
{
|
||||||
|
if (add_op(data, "rra") == NULL)
|
||||||
|
return (0);
|
||||||
|
ps_rerot(data, 'a');
|
||||||
|
data->a->ind = inds;
|
||||||
|
(*last) = get_last_a(data);
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int rotate_list(t_psdata *data, t_stack **last)
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
|
||||||
|
if (get_nb_groups(data) > 2)
|
||||||
|
{
|
||||||
|
if (get_nb_groups(data) != 2
|
||||||
|
&& data->a->ind != (*last)->ind && add_op(data, "rra") == NULL)
|
||||||
|
return (0);
|
||||||
|
else if (get_nb_groups(data) != 2 && data->a->ind != (*last)->ind)
|
||||||
|
{
|
||||||
|
ps_rerot(data, 'a');
|
||||||
|
(*last) = get_last_a(data);
|
||||||
|
while ((*last)->ind == data->a->ind
|
||||||
|
&& (tmp = add_op(data, "rra")) != NULL)
|
||||||
|
{
|
||||||
|
ps_rerot(data, 'a');
|
||||||
|
(*last) = get_last_a(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
int sort(t_psdata *data)
|
int sort(t_psdata *data)
|
||||||
{
|
{
|
||||||
t_list *tmp;
|
t_list *tmp;
|
||||||
@ -185,44 +229,16 @@ int sort(t_psdata *data)
|
|||||||
while (data->a->ind != last->ind)
|
while (data->a->ind != last->ind)
|
||||||
{
|
{
|
||||||
inds2 = data->a->ind;
|
inds2 = data->a->ind;
|
||||||
while (data->a->ind == inds2 && (tmp = add_op(data, "pb\0")) != NULL)
|
while (data->a && data->a->ind == inds2
|
||||||
|
&& (tmp = add_op(data, "pb\0")) != NULL)
|
||||||
ps_push(data, 'b');
|
ps_push(data, 'b');
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
inds2 = last->ind;
|
inds2 = last->ind;
|
||||||
while (last->ind == inds2 || data->size_b > 0)
|
if (join_lists(data, &last, inds, inds2) == 0)
|
||||||
{
|
return (0);
|
||||||
if ((last->ind != inds2 && data->size_b > 0) || (data->b && data->b->nb > last->nb))
|
if (rotate_list(data, &last) == 0)
|
||||||
{
|
return (0);
|
||||||
if (add_op(data, "pa\0") == NULL)
|
|
||||||
return (0);
|
|
||||||
ps_push(data, 'a');
|
|
||||||
data->a->ind = inds;
|
|
||||||
}
|
|
||||||
else if (data->size_b == 0 || data->b->nb < last->nb)
|
|
||||||
{
|
|
||||||
if (add_op(data, "rra") == NULL)
|
|
||||||
return (0);
|
|
||||||
ps_rerot(data, 'a');
|
|
||||||
data->a->ind = inds;
|
|
||||||
last = get_last_a(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if (get_nb_groups(data) > 2)
|
|
||||||
// {
|
|
||||||
if (get_nb_groups(data) != 2 && data->a->ind != last->ind && add_op(data, "rra") == NULL)
|
|
||||||
return (0);
|
|
||||||
else if (get_nb_groups(data) != 2 && data->a->ind != last->ind)
|
|
||||||
{
|
|
||||||
ps_rerot(data, 'a');
|
|
||||||
last = get_last_a(data);
|
|
||||||
while (last->ind == data->a->ind && (tmp = add_op(data, "rra")) != NULL)
|
|
||||||
{
|
|
||||||
ps_rerot(data, 'a');
|
|
||||||
last = get_last_a(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
inds++;
|
inds++;
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
@ -242,7 +258,7 @@ void clean_op(t_psdata *data)
|
|||||||
{
|
{
|
||||||
ct1 = (char*)(it->content);
|
ct1 = (char*)(it->content);
|
||||||
ct2 = (char*)(it->next->content);
|
ct2 = (char*)(it->next->content);
|
||||||
if (ct1 && ct2 && ct1[0] == 'p' && ct2[0] == 'p' && ct1[1] != ct2[1])
|
if (ct1[0] == 'p' && ct2[0] == 'p' && ct1[1] != ct2[1])
|
||||||
{
|
{
|
||||||
*prec = it->next->next;
|
*prec = it->next->next;
|
||||||
ft_memdel(&(it->next->content));
|
ft_memdel(&(it->next->content));
|
||||||
@ -255,7 +271,8 @@ void clean_op(t_psdata *data)
|
|||||||
else if (it->next->next)
|
else if (it->next->next)
|
||||||
{
|
{
|
||||||
ct3 = (char*)(it->next->next->content);
|
ct3 = (char*)(it->next->next->content);
|
||||||
if (ct1[0] == 'p' && ct1[1] == 'b' && ct3[0] == 'p' && ct3[1] == 'a' && ft_strcmp(ct2, "rra") == 0)
|
if (ct1[0] == 'p' && ct1[1] == 'b' && ct3[0] == 'p'
|
||||||
|
&& ct3[1] == 'a' && ft_strcmp(ct2, "rra") == 0)
|
||||||
{
|
{
|
||||||
*prec = it->next;
|
*prec = it->next;
|
||||||
ft_strcpy((char*)(it->next->next->content), "sa");
|
ft_strcpy((char*)(it->next->next->content), "sa");
|
||||||
@ -278,46 +295,40 @@ void clean_op(t_psdata *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_ops(t_psdata *data)
|
||||||
|
{
|
||||||
|
t_list *it;
|
||||||
|
|
||||||
|
it = data->op;
|
||||||
|
while (it)
|
||||||
|
{
|
||||||
|
ft_printf("%s\n", (char*)(it->content));
|
||||||
|
it = it->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
t_list *it;
|
|
||||||
t_stack *ptr;
|
|
||||||
t_psdata data;
|
t_psdata data;
|
||||||
|
|
||||||
ps_initdata(&data);
|
ps_initdata(&data);
|
||||||
if (!get_params(&data, ac, av))
|
if (!get_params(&data, ac, av, 0))
|
||||||
return (0);
|
return (0);
|
||||||
ptr = data.a;
|
if (data.a == NULL)
|
||||||
if (ptr == NULL)
|
ft_putendl_fd("Error", 2);
|
||||||
ft_putendl("Empty");
|
|
||||||
while (ptr)
|
|
||||||
{
|
|
||||||
ptr->ind = 0;
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
if (data.size_a == 3)
|
if (data.size_a == 3)
|
||||||
{
|
|
||||||
sortfor3(&data);
|
sortfor3(&data);
|
||||||
ps_stkclean(&data);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
else if (data.size_a == 5)
|
else if (data.size_a == 5)
|
||||||
{
|
|
||||||
sortfor5(&data);
|
sortfor5(&data);
|
||||||
ps_stkclean(&data);
|
if (data.size_a != 0 && data.size_a != 3 && data.size_a != 5)
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
mark_groups(&data);
|
|
||||||
if (sort(&data) == 0)
|
|
||||||
ft_putendl_fd("Error\n", 2);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
clean_op(&data);
|
mark_groups(&data);
|
||||||
it = data.op;
|
if (sort(&data) == 0)
|
||||||
while (it)
|
ft_putendl_fd("Error\n", 2);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
ft_printf("%s\n", (char*)(it->content));
|
clean_op(&data);
|
||||||
it = it->next;
|
print_ops(&data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ps_stkclean(&data);
|
ps_stkclean(&data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user