-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminishell.c
More file actions
63 lines (58 loc) · 1.75 KB
/
minishell.c
File metadata and controls
63 lines (58 loc) · 1.75 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
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maustel <maustel@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/18 16:04:16 by dhuss #+# #+# */
/* Updated: 2024/12/01 13:05:50 by maustel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void minishell_loop(t_shell *shell)
{
char *input;
while (1)
{
handle_signals(0);
input = readline("minishell: ");
handle_signals(1);
if (!input)
return (clear_all(shell->env));
if (input[0] != '\0')
{
lexer(shell, input);
parser(shell);
expansion(shell, shell->env);
executor(shell);
add_history(input);
free_minishell(shell, input);
if (shell->exit == true)
break ;
}
}
}
int main(int argc, char *argv[], char **env)
{
t_shell shell;
int error_code;
init_terminal();
shell.table = NULL;
shell.exit = false;
if (argc == 1)
{
if (copy_env(env, &shell) == -1)
return (-1);
if (shlvl(&shell) != 0)
return (-1);
minishell_loop(&shell);
rl_clear_history();
printf("exit\n");
}
else
print_error(E_ARGC, NULL, PRINT);
(void) argv;
error_code = print_error(-1, NULL, NOTPRINT);
return (error_code);
}