forked from staskine/42Minishell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
62 lines (56 loc) · 1.68 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sataskin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 13:25:04 by sataskin #+# #+# */
/* Updated: 2024/07/22 10:41:58 by sataskin ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int g_sig;
static int main_loop(t_mini *shell)
{
char *rl;
int ret;
set_signal(0);
rl = readline(PINK PROMPT RESET);
if (!rl)
return (1);
if (rl[0] == '\0')
return (0);
set_signal(1);
ret = parser(rl, shell);
if (ret == 0 && shell->cmds)
minishell(shell);
else if (ret == 0 && !shell->cmds)
exit_code(shell, 0, 0);
else if (shell->syntax == 0)
exit_code(shell, 1, 0);
close_files(&shell->cmds);
ft_lstclear_pars(&shell->cmds);
add_history(rl);
free(rl);
return (0);
}
int main(int argc, char **argv, char **envp)
{
static t_mini shell;
(void)argv;
g_sig = 0;
if (argc != 1)
{
printf("Run minishell using only <./minishell>\n");
exit (1);
}
set_data(&shell, envp);
while (1)
{
if (main_loop(&shell) > 0)
break ;
}
free_data(&shell, "exit\n");
return (0);
}