MiniDevil As beautiful as a shell
executor.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* executor.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: baelgadi <baelgadi@student.42.fr> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2025/12/16 17:48:52 by zotaj-di #+# #+# */
9 /* Updated: 2026/03/04 07:00:50 by baelgadi ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include "executor.h"
14 #include "token.h"
15 #include "libft.h"
16 
24 static int exec_command_node(t_ast *node, t_shell *shell)
25 {
26  char **args;
27 
28  args = node->data.cmd.args;
29  return (exec_simple_command(args, shell));
30 }
31 
42 int executor(t_ast *node, t_shell *shell)
43 {
44  if (!node)
45  return (0);
46  if (node->type == NODE_COMMAND)
47  return (exec_command_node(node, shell));
48  if (node->type == NODE_PIPE)
49  return (handle_pipe(node, shell));
50  if (node->type >= NODE_REDIR_IN && node->type <= NODE_REDIR_HEREDOC)
51  return (handle_redir(node, shell));
52  return (0);
53 }
int exec_simple_command(char **args, t_shell *shell)
Execute a simple command (builtin or external)
Definition: exec_utils.c:95
static int exec_command_node(t_ast *node, t_shell *shell)
Execute a NODE_COMMAND AST node.
Definition: executor.c:24
int executor(t_ast *node, t_shell *shell)
Main AST executor that dispatches by node type.
Definition: executor.c:42
Executor prototypes for commands, pipes, redirections & heredocs.
int handle_pipe(t_ast *node, t_shell *shell)
Execute a pipe node by forking left and right children.
int handle_redir(t_ast *node, t_shell *shell)
Execute a redirection node.
@ NODE_REDIR_HEREDOC
Definition: structs.h:57
@ NODE_COMMAND
Definition: structs.h:52
@ NODE_PIPE
Definition: structs.h:53
@ NODE_REDIR_IN
Definition: structs.h:54
AST node (union based ↑)
Definition: structs.h:151
t_ast_data data
cmd, redir or binary data
Definition: structs.h:153
t_node_type type
To determine which union member to pick.
Definition: structs.h:152
char ** args
NULL terminated args array.
Definition: structs.h:103
Shell state.
Definition: structs.h:164
Lexer, tokenizer, expander, and quote handling prototypes.
t_cmd_node cmd
Definition: structs.h:141