1- /* ************************************************************************** */
2- /* */
3- /* ::: :::::::: */
4- /* executor.h :+: :+: :+: */
5- /* +:+ +:+ +:+ */
6- /* By: marvin <marvin@student.42.fr> +#+ +:+ +#+ */
7- /* +#+#+#+#+#+ +#+ */
8- /* Created: 2026/01/10 02:38:39 by marvin #+# #+# */
9- /* Updated: 2026/01/10 02:38:39 by marvin ### ########.fr */
10- /* */
11- /* ************************************************************************** */
12-
13- /* Executor public API: turning an AST into side-effects.
14- The main entry is execute_top_level() which walks the tree returned by
15- the parser. Every execute_* function returns t_execution_state so the
16- exit code and any ctrl-c signal propagate up cleanly. */
17-
18- #ifndef EXECUTOR_H
19- # define EXECUTOR_H
20-
21- # include "public/executor_types.h"
22- # include "alias.h"
23-
24- /* forward declarations to avoid heavy includes */
25- typedef struct s_shell t_shell ;
26- typedef struct s_ast_node t_ast_node ;
27-
28- /* An expanded, ready-to-run simple command: pre-command assignments,
29- the argv array, and the resolved executable path. pooled=true means
30- argv.ctx comes from argv_pool (don't free it, just reset the vec). */
31- typedef struct executable_cmd_s
32- {
33- t_vec_env pre_assigns ; /* NAME=VALUE pairs before the command */
34- t_vec argv ; /* NULL-terminated argv word list */
35- char * fname ; /* resolved path (heap) or NULL for builtins */
36- bool pooled ; /* true if argv was borrowed from argv_pool */
37- } t_executable_cmd ;
38-
39- /* argv backing pool (free_utils2.c): borrow on expand, return on teardown. */
40- void argv_pool_acquire (t_shell * state , t_executable_cmd * cmd );
41- void argv_pool_release (t_shell * state , t_executable_cmd * cmd );
42- void free_argv_pool (t_shell * state );
43-
44- /* Execution context for one node in the pipeline: which fds to hook up,
45- which AST node to execute, and whether this command runs in the parent
46- process (builtins, function calls) and is allowed to modify state. */
47- typedef struct executable_node_s
48- {
49- int infd ; /* read end of pipe from previous stage */
50- int outfd ; /* write end of pipe to next stage */
51- int next_infd ; /* saved next read end (pipeline setup) */
52- t_ast_node * node ; /* the AST node being executed */
53- t_vec_int redirs ; /* indices into state->redirects */
54- bool modify_parent_ctx ; /* true for builtins that modify state */
55- } t_executable_node ;
56-
57- void execute_top_level (t_shell * state );
58- int exec_string (t_shell * state , char * str );
59- int exec_file_string (t_shell * state , char * str ,
60- const char * src );
61- t_execution_state execute_pipeline (t_shell * state ,
62- t_executable_node * exe );
63- void set_up_redirection (t_shell * state ,
64- t_executable_node * exe );
65- t_execution_state execute_simple_command (t_shell * state ,
66- t_executable_node * exe );
67- void forward_exit_status (t_execution_state res );
68- t_execution_state execute_command (t_shell * state ,
69- t_executable_node * exe );
70- t_execution_state execute_tree_node (t_shell * state ,
71- t_executable_node * exe );
72- t_execution_state execute_simple_list (t_shell * state ,
73- t_executable_node * exe );
74- t_string word_to_string (t_ast_node node );
75- t_string word_to_hrdoc_string (t_ast_node node );
76- void set_cmd_status (t_shell * state , t_execution_state res );
77- t_execution_state res_status (int status );
78- t_execution_state res_pid (int pid );
79- void fire_debug_trap (t_shell * state );
80- void fire_err_trap (t_shell * state , int code );
81- void fire_return_trap (t_shell * state , int code );
82- void trap_save_reset (t_shell * state , char * * save );
83- void pseudo_traps_quiet (t_shell * state );
84- void trap_restore (t_shell * state , char * * save );
85- void exe_res_set_status (t_shell * st , t_execution_state * res );
86- int find_cmd_path (t_shell * state , char * cmd_name ,
87- char * * path_of_exe );
88- int exec_external_argv (t_shell * state , t_vec * args );
89- int run_external_sync (t_shell * state , t_vec * args );
90- int expand_simple_command (t_shell * state , t_ast_node * node ,
91- t_executable_cmd * ret , t_vec_int * redirects );
92- int (* builtin_func (char * name ))(t_shell * state , t_vec argv );
93-
1+ /* ************************************************************************** */
2+ /* */
3+ /* ::: :::::::: */
4+ /* executor.h :+: :+: :+: */
5+ /* +:+ +:+ +:+ */
6+ /* By: marvin <marvin@student.42.fr> +#+ +:+ +#+ */
7+ /* +#+#+#+#+#+ +#+ */
8+ /* Created: 2026/01/10 02:38:39 by marvin #+# #+# */
9+ /* Updated: 2026/01/10 02:38:39 by marvin ### ########.fr */
10+ /* */
11+ /* ************************************************************************** */
12+
13+ /* Executor public API: turning an AST into side-effects.
14+ The main entry is execute_top_level() which walks the tree returned by
15+ the parser. Every execute_* function returns t_execution_state so the
16+ exit code and any ctrl-c signal propagate up cleanly. */
17+
18+ #ifndef EXECUTOR_H
19+ # define EXECUTOR_H
20+
21+ # include "public/executor_types.h"
22+ # include "alias.h"
23+
24+ /* forward declarations to avoid heavy includes */
25+ typedef struct s_shell t_shell ;
26+ typedef struct s_ast_node t_ast_node ;
27+
28+ /* An expanded, ready-to-run simple command: pre-command assignments,
29+ the argv array, and the resolved executable path. pooled=true means
30+ argv.ctx comes from argv_pool (don't free it, just reset the vec). */
31+ typedef struct executable_cmd_s
32+ {
33+ t_vec_env pre_assigns ; /* NAME=VALUE pairs before the command */
34+ t_vec argv ; /* NULL-terminated argv word list */
35+ char * fname ; /* resolved path (heap) or NULL for builtins */
36+ bool pooled ; /* true if argv was borrowed from argv_pool */
37+ } t_executable_cmd ;
38+
39+ /* argv backing pool (free_utils2.c): borrow on expand, return on teardown. */
40+ void argv_pool_acquire (t_shell * state , t_executable_cmd * cmd );
41+ void argv_pool_release (t_shell * state , t_executable_cmd * cmd );
42+ void free_argv_pool (t_shell * state );
43+
44+ /* Execution context for one node in the pipeline: which fds to hook up,
45+ which AST node to execute, and whether this command runs in the parent
46+ process (builtins, function calls) and is allowed to modify state. */
47+ typedef struct executable_node_s
48+ {
49+ int infd ; /* read end of pipe from previous stage */
50+ int outfd ; /* write end of pipe to next stage */
51+ int next_infd ; /* saved next read end (pipeline setup) */
52+ t_ast_node * node ; /* the AST node being executed */
53+ t_vec_int redirs ; /* indices into state->redirects */
54+ bool modify_parent_ctx ; /* true for builtins that modify state */
55+ } t_executable_node ;
56+
57+ void execute_top_level (t_shell * state );
58+ int exec_string (t_shell * state , char * str );
59+ int exec_file_string (t_shell * state , char * str ,
60+ const char * src );
61+ t_execution_state execute_pipeline (t_shell * state ,
62+ t_executable_node * exe );
63+ void set_up_redirection (t_shell * state ,
64+ t_executable_node * exe );
65+ t_execution_state execute_simple_command (t_shell * state ,
66+ t_executable_node * exe );
67+ void forward_exit_status (t_execution_state res );
68+ t_execution_state execute_command (t_shell * state ,
69+ t_executable_node * exe );
70+ t_execution_state execute_tree_node (t_shell * state ,
71+ t_executable_node * exe );
72+ t_execution_state execute_simple_list (t_shell * state ,
73+ t_executable_node * exe );
74+ t_string word_to_string (t_ast_node node );
75+ t_string word_to_hrdoc_string (t_ast_node node );
76+ void set_cmd_status (t_shell * state , t_execution_state res );
77+ t_execution_state res_status (int status );
78+ t_execution_state res_pid (int pid );
79+ void fire_debug_trap (t_shell * state );
80+ void fire_err_trap (t_shell * state , int code );
81+ void fire_return_trap (t_shell * state , int code );
82+ void trap_save_reset (t_shell * state , char * * save );
83+ void pseudo_traps_quiet (t_shell * state );
84+ void trap_restore (t_shell * state , char * * save );
85+ void exe_res_set_status (t_shell * st , t_execution_state * res );
86+ int find_cmd_path (t_shell * state , char * cmd_name ,
87+ char * * path_of_exe );
88+ int exec_external_argv (t_shell * state , t_vec * args );
89+ int run_external_sync (t_shell * state , t_vec * args );
90+ int expand_simple_command (t_shell * state , t_ast_node * node ,
91+ t_executable_cmd * ret , t_vec_int * redirects );
92+ int (* builtin_func (t_shell * state , char * name ))(t_shell * s ,
93+ t_vec argv );
94+
9495#endif
0 commit comments