-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_handling.c
More file actions
68 lines (63 loc) · 2.17 KB
/
input_handling.c
File metadata and controls
68 lines (63 loc) · 2.17 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* input_handling.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tafanasi <tafanasi@student.42warsaw.pl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/25 12:00:00 by tafanasi #+# #+# */
/* Updated: 2025/08/25 12:00:00 by tafanasi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *handle_continuation(t_shell *shell, char *input)
{
char *continuation_input;
char *complete_input;
continuation_input = readline("> ");
if (!continuation_input)
{
free(input);
clear_history();
free_shell(shell);
exit(EXIT_SUCCESS);
}
complete_input = malloc(strlen(input) + strlen(continuation_input) + 2);
if (!complete_input)
return (input);
strcpy(complete_input, input);
strcat(complete_input, " ");
strcat(complete_input, continuation_input);
free(input);
free(continuation_input);
return (complete_input);
}
char *process_continuation(t_shell *shell, char *input)
{
while (shell->parsed_input && shell->parsed_input->is_valid
&& shell->parsed_input->incomplete_pipe)
{
input = handle_continuation(shell, input);
if (shell->parsed_input)
{
free_shell_input(shell->parsed_input);
shell->parsed_input = NULL;
}
parser(shell, input);
}
return (input);
}
void process_input(t_shell *shell, char *input, char **args)
{
if (input[0] != '\0')
add_history(input);
parser(shell, input);
input = process_continuation(shell, input);
if (shell->parsed_input && shell->parsed_input->is_valid)
exec_cmd(shell->parsed_input->first_cmd, shell, args);
if (shell->parsed_input)
{
free_shell_input(shell->parsed_input);
shell->parsed_input = NULL;
}
}