-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
73 lines (66 loc) · 1.86 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wonyang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/08 22:30:32 by wonyang #+# #+# */
/* Updated: 2023/01/17 15:22:01 by wonyang ### ########seoul.kr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
#include "libft.h"
#include "minishell.h"
#include "execute.h"
#include "token.h"
t_global g_var;
void run_code(char *str)
{
t_tnode *root;
root = parse_line(str);
if (!root)
return ;
execute(root);
clear_node(root, &del_t_token);
}
static void routine(void)
{
char *str;
t_tnode *root;
while (1)
{
str = readline(PROMPT);
if (str == NULL)
{
ft_putendl_fd("\x1b[1A\033[12Cexit", STDOUT_FILENO);
break ;
}
if (ft_strcmp(str, "") == 0)
{
free(str);
continue ;
}
add_history(str);
root = parse_line(str);
if (!root)
continue ;
execute(root);
clear_node(root, &del_t_token);
free(str);
}
}
int main(int argc, char **argv, char **env)
{
(void)argv;
if (argc != 1 || init_minishell_setting(env) == ERROR)
return (1);
routine();
clear_envp(&(g_var.envp));
free(g_var.tmp_path);
tcsetattr(STDIN_FILENO, TCSANOW, &(g_var.old_term));
return (g_var.status);
}