-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_execution.c
55 lines (50 loc) · 1.66 KB
/
handle_execution.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_execution.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: almelo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/25 15:54:04 by almelo #+# #+# */
/* Updated: 2023/04/05 17:32:54 by almelo ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void deep_free(char **envp)
{
size_t i;
i = 0;
while (envp[i])
{
free(envp[i]);
i++;
}
free(envp);
}
void handle_execution(t_tokenl *token_lst, t_envl *env_lst)
{
char **argv;
char **envp;
int prevpipe;
int bkp_stdout;
prevpipe = dup(STDIN_FILENO);
bkp_stdout = dup(STDOUT_FILENO);
while (token_lst->head)
{
envp = list_to_envp(env_lst);
argv = get_next_argv(token_lst);
if (token_lst->head)
bkp_stdout = handle_redirect(token_lst, &prevpipe);
env_lst = handle_builtin_pp(argv, envp, env_lst);
if (token_lst->pipe_count > 0)
{
ft_pipe(argv, envp, env_lst, &prevpipe);
free(dequeue_token(token_lst));
}
else
ft_last(argv, envp, env_lst, &prevpipe);
dup2(bkp_stdout, STDOUT_FILENO);
deep_free(envp);
deep_free(argv);
}
}