heredoc ctrl+C
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
|
/* 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)
|
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;
|
g_return_code = 0;
|
||||||
msh->fds[i] = ft_calloc(2, sizeof(int *));
|
msh->fds[i] = ft_calloc(2, sizeof(int *));
|
||||||
if (!msh->fds[i])
|
if (!msh->fds[i])
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */
|
/* 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)
|
void here_doc_child(t_msh *msh, char *eof)
|
||||||
{
|
{
|
||||||
|
rl_catch_signals = 1;
|
||||||
here_doc_variables(1, msh);
|
here_doc_variables(1, msh);
|
||||||
signal(SIGINT, signal_handler_here_doc);
|
signal(SIGINT, signal_handler_here_doc);
|
||||||
get_here_doc_input(msh, eof);
|
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);
|
signal(SIGQUIT, signal_handler_interactive);
|
||||||
close(msh->in_fd);
|
close(msh->in_fd);
|
||||||
if (WIFEXITED(status) && WEXITSTATUS(status))
|
if (WIFEXITED(status) && WEXITSTATUS(status))
|
||||||
|
{
|
||||||
unlink(here_doc_file);
|
unlink(here_doc_file);
|
||||||
|
msh->in_fd = -1;
|
||||||
|
g_return_code = 130;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
msh->in_fd = open(here_doc_file, O_RDWR, 0644);
|
msh->in_fd = open(here_doc_file, O_RDWR, 0644);
|
||||||
if (msh->in_fd == -1 && !(WIFEXITED(status) && WEXITSTATUS(status)))
|
if (msh->in_fd == -1 && !(WIFEXITED(status) && WEXITSTATUS(status)))
|
||||||
perror("open");
|
perror("open");
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */
|
/* 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)
|
void ambiguous_redirect(char *str, t_msh *msh)
|
||||||
{
|
{
|
||||||
ft_printf_fd(2, "minishell: %s: ambiguous redirect\n", str);
|
ft_printf_fd(2, "minishell: %s: ambiguous redirect\n", str);
|
||||||
msh->in_fd = -2;
|
msh->in_fd = -1;
|
||||||
g_return_code = 1;
|
g_return_code = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ int open_input_file(t_msh *msh, t_cmd **cur_token)
|
|||||||
}
|
}
|
||||||
free_token(filename);
|
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)
|
int get_in_type(t_msh *msh, t_cmd *t_strt, t_cmd *tokens, int here_doc)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
/* 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)
|
int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
|
||||||
{
|
{
|
||||||
struct termios t_p;
|
|
||||||
|
|
||||||
*msh = ft_calloc(1, sizeof(t_msh));
|
*msh = ft_calloc(1, sizeof(t_msh));
|
||||||
if (!*msh)
|
if (!*msh)
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -99,13 +97,9 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
|
|||||||
(void)argv;
|
(void)argv;
|
||||||
(*msh)->env = get_env(envp);
|
(*msh)->env = get_env(envp);
|
||||||
(*msh)->env = add_shlvl((*msh)->env);
|
(*msh)->env = add_shlvl((*msh)->env);
|
||||||
tcgetattr(1, &t_p);
|
|
||||||
//(*msh)->echoctl = t_p.c_lflag & ECHOCTL;
|
|
||||||
rl_catch_signals = 0;
|
rl_catch_signals = 0;
|
||||||
signal(SIGINT, signal_handler_interactive);
|
signal(SIGINT, signal_handler_interactive);
|
||||||
signal(SIGQUIT, signal_handler_interactive);
|
signal(SIGQUIT, signal_handler_interactive);
|
||||||
//if (set_echoctl(0))
|
|
||||||
// ft_exit(*msh, 1);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/19 14:09:44 by tomoron #+# #+# */
|
/* 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)
|
else if (cur_cmd && cur_cmd->cmd_type == PIPE)
|
||||||
msh->out_type = PIPE;
|
msh->out_type = PIPE;
|
||||||
return (ret || msh->in_fd == -2);
|
return (ret || msh->in_fd == -1);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -42,6 +42,9 @@ void signal_handler_here_doc(int signum)
|
|||||||
if (signum == SIGINT)
|
if (signum == SIGINT)
|
||||||
{
|
{
|
||||||
msh = here_doc_variables(0, 0);
|
msh = here_doc_variables(0, 0);
|
||||||
|
rl_on_new_line();
|
||||||
|
printf("\n");
|
||||||
|
if(msh->in_fd > 2)
|
||||||
close(msh->in_fd);
|
close(msh->in_fd);
|
||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
}
|
}
|
||||||
@ -49,6 +52,9 @@ void signal_handler_here_doc(int signum)
|
|||||||
|
|
||||||
int set_echoctl(int value)
|
int set_echoctl(int value)
|
||||||
{
|
{
|
||||||
|
printf("nope");
|
||||||
|
(void)value;
|
||||||
|
/*
|
||||||
struct termios t_p;
|
struct termios t_p;
|
||||||
|
|
||||||
if (!isatty(1))
|
if (!isatty(1))
|
||||||
@ -64,6 +70,8 @@ int set_echoctl(int value)
|
|||||||
if (tcsetattr(1, TCSANOW, &t_p))
|
if (tcsetattr(1, TCSANOW, &t_p))
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
|
*/
|
||||||
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void signal_handler_command(int signum)
|
void signal_handler_command(int signum)
|
||||||
|
Reference in New Issue
Block a user