/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* parsing.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/12/07 19:23:59 by erey-bet #+# #+# */ /* Updated: 2022/12/08 11:22:53 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 put_error(void) { write(2, "Error\n", 6); return (1); } char **set_only_space(char *argv[], int i) { int x; x = 0; while (argv[i][x]) if (ft_strchr("\a\b\t\n\v\f\r", argv[i][x++]) != NULL) argv[i][x - 1] = ' '; return (argv); } int if_there_is_double(long *tab, int y) { int i; int x; i = 0; while (i < y) { x = 0; while (x < y) { if (tab[i] == tab[x] && i != x) return (1); x++; } i++; } return (0); } int parsing(int argc, char *argv[], long *tab) { int i; int y; int x; char **tmp; i = 0; y = 0; while (++i < argc) { argv = set_only_space(argv, i); x = 0; tmp = ft_split(argv[i], ' '); while (tmp[x] != NULL) { if (ft_atoi_check(tmp[x])) tab[y++] = ft_atoi(tmp[x]); else return (put_error()); x++; } } if (if_there_is_double(tab, y) || (y < argc - 1)) return (put_error()); choice(tab, y); return (0); }