-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignal.c
77 lines (69 loc) · 1.81 KB
/
signal.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
71
72
73
74
75
76
77
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* signal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zkarapet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/22 16:59:23 by zkarapet #+# #+# */
/* Updated: 2023/03/03 21:15:38 by zkarapet ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void init_term(void)
{
struct termios term;
tcgetattr(0, &term);
term.c_lflag &= ~ECHO;
term.c_lflag &= ~ECHOCTL;
term.c_lflag |= ECHO;
tcsetattr(0, 0, &term);
}
void reset_term(void)
{
struct termios term;
tcgetattr(0, &term);
term.c_lflag |= ECHOCTL;
tcsetattr(0, 0, &term);
}
void sig_control(int a)
{
if (a == 0)
{
reset_term();
g_status = 290;
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
}
else if (a == 1)
{
init_term();
signal(SIGINT, sigint_handler);
signal(SIGQUIT, SIG_IGN);
}
else if (a == 2)
{
signal(SIGINT, sig_handler_hdoc);
signal(SIGQUIT, SIG_IGN);
}
}
void sigint_handler(int sig)
{
if (sig == SIGINT)
{
g_status = 1;
ioctl(STDIN_FILENO, TIOCSTI, "\n");
rl_replace_line("", 0);
rl_on_new_line();
}
}
void sig_handler_hdoc(int sig)
{
if (sig == SIGINT)
{
g_status = -42;
ioctl(STDIN_FILENO, TIOCSTI, "\n");
rl_replace_line("", 0);
rl_on_new_line();
}
}