-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
101 lines (93 loc) · 3.14 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sessarhi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/26 04:24:26 by sessarhi #+# #+# */
/* Updated: 2024/08/30 10:17:25 by sessarhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void rrl_nr_helpr_f2(t_norm_rll *helper)
{
helper->lgc_norm.l_gc = &helper->l_gc;
helper->lgc_norm.lst = helper->lst;
helper->lgc_norm.bol2 = &helper->bol;
}
void readline_loop_hellper2(t_norm_rll *helper)
{
if (g_a.exitstatus_singnal == 1)
{
ft_export_status(1, &helper->env, &helper->l_gc, helper->lst);
g_a.exitstatus_singnal = 0;
}
intit_env_list(&helper->env_lst, helper->env, helper->lst);
if (*(helper->line)[0] != '\0' && !white_spaces(*(helper->line)))
{
add_history(*(helper->line));
rll_nr_helpr_f(helper);
if (parsing_part(&helper->help, &helper->env_lst, &helper->l_gc,
&helper->cmd) || g_a.stphedorc_insgin == 2)
{
if (g_a.stphedorc_insgin == 2)
rll_helper2();
g_a.stphedorc_insgin = 0;
return (free_nr_rl_vars(&helper->cmd, &helper->env_lst,
&helper->l_gc, helper->line), (void)0);
}
rrl_nr_helpr_f2(helper);
main_execute(helper->cmd, helper->env_lst,
helper->lgc_norm, &helper->env);
}
free_nr_rl_vars(&helper->cmd, &helper->env_lst,
&helper->l_gc, helper->line);
}
void readline_loop_hellper(t_norm_rll *helper)
{
while (1)
{
*(helper->line)
= readline(BOLD GREEN "minishell" YELLOW "$ " RESET BOLD);
if (!*(helper->line))
{
write(0, "exit\n", 5);
intit_env_list(&helper->env_lst, helper->env, helper->lst);
helper->exit_s = my_getenv("@exitstatus", helper->env_lst);
helper->status = 0;
if (g_a.exitstatus_singnal == 1)
rll_helper1(&helper->status, &g_a.exitstatus_singnal);
else if (helper->exit_s)
helper->status = ft_atoi(helper->exit_s);
return (ft_free(&helper->l_gc),
ft_free(helper->lst), exit(helper->status));
}
readline_loop_hellper2(helper);
}
}
void readline_loop(char **line, t_gc **lst, char **env)
{
t_norm_rll help_rll;
init_rn_rll(&help_rll);
help_rll.bol = setup_env_and_path(&env, lst, &help_rll.l_gc);
check_and_export_status(&env, &help_rll.l_gc, lst);
help_rll.env = env;
help_rll.lst = lst;
help_rll.line = line;
readline_loop_hellper(&help_rll);
}
int main(int ac, char **av, char **env)
{
t_gc *lst;
char *line;
lst = NULL;
if (ac != 1)
return (printf("Usage: %s\n", av[0]), 1);
rl_catch_signals = 0;
signal(SIGINT, handle_sigint);
signal(SIGQUIT, handle_sigint);
readline_loop(&line, &lst, env);
ft_free(&lst);
return (0);
}