heredoc ctrl+C

This commit is contained in:
2024-04-25 18:41:02 +02:00
parent 15f8e10829
commit 2af75c9497
6 changed files with 27 additions and 17 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
/* Updated: 2024/04/25 13:44:26 by tomoron ### ########.fr */
/* Updated: 2024/04/25 18:21:20 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -72,6 +72,8 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
void exec_command(t_msh *msh, int i, int cmd_count)
{
if(msh->in_fd == -1 || msh->out_fd == -1)
return ;
g_return_code = 0;
msh->fds[i] = ft_calloc(2, sizeof(int *));
if (!msh->fds[i])

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */
/* Updated: 2024/04/25 10:16:53 by tomoron ### ########.fr */
/* Updated: 2024/04/25 18:38:34 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,6 +37,7 @@ void get_here_doc_input(t_msh *msh, char *eof)
void here_doc_child(t_msh *msh, char *eof)
{
rl_catch_signals = 1;
here_doc_variables(1, msh);
signal(SIGINT, signal_handler_here_doc);
get_here_doc_input(msh, eof);
@ -55,7 +56,12 @@ void here_doc_signal(t_msh *msh, int child_pid, char *here_doc_file)
signal(SIGQUIT, signal_handler_interactive);
close(msh->in_fd);
if (WIFEXITED(status) && WEXITSTATUS(status))
{
unlink(here_doc_file);
msh->in_fd = -1;
g_return_code = 130;
return ;
}
msh->in_fd = open(here_doc_file, O_RDWR, 0644);
if (msh->in_fd == -1 && !(WIFEXITED(status) && WEXITSTATUS(status)))
perror("open");

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */
/* Updated: 2024/04/24 21:30:46 by tomoron ### ########.fr */
/* Updated: 2024/04/25 18:39:48 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,7 +36,7 @@ void redirect_input(t_msh *msh, int i, char **cmd_args)
void ambiguous_redirect(char *str, t_msh *msh)
{
ft_printf_fd(2, "minishell: %s: ambiguous redirect\n", str);
msh->in_fd = -2;
msh->in_fd = -1;
g_return_code = 1;
}
@ -66,7 +66,7 @@ int open_input_file(t_msh *msh, t_cmd **cur_token)
}
free_token(filename);
}
return (msh->in_fd == -2);
return (msh->in_fd == -1);
}
int get_in_type(t_msh *msh, t_cmd *t_strt, t_cmd *tokens, int here_doc)

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
/* Updated: 2024/04/25 13:40:02 by tomoron ### ########.fr */
/* Updated: 2024/04/25 18:38:02 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -90,8 +90,6 @@ t_env *add_shlvl(t_env *env)
int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
{
struct termios t_p;
*msh = ft_calloc(1, sizeof(t_msh));
if (!*msh)
exit(1);
@ -99,13 +97,9 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
(void)argv;
(*msh)->env = get_env(envp);
(*msh)->env = add_shlvl((*msh)->env);
tcgetattr(1, &t_p);
//(*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);
return (0);
}

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/19 14:09:44 by tomoron #+# #+# */
/* Updated: 2024/04/24 21:31:01 by tomoron ### ########.fr */
/* Updated: 2024/04/25 18:39:52 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -91,5 +91,5 @@ int get_out_type(t_msh *msh, t_cmd *cur_cmd)
}
else if (cur_cmd && cur_cmd->cmd_type == PIPE)
msh->out_type = PIPE;
return (ret || msh->in_fd == -2);
return (ret || msh->in_fd == -1);
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
/* Updated: 2024/04/25 13:46:40 by tomoron ### ########.fr */
/* Updated: 2024/04/25 18:39:18 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,18 +37,24 @@ void *here_doc_variables(int write, void *data)
void signal_handler_here_doc(int signum)
{
t_msh *msh;
t_msh *msh;
if (signum == SIGINT)
{
msh = here_doc_variables(0, 0);
close(msh->in_fd);
rl_on_new_line();
printf("\n");
if(msh->in_fd > 2)
close(msh->in_fd);
ft_exit(msh, 1);
}
}
int set_echoctl(int value)
{
printf("nope");
(void)value;
/*
struct termios t_p;
if (!isatty(1))
@ -64,6 +70,8 @@ int set_echoctl(int value)
if (tcsetattr(1, TCSANOW, &t_p))
return (1);
return (0);
*/
return(0);
}
void signal_handler_command(int signum)