-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
80 lines (72 loc) · 2.03 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmesum <mmesum@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/13 15:41:43 by mmesum #+# #+# */
/* Updated: 2023/03/30 10:19:34 by mmesum ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_execute *g_execute;
char **init_env(char **env)
{
int i;
char **new_env;
i = 0;
while (env[i] != NULL)
i++;
new_env = malloc(sizeof(char *) * (i + 1));
i = 0;
while (env[i] != NULL)
{
new_env[i] = ft_strdup(env[i]);
i++;
}
new_env[i] = NULL;
return (new_env);
}
void init_execute(char **env)
{
g_execute = malloc(sizeof(t_execute));
g_execute->last_exit_code = 0;
g_execute->env = init_env(env);
g_execute->export = init_env(env);
g_execute->only_red_count = 0;
}
void main_loop(void)
{
t_node *head;
t_token *tokens;
signal(SIGINT, &ctrl_c);
signal(SIGQUIT, SIG_IGN);
while (1)
{
g_execute->input = readline("minishell: ");
add_history(g_execute->input);
ctrl_d(g_execute);
tokens = lexer(g_execute->input);
if (tokens == NULL)
{
free(g_execute->input);
continue ;
}
if (first_check_free(tokens, g_execute->input) == 1)
continue ;
head = parser(tokens, g_execute);
if (parse_error_free(head, tokens, g_execute->input) == 1)
continue ;
exec_rest(head);
}
}
int main(int argc, char **argv, char **env)
{
if (argc != 1)
return (0);
(void)argv;
init_execute(env);
main_loop();
return (0);
}