-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree_executing.c
More file actions
74 lines (67 loc) · 2.66 KB
/
tree_executing.c
File metadata and controls
74 lines (67 loc) · 2.66 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
70
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tree_executing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: frame <frame@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/09 22:36:12 by moabid #+# #+# */
/* Updated: 2022/10/26 10:24:34 by frame ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void command_statement_run(char **command_statement,
char *command_path, struct s_minishell *minishell)
{
if (is_builtin(command_statement[0]) == true)
builtin_run(command_statement, minishell);
if (execve(command_path, command_statement, e_to_s(minishell->env)) == -1)
ft_error(command_statement[0]);
}
char **command_statement_create_complexe(struct s_ast *ast)
{
int i;
struct s_ast *tmp;
char **command_statement;
i = 0;
tmp = ast;
command_statement = ft_malloc(sizeof(char *) * (ast_child_num(ast) + 2));
command_statement[i] = ft_strdup(tmp->value.token_name);
if (tmp->left)
command_statement[++i] = ft_strdup(tmp->left->value.token_name);
if (tmp->right)
command_statement[++i] = ft_strdup(tmp->right->value.token_name);
if (tmp->left)
{
tmp = tmp->left;
while (tmp->left)
{
command_statement[++i] = ft_strdup(tmp->left->value.token_name);
tmp = tmp->left;
}
}
command_statement[ast_child_num(ast) + 1] = NULL;
return (command_statement);
}
void command_statement_execute_complexe(struct s_ast *ast,
struct s_minishell *minishell)
{
char **command_statement;
char *command_path;
command_statement = command_statement_create_complexe(ast);
command_path = get_path(command_statement[0], minishell->env);
command_statement_run(command_statement, command_path, minishell);
command_statement_destroy(command_statement);
}
void redirection_run(struct s_ast *ast, struct s_ast *first,
struct s_minishell *minishell, int fd_out)
{
if (ast->left->value.token_type == PIPE)
redirection_run(ast->left, first, minishell, fd_out);
if (ast->left->value.token_type != PIPE)
process_pipe_run_left(ast->left, minishell);
if (ast->right != first->right)
process_pipe_run_right(ast, minishell);
else
minishell_ast_execute(ast->right, minishell);
}