-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
61 lines (53 loc) · 1.66 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lenzo-pe <lenzo-pe@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/27 19:40:41 by lenzo-pe #+# #+# */
/* Updated: 2022/03/02 22:22:32 by lenzo-pe ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int *last_status_number(void)
{
static int lsn;
return (&lsn);
}
void handle_signals(int sig)
{
if (sig == SIGINT)
{
write(1, "\n", 1);
rl_replace_line("", 0);
rl_on_new_line();
rl_redisplay();
*last_status_number() = 130;
}
}
int mysignal(int sig, void (*handler)(int))
{
t_sigaction act;
act.sa_handler = handler;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(sig, &act, NULL);
return (0);
}
int main(void)
{
t_env_vars *env_vars;
t_tokens *tokens;
char *input;
env_vars = get_environment_variables();
while (42)
{
mysignal(SIGINT, handle_signals);
mysignal(SIGQUIT, SIG_IGN);
input = get_input(env_vars->global_vars, env_vars);
tokens = lexical_analysis_and_parse(input, env_vars);
execute_cmds(tokens, env_vars);
}
return (0);
}