-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
62 lines (56 loc) · 1.62 KB
/
main.c
File metadata and controls
62 lines (56 loc) · 1.62 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vloth <vloth@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/13 18:23:57 by vloth #+# #+# */
/* Updated: 2023/09/08 18:42:12 by vloth ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
pid_t g_pid;
void eternal_loop(t_data *data)
{
char *str;
str = NULL;
rl_outstream = stderr;
while (1)
{
connect_signal();
g_pid = 0;
str = readline("MS#🤖: ");
if (!str)
{
printf("Exit\n");
free(str);
free_everything(data);
exit(0);
}
add_history(str);
if (!split_or_not(str, data->cmd_index))
{
if (!malloc_all(data))
exec(data);
}
else
free_list_second(data);
}
}
int main(int argc, char **argv, char **envp)
{
t_data data;
if (!isatty(STDIN_FILENO))
return (EXIT_FAILURE);
if (envp == NULL || *envp == NULL)
{
ft_putstr_fd(ERROR_ENV, 2);
return (EXIT_FAILURE);
}
the_arg(argc, argv);
init_data(&data, envp);
eternal_loop(&data);
rl_clear_history();
return (0);
}