-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsign_handler.c
70 lines (62 loc) · 1.65 KB
/
sign_handler.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sign_handler.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ggiannit <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/01 16:28:42 by ggiannit #+# #+# */
/* Updated: 2023/04/17 09:42:00 by ggiannit ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int ft_magic_heredoc(int keepit)
{
static int pid = 0;
if (pid)
{
kill(pid, SIGKILL);
write(1, "\n", 1);
pid = 0;
return (1);
}
if (keepit)
pid = keepit;
return (0);
}
void ft_sign_handler_heredoc(int sig)
{
if (sig == SIGINT)
{
ft_sign_ecode(NULL, 130);
ft_magic_heredoc(0);
}
}
void ft_sign_ecode(t_mish *meta, int ecode)
{
static t_mish *versometa;
if (meta)
versometa = meta;
else
versometa->exit_code = ecode;
}
void ft_sign_handler_exec(int sig)
{
if (sig == SIGINT)
{
ft_sign_ecode(NULL, 130);
write(1, "\n", 1);
}
}
void ft_sign_handler_rl(int sig)
{
if (sig == SIGINT)
{
ft_sign_ecode(NULL, 130);
write(1, "\n", 1);
write(1, "\033[0;97m", 7);
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
}
}