-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathline_reader.c
More file actions
executable file
·69 lines (63 loc) · 2.1 KB
/
line_reader.c
File metadata and controls
executable file
·69 lines (63 loc) · 2.1 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
64
65
66
67
68
69
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* line_reader.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cduquair <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/02 13:41:35 by hkonte #+# #+# */
/* Updated: 2025/06/02 13:41:42 by hkonte ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
extern int g_signal;
static void handle_sigint_status_code(t_main *main)
{
if (g_signal == SIGINT)
{
main->last_exit_status = 130;
g_signal = 0;
}
}
static void ft_ctrld(t_main *main, char *user_input)
{
if (main->tube)
{
if (main->tube->fd != -1)
close(main->tube->fd);
free(main->tube);
main->tube = NULL;
}
if (main->cmd_info)
free_cmd_info(&main->cmd_info);
if (main->str_envp)
free(main->str_envp);
free_main(&main);
(void)(user_input);
printf("exit\n");
exit(EXIT_SUCCESS);
}
void line_reader(t_main *main)
{
char *user_input;
while (1)
{
user_input = readline("minishell$ ");
handle_sigint_status_code(main);
if (user_input == NULL)
ft_ctrld(main, user_input);
if (main->history == NULL && user_input)
main->history = list_history_init(user_input);
else if (user_input)
list_history_add(&main->history, user_input);
if (user_input && *user_input)
add_history(user_input);
main->tokens = tokenize_input(user_input);
free(user_input);
main->cmd_info = parse_tokens(main, main->tokens);
if (main->cmd_info)
executor(main);
free_cmd_info(&main->cmd_info);
free_tokens(&main->tokens);
}
}