-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminishell.c
97 lines (88 loc) · 2.18 KB
/
minishell.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/01 11:49:37 by zhabri #+# #+# */
/* Updated: 2023/01/12 15:21:41 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_glob *g_glob;
void get_envp(char **envp)
{
if (g_glob)
g_glob->envp = str_tab_to_list(envp);
}
void get_head(t_list **head)
{
*head = NULL;
g_glob->head = head;
}
void events(t_list **head)
{
get_ops(g_glob->input, head);
get_after_op();
free_op_list();
get_ops(g_glob->input, head);
if (!op_error())
{
get_args();
if (!pipe_error())
{
scan_heredocs();
get_cmd();
if (!g_glob->sig_int)
pipex();
unlink_heredocs();
clear_cmds();
if (g_glob->cmds)
free(g_glob->cmds);
}
}
free_op_list();
}
void event_loop(void)
{
t_list **head;
char *input;
while (1)
{
reset_g_glob();
input = readline("minishell> ");
if (input == NULL)
{
ft_putstr_fd("exit\n", 1);
break ;
}
if (*input == '\0')
continue ;
head = NULL;
head = malloc(sizeof(t_list *));
get_head(head);
g_glob->input = input;
add_history(input);
if (head && !quote_error(input))
events(head);
free(g_glob->input);
free(g_glob->head);
}
}
int main(int argc, char **argv, char **envp)
{
int exit_ret;
char **t;
(void)argc;
init_sig_callbacks(0);
init_g_glob();
get_envp(envp);
t = tab_dup(argv, argc);
get_sum(t, &(g_glob->minishell_sum), NULL, NULL);
free_tab(t);
event_loop();
exit_ret = g_glob->exit_ret;
final_clean_up();
return (exit_ret);
}