echoctl
This commit is contained in:
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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");
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user