-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
70 lines (62 loc) · 1.29 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
#include "minishell.h"
void do_signals(int sig)
{
if (sig == SIGINT)
{
write(1, "\n", 1);
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
}
}
static int ctrld_exit(t_shell *shell)
{
int code;
code = shell->last_exit_code;
ft_lstclear(&shell->cmd, free_process);
free_and_null(shell->heredoc, shell->line);
ft_lstclear(&shell->env, del_dict);
return (code);
}
int _start_shell(t_shell *shell)
{
while (shell->status)
{
signal(SIGQUIT, SIG_IGN);
signal(SIGINT, do_signals);
shell->line = readline("["SHELL_NAME"]# ");
if (shell->line == NULL)
return (ctrld_exit(shell));
shell->err = 0;
shell->flags = _init_flags();
pre_parser(shell->line, shell);
if (shell->line)
add_history(shell->line);
if (!shell->err)
handle_processes(shell->cmd);
ft_lstclear(&shell->cmd, free_process);
free_and_null(shell->heredoc, shell->line);
}
ft_lstclear(&shell->env, del_dict);
return (1);
}
t_flags _init_flags(void)
{
t_flags flags;
ft_memset((void *)&flags, 0, sizeof(flags));
flags.pipe_in = -1;
flags.pipe_out = -1;
return (flags);
}
int main(int ac, char **av, char **envp)
{
t_shell shell;
int code;
ac = 0;
av = 0;
ft_bzero(&shell, sizeof(shell));
upload_env_to_dict(envp, &shell.env);
shell.status = 1;
code = _start_shell(&shell);
return (code);
}