60 lines
1.6 KiB
C
60 lines
1.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* parsing.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/12/07 19:23:59 by erey-bet #+# #+# */
|
|
/* Updated: 2022/12/07 19:24:04 by erey-bet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "push_swap.h"
|
|
|
|
void choice(long *tab, int y)
|
|
{
|
|
if (y == 4 || y > 5)
|
|
pre_push_swap(tab, y);
|
|
else if (y == 5)
|
|
push_swap_5(tab, y);
|
|
else if (y == 3)
|
|
push_swap_3(tab, y);
|
|
else if (y == 2)
|
|
if (tab[0] > tab[1])
|
|
write(1, "ra\n", 3);
|
|
}
|
|
|
|
int parsing(int argc, char *argv[], long *tab)
|
|
{
|
|
int i;
|
|
int y;
|
|
int x;
|
|
char **tmp;
|
|
|
|
i = 0;
|
|
y = 0;
|
|
while (++i < argc)
|
|
{
|
|
x = 0;
|
|
while (argv[i][x])
|
|
if (ft_strchr("\a\b\t\n\v\f\r", argv[i][x++]) != NULL)
|
|
argv[i][x - 1] = ' ';
|
|
x = 0;
|
|
tmp = ft_split(argv[i], ' ');
|
|
while (tmp[x] != NULL)
|
|
{
|
|
if (ft_atoi_check(tmp[x]))
|
|
tab[y++] = ft_atoi(tmp[x]);
|
|
else
|
|
{
|
|
write(1, "Error\n", 6);
|
|
return (1);
|
|
}
|
|
x++;
|
|
}
|
|
}
|
|
choice(tab, y);
|
|
return (0);
|
|
}
|