-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
73 lines (67 loc) · 2 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: nelidris <nelidris@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/15 06:41:02 by ahamdy #+# #+# */
/* Updated: 2022/08/22 11:28:56 by nelidris ### ########.fr */
/* */
/* ************************************************************************** */
#include <minishell.h>
void ctrl_c_handler(int signal)
{
(void)signal;
rl_on_new_line();
write(1, "\n", 1);
rl_replace_line("", 0);
rl_redisplay();
exit_code_handler(POSTEXIT, 1);
}
static void here_doc_edit_exit(char *prompt_cmd, t_cmd_line **cmd_line)
{
here_doc_signal(1, 0);
exit_code_handler(POSTEXIT, 1);
add_history(prompt_cmd);
free_cmd_line(cmd_line);
free(prompt_cmd);
}
static void minishell_routine(void)
{
t_cmd_line **cmd_line;
char *prompt_cmd;
prompt_cmd = readline("minishell> ");
if (!prompt_cmd)
{
ft_fprintf(STANDARD_ERROR, "exit\n");
exit(exit_code_handler(GETEXIT, 0));
}
if (!(*prompt_cmd))
{
free(prompt_cmd);
return ;
}
cmd_line = parsing_functions(prompt_cmd);
if (here_doc_signal(0, 0))
{
here_doc_edit_exit(prompt_cmd, cmd_line);
return ;
}
if (cmd_line)
exit_code_handler(POSTEXIT, execute_cmd_line(cmd_line));
add_history(prompt_cmd);
free(prompt_cmd);
}
int main(int c, char **v, char **envp)
{
(void)v;
if (c != 1)
return (1);
envp_handler(POSTENV, env_dup(envp));
signal(SIGINT, ctrl_c_handler);
signal(SIGQUIT, SIG_IGN);
while (1)
minishell_routine();
return (0);
}