From 5810e1c970e2b3d944533dee7ba6a9ef7ad8c459 Mon Sep 17 00:00:00 2001 From: tomoron Date: Wed, 24 Apr 2024 19:17:24 +0200 Subject: [PATCH] echoctl --- srcs/.lst_token.c.swp | Bin 12288 -> 0 bytes srcs/exec_bonus.c | 3 ++- srcs/exit.c | 3 ++- srcs/main.c | 5 ++++- srcs/minishell.h | 4 +++- srcs/pipe.c | 3 ++- srcs/signal_handler.c | 21 ++++++++++++++++++++- srcs/utils.c | 3 ++- 8 files changed, 35 insertions(+), 7 deletions(-) delete mode 100644 srcs/.lst_token.c.swp diff --git a/srcs/.lst_token.c.swp b/srcs/.lst_token.c.swp deleted file mode 100644 index bbfb795e564e737d36bb4bf3e39a4fb7297ff6b8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2KWG#|6vm&iaidX5AcfT=2l4(Sw|AF|#*GG15fucRSXg*$?&i#yz1^_87ZZb| zP&;c23wyP&6vSE-1i`}ELc~I`5Ul-ncV=@Z!30gCya~U|?97{Q-uw2h2$}iP7&qVd%ovJE5B`(Ge?WnitS$WI*x41V$soA9$uZ$2=p0#n4+a+by>hEJ(*O1HT@aP7u~YZ&A9%`sTVk%MP#uTR6}On-kLm zG+8OfU-iuBh!`52+hP+hvjgk^JHQUG1MC1hzz(nj?7;uzK)AGv)=^NODr#EwyMF1_ zBX{foJHQUG1MC1hzz(nj>;OB!4zL6406XvxI$$@5KJOv=Xdrp~|6l+8|MURSRWJZv z>?c|ThrsIrq7`r$yx&K37u*4D;DDoG3XFjvFbIC^CHf9Nf_LC8cmy7Td*BAR4z7T6 zpbUlqfp7gpU%?mf3cLi*!87mx+z0F6I%t9m;4H|4VK4}GgCD5xJNN{mT0aAB>;OB! z4zL6406V}A{I3q&BEy$q$9F}xl$#*~&qjQqQk)PaJR7)@DYNlRv>dM|0TZ*XTnTkp z9G6_hOrn$Jc+VR4wVEQC7h_{0mQw-0XfE4MNA`$nxp?KbdPxKsI4?aeM{A_6h#L8* z7M)|#i+oZVQI`>Ewe^ngOE*j_^<@xwpr(;!PXLx~EVLXcvOUu|>e>)XM;h96NJce9 z`HrYmuog_rY9r#ldqx()SW%;Y#+fYQFN?i+f s-45Tbq*btzP&G(8Ex28ko;b_Wk{Cq|tA8cfqpltj!5#ae;7e!HPf}y8ng9R* 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); }