maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
execute.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* execute.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/05/31 11:02:00 by dmdemirk #+# #+# */
9/* Updated: 2024/09/09 12:54:44 by dmdemirk ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "builtins.h"
14#include "libft.h"
15#include <stdio.h>
16#include <sys/wait.h>
17#include "shell.h"
18#include "execute.h"
19#include "tokens.h"
20#include "pipe.h"
21#include "redirection.h"
22#include "exit_status.h"
23#include "signals.h"
24#include "exit_status.h"
25
26int execute_ast(t_ast *node, t_ms_data *data);
27
38int execute_ast(t_ast *node, t_ms_data *data)
39{
40 if (!node)
41 return (EXIT_FAILURE);
42 if (node->type == PIPE)
43 return (builtin_pipe(node, data));
44 else if (node->type == REDIR_IN)
45 return (redirect_in(node, data));
46 else if (node->type == REDIR_OUT)
47 return (redirect_out(node, data));
48 else if (node->type == REDIR_APPEND)
49 return (redirect_append(node, data));
50 else if (node->type == REDIR_HEREDOC)
51 return (redirect_here_doc(node, data));
52 else if (node->type == PHRASE)
53 {
54 data->args = node->args;
55 return (execute(data));
56 }
57 return (EXIT_SUCCESS);
58}
int execute_ast(t_ast *node, t_ms_data *data)
execute Abstract Syntax Tree
Definition execute.c:38
int execute(t_ms_data *data)
execute distribution function
#define EXIT_SUCCESS
Definition exit_status.h:16
#define EXIT_FAILURE
Definition exit_status.h:17
int builtin_pipe(t_ast *node, t_ms_data *data)
execute pipe when | is found in the command
Definition pipe.c:35
int redirect_out(t_ast *node, t_ms_data *data)
int redirect_in(t_ast *node, t_ms_data *data)
redirection input in context of executing AST
Definition redirect_in.c:38
int redirect_append(t_ast *node, t_ms_data *data)
redirect append ">>" to the end of the file output
int redirect_here_doc(t_ast *node, t_ms_data *data)
Definition tokens.h:50
char ** args
Definition tokens.h:52
t_token_type type
Definition tokens.h:51
char ** args
Definition shell.h:23
@ REDIR_IN
Definition tokens.h:34
@ PHRASE
Definition tokens.h:31
@ REDIR_HEREDOC
Definition tokens.h:37
@ PIPE
Definition tokens.h:32
@ REDIR_OUT
Definition tokens.h:35
@ REDIR_APPEND
Definition tokens.h:36