-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathminishell.c
56 lines (51 loc) · 1.64 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariahi <ariahi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/07 18:41:44 by ariahi #+# #+# */
/* Updated: 2022/09/22 13:56:07 by ariahi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "parse/parse.h"
static void ft_free_int_minishell(t_list **envlst)
{
t_list *tmp;
while (*envlst)
{
tmp = (*envlst)->next;
ft_free_env((*envlst)->content);
free(*envlst);
*envlst = tmp;
}
}
int main(int ac, char **av, char **env)
{
char *line;
t_parse *p;
if (int_minishell(ac, av, env))
return (1);
exe_set_signal(1);
line = readline("minishell> ");
while (line)
{
if (ft_strspn(line, " \t\n") < ft_strlen(line))
add_history(line);
p = parse(line);
if (p)
{
g_shell.exec = 1;
if (exe(p, NULL, NULL))
g_shell.exit_s = 1;
g_shell.exec = 0;
}
free_tree(&p);
free(line);
line = readline("minishell> ");
}
ft_putstr_fd("exit\n", 1);
return (ft_free_int_minishell(&g_shell.envlst), g_shell.exit_s);
}