From d209f7de5a22d075e1b3b25b0615fd2951f6e51e Mon Sep 17 00:00:00 2001 From: Tom Moron Date: Thu, 15 Feb 2024 17:03:05 +0100 Subject: [PATCH] AAAAAAAAAAAAAA --- Makefile | 3 ++- debug.c | 32 ++++++++++++++++++++++++++++++++ echo.c | 4 ++-- exit.c | 11 ++++++----- main.c | 3 ++- minishell.h | 3 ++- parsing.c | 25 +++++++++++++++++-------- 7 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 debug.c diff --git a/Makefile b/Makefile index 7dc8a80..5eb1183 100755 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: marde-vr +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/07/28 00:35:01 by tomoron #+# #+# # -# Updated: 2024/02/13 16:22:36 by marde-vr ### ########.fr # +# Updated: 2024/02/15 14:44:14 by tomoron ### ########.fr # # # # **************************************************************************** # @@ -20,6 +20,7 @@ SRCS = main.c\ echo.c\ pwd.c\ parsing.c\ + debug.c\ parsing_var.c OBJS = $(SRCS:.c=.o) diff --git a/debug.c b/debug.c new file mode 100644 index 0000000..eeb68a1 --- /dev/null +++ b/debug.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* debug.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/15 14:16:47 by tomoron #+# #+# */ +/* Updated: 2024/02/15 14:45:29 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void print_parsed_cmd(t_cmd *cmd) +{ + while(cmd) + { + printf("["); + if(cmd->type == ARG) + printf("ARG : %s",cmd->token); + else if(cmd->type == PIPE) + printf("PIPE"); + else if(cmd->type == OR) + printf("OR"); + else if(cmd->type == AND) + printf("AND"); + printf("] "); + cmd = cmd->next; + } + printf("\n"); +} diff --git a/echo.c b/echo.c index 0c06f3c..9b5fc55 100755 --- a/echo.c +++ b/echo.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */ -/* Updated: 2024/02/13 16:11:20 by marde-vr ### ########.fr */ +/* Updated: 2024/02/14 12:36:02 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ int echo(t_cmd *args) put_nl = 0; args = args->next; } - while (args) + while (args && args->type == ARG) { ft_putstr_fd(args->token, STDOUT_FILENO); if (args->next) diff --git a/exit.c b/exit.c index 75920ca..f656bf3 100755 --- a/exit.c +++ b/exit.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */ -/* Updated: 2024/02/13 16:24:18 by marde-vr ### ########.fr */ +/* Updated: 2024/02/14 12:44:03 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,15 +27,16 @@ void ft_exit(t_cmd *args, t_env *env) start = args; args = args->next; ft_printf("exit\n"); - if (args && args->next && ft_strisnbr(args->token)) + if (args && args->next && args->next->type == ARG + && ft_strisnbr(args->token)) ft_putstr_fd("minishell: exit: too many arguments\n", 2); else { - if (args && !ft_strisnbr(args->token)) + if (args && args->type == ARG && !ft_strisnbr(args->token)) print_numeric_arg_err(args->token); - if (args) + if (args && args->type == ARG) exit_code = (unsigned char)ft_atoi(args->token); - else if (args && !ft_strisnbr(args->token)) + else if (args && args->type == ARG && !ft_strisnbr(args->token)) exit_code = 2; else exit_code = g_return_code; diff --git a/main.c b/main.c index 5137223..e076de3 100755 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ -/* Updated: 2024/02/13 16:16:46 by marde-vr ### ########.fr */ +/* Updated: 2024/02/15 14:13:57 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,6 +81,7 @@ int main(int argc, char **argv, char **envp) add_history(command); parsed_cmd = parse_command(command, env); free(command); + print_parsed_cmd(parsed_cmd);//debug exec_command(parsed_cmd, env); free_cmd(parsed_cmd); } diff --git a/minishell.h b/minishell.h index cc5582c..a197428 100755 --- a/minishell.h +++ b/minishell.h @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/02/13 16:21:55 by marde-vr ### ########.fr */ +/* Updated: 2024/02/15 14:43:57 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,4 +57,5 @@ int get_var_name_len(char *command); char *ft_get_env(t_env *env, char *var_name); int pwd(void); int is_cmd_char(char c); +void print_parsed_cmd(t_cmd *cmd);//debug #endif diff --git a/parsing.c b/parsing.c index eecd820..946d1f9 100755 --- a/parsing.c +++ b/parsing.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */ -/* Updated: 2024/02/13 16:25:15 by marde-vr ### ########.fr */ +/* Updated: 2024/02/13 18:22:38 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" @@ -44,16 +44,25 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) return (res); } -t_token_type get_token_type(char *command) +t_token_type get_token_type(char **command) { - while (ft_isspace(*command)) - command++; - if(command[0] == '|' && command[1] == '|') + while (ft_isspace(**command)) + (*command)++; + if((*command)[0] == '|' && (*command)[1] == '|') + { + (*command) += 2; return(OR); - if(command[0] == '&' && command[1] == '&') + } + if((*command)[0] == '&' && (*command)[1] == '&') + { + (*command) += 2; return(AND); - if(command[0] == '|') + } + if((*command)[0] == '|') + { + (*command) += 1; return(PIPE); + } return (ARG); } @@ -70,7 +79,7 @@ t_cmd *parse_command(char *command, t_env *env) res = 0; while (command && *command) { - type = get_token_type(command); + type = get_token_type(&command); if (type == ARG) token = get_token(&command, &in_quote, &in_dquote, env); else