2023-03-29 13:07:57 -04:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* signal.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/03/28 15:59:01 by cchauvet #+# #+# */
|
2023-04-05 08:13:56 -04:00
|
|
|
/* Updated: 2023/04/05 14:09:39 by alouis-j ### ########.fr */
|
2023-03-29 13:07:57 -04:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "signal_private.h"
|
|
|
|
|
|
|
|
static void ft_new_line(void)
|
|
|
|
{
|
|
|
|
rl_replace_line("", 0);
|
|
|
|
rl_on_new_line();
|
|
|
|
ft_putchar_fd('\n', 1);
|
|
|
|
rl_redisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ft_ctrlc(int num)
|
|
|
|
{
|
|
|
|
t_data *data;
|
|
|
|
|
|
|
|
if (num == SIGQUIT)
|
|
|
|
return ;
|
|
|
|
data = ft_get_data();
|
|
|
|
data->exit_code = 130;
|
|
|
|
if (*ft_get_heredoc() != -1)
|
|
|
|
{
|
2023-04-05 08:13:56 -04:00
|
|
|
if (*ft_get_heredoc() > 2)
|
|
|
|
close(*ft_get_heredoc());
|
2023-03-29 13:07:57 -04:00
|
|
|
*ft_get_heredoc() = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (data->child_pid > 1)
|
|
|
|
{
|
|
|
|
data->child_pid = 0;
|
|
|
|
ft_putchar_fd('\n', 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ft_new_line();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ft_quit(int num)
|
|
|
|
{
|
|
|
|
t_data *data;
|
|
|
|
|
|
|
|
(void) num;
|
|
|
|
data = ft_get_data();
|
|
|
|
data->exit_code = 131;
|
|
|
|
if (data->child_pid > 1)
|
|
|
|
{
|
|
|
|
ft_printf("Quit (core dumped)\n");
|
|
|
|
data->child_pid = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rl_replace_line("", 0);
|
|
|
|
rl_redisplay();
|
|
|
|
}
|
|
|
|
}
|