-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
71 lines (65 loc) · 1.93 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmonte <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/06 15:47:54 by mmonte #+# #+# */
/* Updated: 2021/04/07 21:23:33 by mmonte ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void main_starter(t_main *mn)
{
t_list *next;
next = NULL;
while (mn->lexer)
{
next = mn->lexer->next;
free(mn->lexer->content);
free(mn->lexer);
mn->lexer = next;
}
mn->ap_flag = 0;
mn->dap_flag = 0;
mn->car = 0;
mn->rdir_acc = 0;
mn->pid = 1;
mn->temp0fd = dup(0);
}
static t_main *main_creater(char **envp, char *name_shell)
{
struct termios tios;
if (!(g_mn = ft_calloc(1, sizeof(t_main))))
exit(1);
ft_create_hstry_in_main(g_mn);
g_mn->envp = addtoarr(envp, 0);
g_mn->pid = 1;
if (!(g_mn->name_shell = ft_strjoin((ft_strrchr(name_shell, '/')
+ 1), "$ ")))
{
free(g_mn);
exit(1);
}
tcgetattr(0, &tios);
g_mn->term = tios;
return (g_mn);
}
int main(int argc, char **argv, char **envp)
{
(void)argc;
if (!(g_mn = main_creater(envp, argv[0])))
exit(0);
while (1)
{
signal(SIGINT, ft_signal);
signal(SIGQUIT, ft_signal);
ft_refresh_hstry(g_mn);
lexer_parser(g_mn);
main_starter(g_mn);
if (get_next_line(0, g_mn) == -2)
ft_exit(g_mn, NULL, 0);
}
ft_exit(g_mn, g_mn->job->pipe, 0);
}