MiniDevil As beautiful as a shell
executor.h
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* executor.h :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: baelgadi <baelgadi@student.42.fr> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2025/12/13 03:16:21 by baelgadi #+# #+# */
9 /* Updated: 2026/03/11 02:55:42 by baelgadi ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #ifndef EXECUTOR_H
14 # define EXECUTOR_H
15 
16 # include <sys/types.h>
17 # include "structs.h"
18 
19 /* ────────────── executor.c ──────────────── */
20 
21 int executor(t_ast *node, t_shell *shell);
22 
23 /* ────────────── executor_redir.c ──────────────── */
24 
25 int open_redir_file(char *file, t_node_type type);
26 
27 int setup_redirection(int fd, t_node_type type);
28 
29 void restore_fd(int saved_fd, t_node_type type);
30 
31 int handle_redir(t_ast *node, t_shell *shell);
32 
33 /* ────────────── executor_pipe.c ──────────────── */
34 
35 void exec_right_pipe_child(t_ast *right, int pipe_fd[2], t_shell *shell);
36 
37 void exec_left_pipe_child(t_ast *left, int pipe_fd[2], t_shell *shell);
38 
39 int handle_pipe(t_ast *node, t_shell *shell);
40 
41 /* ────────────── exec_utils.c ──────────────── */
42 
43 int exec_cmd_not_found(char *cmd);
44 
45 int is_builtin(char *cmd);
46 
47 int exec_builtin(char **args, t_shell *shell);
48 
49 int exec_simple_command(char **args, t_shell *shell);
50 
51 int pipe_fork_error(int pipe_fd[2], pid_t left_pid);
52 
53 /* ────────────── path.c ──────────────── */
54 
55 char *search_in_dir(char *dir, char *cmd);
56 
57 char *find_cmd_path(char *cmd, t_env *env);
58 
59 /* ────────────── exec_cmd.c ──────────────── */
60 
61 int exec_external(char **args, t_shell *shell);
62 
63 /* ────────────── heredoc.c ──────────────── */
64 
65 int handle_heredoc(char *delimiter, int quoted, t_shell *shell);
66 
67 /* ────────────── heredoc_collect.c ──────────────── */
68 
69 int walk_heredocs(t_ast *node, t_shell *shell);
70 
71 int collect_heredocs(t_ast *node, t_shell *shell);
72 
73 /* ────────────── B O N U S ──────────────── */
74 
77 int handle_and_or(t_ast *node, t_shell *shell);
78 
79 int handle_subshell(t_ast *node, t_shell *shell);
80 
83 #endif
int exec_cmd_not_found(char *cmd)
Print "command not found" to STDERR.
Definition: exec_utils.c:25
char * find_cmd_path(char *cmd, t_env *env)
Resolve a command name into its full executable path.
Definition: path.c:115
int handle_heredoc(char *delimiter, int quoted, t_shell *shell)
Execute a heredoc (read input and return a readable fd)
Definition: heredoc.c:133
int setup_redirection(int fd, t_node_type type)
Redirect STDIN or STDOUT to fd, saving the original.
void exec_left_pipe_child(t_ast *left, int pipe_fd[2], t_shell *shell)
Execute the left side of a pipe in a child process.
Definition: executor_pipe.c:33
int open_redir_file(char *file, t_node_type type)
Open a file for redirection (based on the redirection type)
int exec_simple_command(char **args, t_shell *shell)
Execute a simple command (builtin or external)
Definition: exec_utils.c:95
int handle_redir(t_ast *node, t_shell *shell)
Execute a redirection node.
int exec_builtin(char **args, t_shell *shell)
Dispatch a builtin command to its function.
Definition: exec_utils.c:67
int executor(t_ast *node, t_shell *shell)
Main AST executor that dispatches by node type.
Definition: executor.c:42
int walk_heredocs(t_ast *node, t_shell *shell)
Recursively walk the AST collecting all heredocs.
int handle_pipe(t_ast *node, t_shell *shell)
Execute a pipe node by forking left and right children.
int exec_external(char **args, t_shell *shell)
Fork and execute an external command.
Definition: exec_cmd.c:150
int pipe_fork_error(int pipe_fd[2], pid_t left_pid)
Clean up pipe fds and wait for left child on fork failure.
Definition: exec_utils.c:111
int collect_heredocs(t_ast *node, t_shell *shell)
Pre collect all heredocs in the AST before the execution phase.
void exec_right_pipe_child(t_ast *right, int pipe_fd[2], t_shell *shell)
Execute the right side of a pipe in a child process.
Definition: executor_pipe.c:60
void restore_fd(int saved_fd, t_node_type type)
Restore a previously saved file descriptor.
int is_builtin(char *cmd)
Check if a command is a shell builtin.
Definition: exec_utils.c:39
char * search_in_dir(char *dir, char *cmd)
Search an executable command in a directory.
Definition: path.c:61
Central type definitions for mandatory part.
t_node_type
AST node types.
Definition: structs.h:51
AST node (union based ↑)
Definition: structs.h:151
Environment variable (doubly linked list)
Definition: structs.h:87
Shell state.
Definition: structs.h:164