From 99e229192d46c84943a84f6809c2f2f019f73edf Mon Sep 17 00:00:00 2001 From: Tom Moron Date: Tue, 13 Feb 2024 16:08:47 +0100 Subject: [PATCH] commit --- ft_parsing.c | 18 +++++++++++++++--- ft_parsing_var.c | 4 ++-- minishell.h | 3 ++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ft_parsing.c b/ft_parsing.c index 947a91d..17b49b3 100755 --- a/ft_parsing.c +++ b/ft_parsing.c @@ -6,11 +6,16 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */ -/* Updated: 2024/02/12 14:52:13 by tomoron ### ########.fr */ +/* Updated: 2024/02/13 15:50:08 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +int ft_is_cmd_char(char c) +{ + return(!ft_isspace(c) && c != '|' && c != '&'); +} + char *ft_get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) { char *res; @@ -20,7 +25,7 @@ char *ft_get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) while (ft_isspace(**cmd)) (*cmd)++; res = ft_calloc(ft_get_token_len(*cmd, env) + 1, 1); - while (res && **cmd && (!ft_isspace(**cmd) || *in_quote || *in_dquote)) + while (res && **cmd && (ft_is_cmd_char(**cmd) || *in_quote || *in_dquote)) { if (**cmd == '"' && !*in_quote) *in_dquote = !*in_dquote; @@ -41,7 +46,14 @@ char *ft_get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) t_token_type ft_get_token_type(char *command) { - (void)command; + while (ft_isspace(*command)) + command++; + if(command[0] == '|' && command[1] == '|') + return(OR); + if(command[0] == '&' && command[1] == '&') + return(AND); + if(command[0] == '|') + return(PIPE); return (ARG); } diff --git a/ft_parsing_var.c b/ft_parsing_var.c index 73557e9..ce89d2d 100755 --- a/ft_parsing_var.c +++ b/ft_parsing_var.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */ -/* Updated: 2024/02/12 20:11:18 by tomoron ### ########.fr */ +/* Updated: 2024/02/13 15:47:33 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,7 +50,7 @@ int ft_get_token_len(char *command, t_env *env) in_quote = 0; in_dquote = 0; res = 0; - while (*command && (!ft_isspace(*command) || in_quote || in_dquote)) + while (*command && (ft_is_cmd_char(*command) || in_quote || in_dquote)) { if (*command == '"' && !in_quote) in_dquote = !in_dquote; diff --git a/minishell.h b/minishell.h index d383031..dbfb3aa 100755 --- a/minishell.h +++ b/minishell.h @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/02/11 22:54:49 by tomoron ### ########.fr */ +/* Updated: 2024/02/13 15:49:02 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,4 +56,5 @@ int ft_add_var_to_str(char *res, char **command, t_env *env); int get_var_name_len(char *command); char *ft_getenv(t_env *env, char *var_name); int ft_pwd(void); +int ft_is_cmd_char(char c); #endif