-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
81 lines (74 loc) · 2 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
78
79
80
81
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tbousque <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/21 19:42:43 by mportrai #+# #+# */
/* Updated: 2022/11/24 01:09:51 by tbousque ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
#include "vector.h"
#include <stdio.h>
#include "ast.h"
#include "command.h"
#include "environement_variable.h"
#include "signaling.h"
#include <readline/readline.h>
#include <readline/history.h>
#include "libft.h"
t_env ft_prepare_env(const char **envp, char *argv)
{
t_env env;
if (*envp == NULL)
env = env_init_null(argv);
else
{
(void) argv;
env = env_init_from_envp(envp);
}
return (env);
}
int prompt(t_env *env)
{
char *line;
int is_running;
int exit_status;
exit_status = 0;
is_running = 1;
while (is_running)
{
line = readline("Minishell$ ");
if (line == NULL)
{
is_running = 0;
write(2, "\nexit\n", 6);
}
else
{
add_history(line);
exit_status = execute_line(line, env);
if (env->is_child)
is_running = 0;
}
free(line);
}
return (exit_status);
}
int main(int argc, char const *argv[], char const *envp[])
{
t_env env;
int exit_status;
(void) argc;
exit_status = 0;
signal_handling();
env = ft_prepare_env(envp, (char *)argv[0]);
remove_echo_ctrl();
exit_status = prompt(&env);
rl_clear_history();
env_free(&env);
add_echo_ctrl();
return (exit_status);
}