-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
83 lines (74 loc) · 2.27 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
82
83
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akhalidy <akhalidy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/30 12:41:12 by framdani #+# #+# */
/* Updated: 2021/12/20 10:56:12 by akhalidy ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/parser.h"
#include "libft/libft.h"
#include "includes/minishell.h"
#include <readline/readline.h>
#include <readline/history.h>
void catch_eof(void)
{
char *cm_cap;
cm_cap = tgetstr("up", NULL);
tputs(tgoto(cm_cap, 0, 0), 0, putchar);
printf("minishell$ exit\n");
exit(g_help.ret);
}
t_list *ft_init(char **env, char **argv, int argc)
{
t_list *envl;
argc = 0;
argv = NULL;
g_help.on_oldpwd = 1;
g_help.on_pwd = 1;
g_help.in_child = 0;
g_help.in_here_doc = 0;
g_help.std_in = dup(STDIN_FILENO);
g_help.std_out = dup(STDOUT_FILENO);
envl = ft_arr_to_list(env);
ft_inc_shlvl(envl);
return (envl);
}
t_cmd *parse(char *cmd_line, t_list **envl)
{
t_cmd *lst_cmds;
t_token *tokens;
int size;
size = ft_strlen(cmd_line) + 1;
tokens = lexer(cmd_line, size, envl);
tokens = parser(tokens);
lst_cmds = fill_struct(tokens);
free_lst_tokens(&tokens);
free(cmd_line);
return (lst_cmds);
}
int main(int argc, char **argv, char **env)
{
t_list *envl;
char *cmd_line;
t_cmd *lst_cmds;
envl = ft_init(env, argv, argc);
while (1)
{
signal(SIGINT, handler);
signal(SIGQUIT, handler_2);
cmd_line = readline("minishell$ ");
if (cmd_line == NULL)
catch_eof();
if (*cmd_line != '\0')
add_history(cmd_line);
lst_cmds = parse(cmd_line, &envl);
if (lst_cmds != NULL)
ft_launch_execution(lst_cmds, &envl);
free_lst_cmds(&lst_cmds);
// system("leaks minishell");
}
}