From fe095d4b1ff05dcb31ece25d2fbf56e9a0ecdd8c Mon Sep 17 00:00:00 2001 From: tomoron Date: Thu, 25 Apr 2024 13:50:19 +0200 Subject: [PATCH] glhf pour les conflits --- srcs/check_syntax.c | 7 ++++++- srcs/check_syntax_utils.c | 4 +++- srcs/env.c | 4 +++- srcs/exec_bonus.c | 4 ++-- srcs/exit.c | 4 ++-- srcs/main.c | 11 +++++++---- srcs/pipe.c | 4 ++-- srcs/signal_handler.c | 7 ++----- srcs/utils.c | 4 ++-- srcs/utils_bonus.c | 3 ++- 10 files changed, 31 insertions(+), 21 deletions(-) diff --git a/srcs/check_syntax.c b/srcs/check_syntax.c index dcd9b1b..73999cf 100644 --- a/srcs/check_syntax.c +++ b/srcs/check_syntax.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/24 14:50:15 by tomoron #+# #+# */ -/* Updated: 2024/04/24 15:00:00 by tomoron ### ########.fr */ +/* Updated: 2024/04/25 13:15:19 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,12 +20,14 @@ int check_parens_syntax(t_cmd *cmd, t_cmd *last, t_env *env) if (last && is_cmd_type(last)) { ft_putstr_fd("minishell: syntax error\n", 2); + g_return_code = 2; return (0); } parsed_cmd = parsing_bonus(cmd->value); if (!parsed_cmd) { ft_putstr_fd("minishell: syntax error\n", 2); + g_return_code = 2; return (0); } tmp = check_cmds_syntax(parsed_cmd, env); @@ -110,6 +112,9 @@ int check_str_syntax(char *cmd) cmd++; } if (in_quote || in_dquote || parenthesis) + { + g_return_code = 2; ft_putstr_fd("minishell: syntax error\n", 2); + } return (!(in_quote || in_dquote || parenthesis)); } diff --git a/srcs/check_syntax_utils.c b/srcs/check_syntax_utils.c index 32cf586..012c979 100644 --- a/srcs/check_syntax_utils.c +++ b/srcs/check_syntax_utils.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/24 14:54:53 by tomoron #+# #+# */ -/* Updated: 2024/04/24 18:57:48 by marde-vr ### ########.fr */ +/* Updated: 2024/04/25 13:15:00 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,7 @@ void print_syntax_error_bonus(t_cmd *cmd) if (cmd->cmd_type == CMD || cmd->cmd_type == PAREN) return ; ft_printf_fd(2, "minishell : syntax error near unexpected token `"); + g_return_code = 2; if (cmd->cmd_type == AND) ft_printf_fd(2, "&&"); if (cmd->cmd_type == OR) @@ -34,6 +35,7 @@ int check_tokens_syntax(t_cmd *cmd, t_cmd *last, t_env *env) if (last && is_cmd_type(last)) { + g_return_code = 2; ft_putstr_fd("minishell : syntax error\n", 2); return (0); } diff --git a/srcs/env.c b/srcs/env.c index 9ca357f..8f18571 100644 --- a/srcs/env.c +++ b/srcs/env.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/24 10:58:36 by marde-vr #+# #+# */ -/* Updated: 2024/04/24 10:59:12 by marde-vr ### ########.fr */ +/* Updated: 2024/04/25 13:49:47 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,9 +56,11 @@ void sort_env(t_env *env) void print_env_declare(t_msh *msh, t_env *env_orig) { t_env *env; + t_env *start; env = dup_env(env_orig); sort_env(env); + start = env; if (!msh->out_fd) msh->out_fd = 1; while (env) diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index 4acc363..0196843 100755 --- a/srcs/exec_bonus.c +++ b/srcs/exec_bonus.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ -/* Updated: 2024/04/24 21:31:10 by tomoron ### ########.fr */ +/* Updated: 2024/04/25 13:44:26 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -108,7 +108,7 @@ void end_execution(t_msh *msh, int cmd_count) free(msh->fds); signal(SIGINT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive); - set_echoctl(0); + //set_echoctl(0); } void exec_commands(t_msh *msh) diff --git a/srcs/exit.c b/srcs/exit.c index f350def..c370060 100755 --- a/srcs/exit.c +++ b/srcs/exit.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */ -/* Updated: 2024/04/24 19:14:52 by tomoron ### ########.fr */ +/* Updated: 2024/04/25 13:26:35 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,7 +45,7 @@ int exit_bt(t_msh *msh) else { get_exit_bt_return_code(msh, &exit_code); - set_echoctl(msh->echoctl); + //set_echoctl(msh->echoctl); free_msh(msh); exit(exit_code); } diff --git a/srcs/main.c b/srcs/main.c index d2b5201..d8dd876 100755 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ -/* Updated: 2024/04/24 19:10:38 by tomoron ### ########.fr */ +/* Updated: 2024/04/25 13:40:02 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -82,6 +82,8 @@ t_env *add_shlvl(t_env *env) else nb = ft_atoi(tmp); nb++; + if(nb < 0) + nb = 0; env = export_set_env(env, ft_strdup("SHLVL"), ft_itoa(nb), 0); return (env); } @@ -98,11 +100,12 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp) (*msh)->env = get_env(envp); (*msh)->env = add_shlvl((*msh)->env); tcgetattr(1, &t_p); - (*msh)->echoctl = t_p.c_lflag & ECHOCTL; + //(*msh)->echoctl = t_p.c_lflag & ECHOCTL; + rl_catch_signals = 0; signal(SIGINT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive); - if (set_echoctl(0)) - ft_exit(*msh, 1); + //if (set_echoctl(0)) + // ft_exit(*msh, 1); return (0); } diff --git a/srcs/pipe.c b/srcs/pipe.c index f81b6ee..b2ca63c 100755 --- a/srcs/pipe.c +++ b/srcs/pipe.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */ -/* Updated: 2024/04/24 19:13:12 by tomoron ### ########.fr */ +/* Updated: 2024/04/25 13:26:52 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -73,7 +73,7 @@ void execute_command(t_msh *msh, char **cmd_args) env = env_to_char_tab(msh->env); if (env) { - set_echoctl(msh->echoctl); + //set_echoctl(msh->echoctl); if (execve(msh->tokens->value, cmd_args, env)) perror("execve"); } diff --git a/srcs/signal_handler.c b/srcs/signal_handler.c index 67284d2..d55ca96 100755 --- a/srcs/signal_handler.c +++ b/srcs/signal_handler.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */ -/* Updated: 2024/04/24 19:14:06 by tomoron ### ########.fr */ +/* Updated: 2024/04/25 13:46:40 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,13 +17,11 @@ void signal_handler_interactive(int signum) if (signum == SIGINT) { g_return_code = 130; - printf("%s%s^C\n", rl_prompt, rl_line_buffer); rl_replace_line("", 0); + printf("^C\n"); rl_on_new_line(); rl_redisplay(); } - else if (signum == SIGQUIT) - printf("%s%s", rl_prompt, rl_line_buffer); } void *here_doc_variables(int write, void *data) @@ -43,7 +41,6 @@ void signal_handler_here_doc(int signum) if (signum == SIGINT) { - printf("%s%s^C\n", rl_prompt, rl_line_buffer); msh = here_doc_variables(0, 0); close(msh->in_fd); ft_exit(msh, 1); diff --git a/srcs/utils.c b/srcs/utils.c index 816aaaa..53bc139 100755 --- a/srcs/utils.c +++ b/srcs/utils.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */ -/* Updated: 2024/04/24 19:14:28 by tomoron ### ########.fr */ +/* Updated: 2024/04/25 13:44:14 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ void ft_exit(t_msh *msh, int exit_code) { - set_echoctl(msh->echoctl); + //set_echoctl(msh->echoctl); free_msh(msh); exit(exit_code); } diff --git a/srcs/utils_bonus.c b/srcs/utils_bonus.c index 73e8101..9812dbf 100755 --- a/srcs/utils_bonus.c +++ b/srcs/utils_bonus.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/27 17:19:27 by tomoron #+# #+# */ -/* Updated: 2024/04/24 18:59:26 by marde-vr ### ########.fr */ +/* Updated: 2024/04/25 13:13:55 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ t_token *parsing_syntax_error(t_token *res) { free_token(res); ft_putstr_fd("minishell: syntax error\n", 2); + g_return_code = 0; return ((void *)1); }