-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminishell.c
executable file
·72 lines (64 loc) · 1.92 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abenheni <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/06 15:26:43 by mazaroua #+# #+# */
/* Updated: 2023/09/30 14:02:08 by abenheni ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_global g_var;
void body(char *line, t_export **export_list, t_env_list **env_list)
{
t_token_list *tokens;
t_cmd_line *cmd_line;
t_tools tools;
cmd_line = NULL;
tokens = NULL;
tokens = tokenizer(line, tokens, &tools);
if (tokens && syntax(tokens))
{
expand(&tokens, env_list);
parser(&cmd_line, tokens);
execution(&cmd_line, env_list, export_list);
}
free_all();
}
char *prompt(void)
{
char *line;
line = readline("\x1B[36m""shell-> $ ""\001\e[0m\002");
if (!line)
{
ft_putstr("exit\n");
exit(0);
}
// add_history(line);
line = remove_additional_spaces(line);
return (line);
}
int main(int ac, char **av, char **env)
{
char *line;
t_export *export_list;
t_env_list *env_list;
(void)ac;
(void)av;
export_list = NULL;
env_list = NULL;
g_var.allocated = NULL;
init_env(&export_list, &env_list, env);
ft_shlvl(&env_list, &export_list);
while (1)
{
g_var.heredoc = 0;
signal(SIGINT, &ctrlc);
signal(SIGQUIT, SIG_IGN);
line = prompt();
if (line)
body(line, &export_list, &env_list);
}
}