-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminishell.c
More file actions
61 lines (54 loc) · 1.63 KB
/
minishell.c
File metadata and controls
61 lines (54 loc) · 1.63 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tafanasi <tafanasi@student.42warsaw.pl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/26 15:59:58 by tafanasi #+# #+# */
/* Updated: 2025/08/28 11:36:45 by tafanasi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
// Clear the line, move to new line, show prompt
void handle_sigint(int sig)
{
(void)sig;
rl_replace_line("", 0);
printf("\n");
rl_on_new_line();
}
void setup_signals(void)
{
signal(SIGINT, handle_sigint);
signal(SIGQUIT, SIG_IGN);
}
void await_input(t_shell *shell, char **args)
{
char *input;
while (1)
{
input = readline("minishell$ ");
if (input)
{
process_input(shell, input, args);
free(input);
}
else
{
clear_history();
free_shell(shell);
exit(EXIT_SUCCESS);
}
}
}
int main(int argc, char **argv, char **envp)
{
t_shell *shell;
if (argc > 1 || argv[0] == NULL)
custom_error("Arguments are not supported");
shell = init_shell(envp);
setup_signals();
await_input(shell, argv);
return (0);
}