diff --git a/srcs/.lst_token.c.swp b/srcs/.lst_token.c.swp deleted file mode 100644 index bbfb795..0000000 Binary files a/srcs/.lst_token.c.swp and /dev/null differ diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index 4d83a4b..3a55a51 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 15:22:20 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 19:15:13 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -108,6 +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); } void exec_commands(t_msh *msh) diff --git a/srcs/exit.c b/srcs/exit.c index 9dd5f3a..f350def 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 15:17:53 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 19:14:52 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,6 +45,7 @@ int exit_bt(t_msh *msh) else { get_exit_bt_return_code(msh, &exit_code); + set_echoctl(msh->echoctl); free_msh(msh); exit(exit_code); } diff --git a/srcs/main.c b/srcs/main.c index 65393b7..d2b5201 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 15:22:06 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 19:10:38 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -98,8 +98,11 @@ 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; signal(SIGINT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive); + if (set_echoctl(0)) + ft_exit(*msh, 1); return (0); } diff --git a/srcs/minishell.h b/srcs/minishell.h index 440a861..f9cc8b0 100755 --- a/srcs/minishell.h +++ b/srcs/minishell.h @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/04/24 15:17:35 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 19:11:36 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,6 +71,7 @@ typedef struct s_msh t_cmd_type in_type; t_cmd_type out_type; int in_fd; + int echoctl; int out_fd; int locked_return_code; char *here_doc_filename; @@ -82,6 +83,7 @@ t_cmd *cmd_add_back(t_cmd *res, char *cmd, t_cmd_type type); t_env *export_set_env(t_env *env, char *name, char *value, int append); void *here_doc_variables(int write, void *data); int add_var_to_str(char *res, char **command, t_env *env); +int set_echoctl(int value); void find_cmd_path(t_msh *msh, char **paths, int *found); t_env *env_add_back(t_env *env, char *name, char *value); t_token *parse_cmds_to_token(t_cmd *command, t_env *env); diff --git a/srcs/pipe.c b/srcs/pipe.c index 08f220e..f81b6ee 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 15:17:58 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 19:13:12 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -73,6 +73,7 @@ void execute_command(t_msh *msh, char **cmd_args) env = env_to_char_tab(msh->env); if (env) { + 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 4a01273..67284d2 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 15:17:24 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 19:14:06 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,6 +50,25 @@ void signal_handler_here_doc(int signum) } } +int set_echoctl(int value) +{ + struct termios t_p; + + if (!isatty(1)) + return (0); + if (tcgetattr(1, &t_p)) + return (1); + if (((t_p.c_lflag & ECHOCTL) != 0) == value) + return (0); + if (value) + t_p.c_lflag = t_p.c_lflag | ECHOCTL; + else + t_p.c_lflag = t_p.c_lflag & (~ECHOCTL); + if (tcsetattr(1, TCSANOW, &t_p)) + return (1); + return (0); +} + void signal_handler_command(int signum) { (void)signum; diff --git a/srcs/utils.c b/srcs/utils.c index 145b55a..816aaaa 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 15:22:11 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 19:14:28 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ void ft_exit(t_msh *msh, int exit_code) { + set_echoctl(msh->echoctl); free_msh(msh); exit(exit_code); }