-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
executable file
·59 lines (52 loc) · 1.75 KB
/
main.c
File metadata and controls
executable file
·59 lines (52 loc) · 1.75 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hkonte <hkonte@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/29 13:13:55 by hkonte #+# #+# */
/* Updated: 2024/11/29 13:14:27 by hkonte ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int g_signal = 0;
void handle_signal(int signal)
{
if (signal == SIGINT)
{
g_signal = SIGINT;
write(1, "\n", 1);
rl_replace_line("", 0);
rl_on_new_line();
rl_redisplay();
}
}
static t_main *init_main(char **envp)
{
t_main *main_struct;
main_struct = ft_calloc(1, sizeof(t_main));
if (!main_struct)
exit(1);
main_struct->envp = init_env(envp);
return (main_struct);
}
int main(int argc, char **argv, char **envp)
{
t_main *main_struct;
struct sigaction sa;
if (argc >= 2)
{
printf("minishell: Can't be launch with args.\n");
return (1);
}
sa.sa_handler = handle_signal;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sigaction(SIGINT, &sa, NULL);
signal(SIGQUIT, SIG_IGN);
main_struct = init_main(envp);
(void)argv;
line_reader(main_struct);
free_main(&main_struct);
}