This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
forked from 42madorna/42_Minishell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
84 lines (77 loc) · 1.95 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madorna- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/23 00:49:50 by madorna- #+# #+# */
/* Updated: 2022/02/13 05:33:32 by madorna- ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void
signal_h(int signal)
{
if (signal == SIGINT)
{
printf("\n");
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
}
}
void
promt(t_mini *mini, int type)
{
static char *names[] = {SHELL_NAME"$ ", "> "};
mini->line = readline(names[type]);
}
void
ft_strc_init(t_mini *mini)
{
set_functions(mini);
ft_env_to_lst(mini);
}
/*
** Minishell
** Subject https://cdn.intra.42.fr/pdf/pdf/34911/en.subject.pdf
*/
/*
** TODO: [MINS-111] Leaks!
** At this moment:
** · l_argv
** · t_cmd
** · PATH
** · l_env/t_cmd env
** · t_cmd path
** · delimiters
*/
int
main(int argc, char **argv, char **env)
{
t_mini mini;
ft_bzero(&mini, sizeof(t_mini));
mini.argc = argc;
mini.argv = argv;
mini.env = env;
ft_strc_init(&mini);
while (1)
{
signal(SIGINT, signal_h);
signal(SIGQUIT, SIG_IGN);
mini.flag = CLEAR;
mini.parse_err = 0;
promt(&mini, 0);
if (mini.line && *mini.line)
mini_loop(&mini);
else if (!mini.line)
{
printf("exit\n");
rl_clear_history();
break ;
}
}
ft_lstclear(&mini.l_env, ft_free_env);
return (0);
}