66 lines
1.6 KiB
C
66 lines
1.6 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* signal.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2023/03/28 15:59:01 by cchauvet #+# #+# */
|
||
|
/* Updated: 2023/03/28 16:09:37 by cchauvet ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
#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)
|
||
|
{
|
||
|
close(*ft_get_heredoc());
|
||
|
*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();
|
||
|
}
|
||
|
}
|