-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
executable file
·77 lines (69 loc) · 1.95 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jgarlic <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/02 23:22:39 by jgarlic #+# #+# */
/* Updated: 2021/12/02 23:22:41 by jgarlic ### ########.fr */
/* */
/* ************************************************************************** */
#include "my_minishell.h"
void my_free_shell(t_shell *shell)
{
if (shell != NULL)
{
my_free_split(shell->env);
if (shell->fd_pipe != -1)
close(shell->fd_pipe);
free(shell->path);
free(shell);
}
}
t_shell *my_init_shell(char **env)
{
t_shell *shell;
shell = NULL;
shell = malloc(sizeof(t_shell));
shell->i = 0;
shell->fd_pipe = -1;
shell->last_code = 0;
shell->env = my_init_split(env);
shell->path = my_split_path(env);
return (shell);
}
void c_quit(int sig)
{
if (sig == SIGQUIT && my_global_static(0, 0) == 0)
write(STDOUT_FILENO, "Quit: 3", 7);
if (sig == SIGINT && my_global_static(0, 0) == 0)
{
write(STDOUT_FILENO, "\n", 1);
rl_replace_line("", 0);
rl_on_new_line();
rl_redisplay();
}
}
void signal_ft(void)
{
signal(SIGTERM, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
signal(SIGINT, c_quit);
}
int main(int argc, char **argv, char **env)
{
t_shell *shell;
char *cmd;
(void)argc;
(void)argv;
shell = my_init_shell(env);
signal_ft();
while (1)
{
cmd = readline("minishell>");
if (cmd == NULL)
exit(0);
my_cmd_controller(cmd, shell);
}
}