From 61a3861d392b069eaae33c82cba545525bc1250f Mon Sep 17 00:00:00 2001 From: Etienne Rey-bethbeder Date: Thu, 8 Dec 2022 17:47:06 +0100 Subject: [PATCH] Projet Fini --- Makefile | 9 ++++----- parsing.c | 51 ++++++++++++++++++++++++++++++++++++++++++--------- push_swap.c | 39 +-------------------------------------- push_swap.h | 10 +++++----- 4 files changed, 52 insertions(+), 57 deletions(-) diff --git a/Makefile b/Makefile index 14a6e09..89f07d0 100644 --- a/Makefile +++ b/Makefile @@ -6,18 +6,16 @@ # By: erey-bet +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2022/09/27 04:19:30 by erey-bet #+# #+# # -# Updated: 2022/12/02 19:24:34 by erey-bet ### ########.fr # +# Updated: 2022/12/08 16:58:13 by erey-bet ### ########.fr # # # # **************************************************************************** # SRCS = push_swap.c operations.c tools.c parsing.c OBJS = ${SRCS:.c=.o} CC = clang -CFLAGS = -g -Wall -Wextra -Werror +CFLAGS = -Wall -Wextra -Werror NAME = push_swap -# TU OUBLIS PAS LE -G DANS CFLAGS HEIN - all: ${NAME} ${NAME}: ${OBJS} @@ -35,6 +33,8 @@ fclean: clean re: fclean all +.PHONY: all clean fclean re coffee + coffee: @clear @echo "" @@ -137,4 +137,3 @@ coffee: @echo ' """------"""' ${MAKE} coffee -.PHONY: all clean fclean re coffee gdb diff --git a/parsing.c b/parsing.c index c79c609..730eef7 100644 --- a/parsing.c +++ b/parsing.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/12/07 19:23:59 by erey-bet #+# #+# */ -/* Updated: 2022/12/07 19:24:04 by erey-bet ### ########.fr */ +/* Updated: 2022/12/08 11:22:53 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,6 +25,43 @@ void choice(long *tab, int y) 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; @@ -36,10 +73,7 @@ int parsing(int argc, char *argv[], long *tab) 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] = ' '; + argv = set_only_space(argv, i); x = 0; tmp = ft_split(argv[i], ' '); while (tmp[x] != NULL) @@ -47,13 +81,12 @@ int parsing(int argc, char *argv[], long *tab) if (ft_atoi_check(tmp[x])) tab[y++] = ft_atoi(tmp[x]); else - { - write(1, "Error\n", 6); - return (1); - } + return (put_error()); x++; } } + if (if_there_is_double(tab, y) || (y < argc - 1)) + return (put_error()); choice(tab, y); return (0); } diff --git a/push_swap.c b/push_swap.c index f885290..d4c7ec8 100644 --- a/push_swap.c +++ b/push_swap.c @@ -6,49 +6,12 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/11/23 16:48:12 by erey-bet #+# #+# */ -/* Updated: 2022/12/07 18:35:18 by erey-bet ### ########.fr */ +/* Updated: 2022/12/08 16:57:34 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -/*void ft_putchar(char c) -{ - write(1, &c, 1); -}*/ - -/*void print_stack(t_stack sa, t_stack sb) -{ - write(1, "A: ", 3); - for (int i = 0; i < sa.len; i++) - { - ft_putchar(sa.list[i] + '0'); - write(1, ", ", 2); - } - ft_putchar('\n'); - if (sb.len > 0) - { - write(1, "B: ", 3); - for (int i = 0; i < sb.len; i++) - { - ft_putchar(sb.list[i] + '0'); - write(1, ", ", 2); - } - ft_putchar('\n'); - } -}*/ - -/*void print_one_stack(t_stack s) -{ - write(1, "A: ", 3); - for (int i = 0; i < s.len; i++) - { - ft_putchar(s.list[i] + '0'); - write(1, ", ", 2); - } - ft_putchar('\n'); -}*/ - void post_push_swap(t_stack sa, t_stack sb, int x, int sa_len) { int i; diff --git a/push_swap.h b/push_swap.h index 8bfa827..79310a1 100644 --- a/push_swap.h +++ b/push_swap.h @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/11/23 16:51:31 by erey-bet #+# #+# */ -/* Updated: 2022/12/04 18:02:57 by erey-bet ### ########.fr */ +/* Updated: 2022/12/08 11:23:13 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,12 +35,12 @@ void push(t_stack *s_push, t_stack *s_receive, char *message); void rotate(t_stack *s, char *message); // Tools -int get_min(long *tab, int len); +int get_min(long *tab, int len); long *get_index(long *tab, int len); -int max_len_binary(t_stack s); -int check_sa(t_stack s); +int max_len_binary(t_stack s); +int check_sa(t_stack s); // Parsing -int parsing(int argc, char *argv[], long *tab); +int parsing(int argc, char *argv[], long *tab); #endif