-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandle_input.c
More file actions
61 lines (56 loc) · 1.86 KB
/
handle_input.c
File metadata and controls
61 lines (56 loc) · 1.86 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_input.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tvithara <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/03 16:55:52 by tvithara #+# #+# */
/* Updated: 2026/02/03 16:55:56 by tvithara ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "execution.h"
#include <readline/history.h>
static int parse_and_execute(t_shell *shell)
{
t_pipeline *pipeline;
shell->commands = parse_tokens(shell->tokens);
free_tokens(shell->tokens);
shell->tokens = NULL;
if (!shell->commands)
return (0);
pipeline = build_pipeline(shell->commands);
if (pipeline)
{
run_pipeline(pipeline, shell);
free_pipeline(pipeline);
}
shell->exit_status = shell->envc.exit_code;
free_commands(shell->commands);
shell->commands = NULL;
if (shell->envc.should_exit)
return (1);
return (0);
}
static int tokenize_and_process(char *line, t_shell *shell)
{
shell->tokens = tokenize_input(line);
free(line);
if (!shell->tokens)
return (0);
process_quotes_and_expansion(shell);
if (!shell->tokens)
return (0);
return (parse_and_execute(shell));
}
int process_input_line(char *line, t_shell *shell)
{
if (*line == '\0')
{
free(line);
return (0);
}
add_history(line);
return (tokenize_and_process(line, shell));
}