From 9c4dfafdf703c4905fca7799b47f7a09b9b2e8de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sun, 31 Mar 2024 21:09:46 +0200 Subject: [PATCH] Starting the separation between commands & args and the operators --- includes/minishell.h | 11 +++---- includes/type_rust.h | 40 ++++++++++++++----------- libft/ft_split.c | 30 +++++++++---------- note_raph.txt | 1 + sources/ft_exit.c | 4 +-- sources/main.c | 69 +++++++++++++++++++++++++++----------------- 6 files changed, 89 insertions(+), 66 deletions(-) create mode 100644 note_raph.txt diff --git a/includes/minishell.h b/includes/minishell.h index d18a8124..f8224d92 100644 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 14:41:15 by rparodi #+# #+# */ -/* Updated: 2024/03/31 19:52:56 by rparodi ### ########.fr */ +/* Updated: 2024/03/31 21:04:32 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,9 +27,10 @@ # include # include -i32 main(void); -i32 ft_strcmp(const char *s1, const char *s2); -void ft_exit(i8 *str, u8 exit_status); -i8 **ft_split(i8 const *s, i8 c); +t_i32 main(void); +t_i32 ft_strcmp(const char *s1, const char *s2); +t_i32 ft_check_type_operators(t_i8 **operators); +void ft_exit(t_str str, t_u8 exit_status); +t_str *ft_split(t_const_str s, t_i8 c); #endif diff --git a/includes/type_rust.h b/includes/type_rust.h index 2c9166b2..61296343 100644 --- a/includes/type_rust.h +++ b/includes/type_rust.h @@ -6,33 +6,39 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 14:44:20 by rparodi #+# #+# */ -/* Updated: 2024/03/29 11:44:40 by rparodi ### ########.fr */ +/* Updated: 2024/03/31 20:53:56 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef TYPE_RUST_H #define TYPE_RUST_H -#include +# include +# include +# include -# define bool int -# define true 1 -# define false 0 +typedef char *t_str; +typedef const char *t_const_str; -# define u8 unsigned char -# define u16 unsigned short -# define u32 unsigned int -# define u64 unsigned long long +typedef unsigned char t_u8; +typedef char t_i8; +typedef unsigned short t_u16; +typedef short t_i16; +typedef int t_i32; +typedef unsigned int t_u32; +typedef unsigned long long t_u64; +typedef long long t_i64; +typedef ssize_t t_isize; +typedef size_t t_usize; -# define i8 char -# define i16 short -# define i32 int -# define i64 long long +typedef float t_f32; +typedef double t_f64; -# define usize size_t -# define isize ssize_t +typedef int t_file; -# define f32 float -# define f64 double +typedef bool t_error; + +# define ERROR 1 +# define NO_ERROR 0 #endif diff --git a/libft/ft_split.c b/libft/ft_split.c index 0454e507..3927fb48 100644 --- a/libft/ft_split.c +++ b/libft/ft_split.c @@ -6,16 +6,16 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/09 13:56:02 by rparodi #+# #+# */ -/* Updated: 2024/03/31 19:35:26 by rparodi ### ########.fr */ +/* Updated: 2024/03/31 21:07:40 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/minishell.h" -static int count_words(const char *str, char sep) +static t_i32 count_words(t_const_str str, t_i8 sep) { - int i; - int count; + t_i32 i; + t_i32 count; i = 0; count = 0; @@ -33,13 +33,13 @@ static int count_words(const char *str, char sep) return (count); } -static char *ft_strndup(const char *s, int j) +static t_str ft_strndup(t_const_str s, t_i32 j) { - int i; - char *str; + t_i32 i; + t_str str; i = 0; - str = (char *)malloc((j + 1)); + str = (t_str)malloc((j + 1)); if (!str) return (NULL); while (s[i] && i < j) @@ -51,10 +51,10 @@ static char *ft_strndup(const char *s, int j) return (str); } -static char **ext_w(char **words_array, const char *str, char sep, int size) +static t_str *ext_w(t_str *words_array, t_const_str str, t_i8 sep, t_i32 size) { - int i; - int j; + t_i32 i; + t_i32 j; i = 0; j = 0; @@ -74,13 +74,13 @@ static char **ext_w(char **words_array, const char *str, char sep, int size) return (words_array); } -char **ft_split(char const *s, char c) +t_str *ft_split(t_const_str s, t_i8 c) { - int size; - char **words_array; + t_i32 size; + t_str *words_array; size = count_words(s, c); - words_array = (char **)malloc(sizeof(char *) * (size + 1)); + words_array = (t_str *)malloc(sizeof(char *) * (size + 1)); if (!words_array) return (NULL); if (size == 0) diff --git a/note_raph.txt b/note_raph.txt new file mode 100644 index 00000000..e04cc25b --- /dev/null +++ b/note_raph.txt @@ -0,0 +1 @@ +Alors pour le coup, il faut que j'arrive a separer les strings par commande puis a chaque sep regarder les autres cmd (bisous lpb si tu passe par la ;)) diff --git a/sources/ft_exit.c b/sources/ft_exit.c index cd21b254..53af92a5 100644 --- a/sources/ft_exit.c +++ b/sources/ft_exit.c @@ -6,13 +6,13 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */ -/* Updated: 2024/03/29 14:46:18 by rparodi ### ########.fr */ +/* Updated: 2024/03/31 20:54:49 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/minishell.h" -void ft_exit(i8 *str, u8 exit_status) +void ft_exit(t_str str, t_u8 exit_status) { free(str); printf("exit\n"); diff --git a/sources/main.c b/sources/main.c index 8785b967..51d773f3 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,55 +6,70 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */ -/* Updated: 2024/03/31 20:08:28 by rparodi ### ########.fr */ +/* Updated: 2024/03/31 21:02:40 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/minishell.h" -i32 ft_check_type_cmd(i8 **cmd) +t_i32 ft_check_type_operators(t_str *operators) { - usize j; + t_usize i; - j = 0; - while (cmd[j]) + i = 0; + while (operators[i]) { - if (ft_strcmp(cmd[j], ">") == 0) + if (ft_strcmp(operators[i], ">") == 0) printf("Have to redirect in the file\n"); - else if (ft_strcmp(cmd[j], ">>") == 0) + else if (ft_strcmp(operators[i], ">>") == 0) printf("Have to redirect at the end of the file after\n"); - else if (ft_strcmp(cmd[j], ">&") == 0) + else if (ft_strcmp(operators[i], ">&") == 0) printf("Have to redirect the stdout in the file\n"); - else if (ft_strcmp(cmd[j], "<") == 0) + else if (ft_strcmp(operators[i], "<") == 0) printf("Have to redirect at the end of the file before\n"); - else if (ft_strcmp(cmd[j], "<<") == 0) + else if (ft_strcmp(operators[i], "<<") == 0) printf("Have to redirect at the end of the file after\n"); - else if (ft_strcmp(cmd[j], "<&") == 0) + else if (ft_strcmp(operators[i], "<&") == 0) printf("Have to redirect the stdout in the file\n"); - else if (ft_strcmp(cmd[j], ";") == 0) + else if (ft_strcmp(operators[i], ";") == 0) printf("Have to execute one more command\n"); - else if (ft_strcmp(cmd[j], ";") == 0) + else if (ft_strcmp(operators[i], ";") == 0) printf("Have to execute one more command\n"); - else if (ft_strcmp(cmd[j], "|") == 0) - printf("I have to pipe a cmd !\n"); - else if (ft_strcmp(cmd[j], "||") == 0) + else if (ft_strcmp(operators[i], "|") == 0) + printf("I have to pipe a operators !\n"); + else if (ft_strcmp(operators[i], "||") == 0) printf("Or something\n"); - else if (ft_strcmp(cmd[j], "&&") == 0) + else if (ft_strcmp(operators[i], "&&") == 0) printf("Only if the first has exit status 0\n"); - else if (ft_strcmp(cmd[j], "&") == 0) + else if (ft_strcmp(operators[i], "&") == 0) printf("Parreil mais chelou\n"); else - printf("Error!\n"); - j++; + return (0); + i++; } return (1); } -void ft_take_cmd(void) +void ft_check(char **input) { - i32 i; - i8 *user_input = NULL; - i8 **args = NULL; + t_usize i; + + i = 0; + while (input[i] != NULL) + { + if (ft_check_type_operators(input) == 1) + printf("Operateur\n"); + else + printf("Commande ou args\n"); + i++; + } +} + +void ft_take_args(void) +{ + t_i32 i; + t_str user_input = NULL; + t_str *args = NULL; i = 0; while (i < 10000000) @@ -65,14 +80,14 @@ void ft_take_cmd(void) args = ft_split(user_input, ' '); if (!user_input) exit(1); - ft_check_type_cmd(args); + ft_check(args); add_history(user_input); free(user_input); i++; } } -i32 main(void) +t_i32 main(void) { - ft_take_cmd(); + ft_take_args(); }