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:
@@ -6,36 +6,36 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
#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 *bs;
|
||||
t_stack *as;
|
||||
t_stack *bs;
|
||||
|
||||
as = data->a;
|
||||
bs = data->b;
|
||||
ft_printf(FT_CLEAR);
|
||||
ft_printf("============== %4s ==============\n", com);
|
||||
while (as || bs)
|
||||
{
|
||||
if (as && bs)
|
||||
ft_printf("%5d || %5d\n", as->nb, bs->nb);
|
||||
else if (!as && bs)
|
||||
ft_printf("%5c || %5d\n", ' ', bs->nb);
|
||||
else if (as && !bs)
|
||||
ft_printf("%5d || %5c\n", as->nb, ' ');
|
||||
as = (as) ? as->next : as;
|
||||
bs = (bs) ? bs->next : bs;
|
||||
}
|
||||
ft_printf("==================================\n");
|
||||
usleep(VISU_SPEED);
|
||||
as = data->a;
|
||||
bs = data->b;
|
||||
ft_printf(FT_CLEAR);
|
||||
ft_printf("============== %4s ==============\n", com);
|
||||
while (as || bs)
|
||||
{
|
||||
if (as && bs)
|
||||
ft_printf("%5d || %5d\n", as->nb, bs->nb);
|
||||
else if (!as && bs)
|
||||
ft_printf("%5c || %5d\n", ' ', bs->nb);
|
||||
else if (as && !bs)
|
||||
ft_printf("%5d || %5c\n", as->nb, ' ');
|
||||
as = (as) ? as->next : as;
|
||||
bs = (bs) ? bs->next : bs;
|
||||
}
|
||||
ft_printf("==================================\n");
|
||||
usleep(VISU_SPEED);
|
||||
}
|
||||
|
||||
void exec_actions(t_psdata *data)
|
||||
@@ -46,24 +46,22 @@ void exec_actions(t_psdata *data)
|
||||
nop = data->op;
|
||||
while (nop && (buff = (char*)nop->content))
|
||||
{
|
||||
if (ft_strlen(buff) == 2)
|
||||
{
|
||||
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')
|
||||
if (ft_strcmp(buff, "rra") == 0 || ft_strcmp(buff, "rrn") == 0)
|
||||
ps_rerot(data, buff[2]);
|
||||
else if (buff[2] == 'r')
|
||||
else if (ft_strcmp(buff, "rrr") == 0)
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -77,10 +75,10 @@ int read_ops(t_psdata *data)
|
||||
buff = NULL;
|
||||
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", 2);
|
||||
ft_putendl_fd("Error", 2);
|
||||
return (1);
|
||||
}
|
||||
ft_lstaddend(&(data->op), nop);
|
||||
@@ -117,11 +115,11 @@ int main(int ac, char **av)
|
||||
|
||||
ps_initdata(&data);
|
||||
ret = 0;
|
||||
if (!get_params(&data, ac, av))
|
||||
if (!get_params(&data, ac, av, 1))
|
||||
return (0);
|
||||
new = data.a;
|
||||
if (new == NULL)
|
||||
ft_putendl("Empty");
|
||||
ft_putendl_fd("Error", 2);
|
||||
if (new == NULL || read_ops(&data))
|
||||
{
|
||||
ps_stkclean(&data);
|
||||
|
||||
Reference in New Issue
Block a user