summaryrefslogtreecommitdiff
path: root/42sh/src/exec/ast_exec_functions.h
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /42sh/src/exec/ast_exec_functions.h
add: added projectsHEADmain
Diffstat (limited to '42sh/src/exec/ast_exec_functions.h')
-rw-r--r--42sh/src/exec/ast_exec_functions.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/42sh/src/exec/ast_exec_functions.h b/42sh/src/exec/ast_exec_functions.h
new file mode 100644
index 0000000..ba2fbcd
--- /dev/null
+++ b/42sh/src/exec/ast_exec_functions.h
@@ -0,0 +1,77 @@
+#ifndef AST_EXEC_FUNCTIONS_H
+#define AST_EXEC_FUNCTIONS_H
+
+#include "builtins/builtins.h"
+#include "exec/ast_eval.h"
+
+#define BASE_RW_SIZE 256
+
+typedef int (*exec_f)(struct ast *ast);
+
+/**
+ * @brief Evaluates the given AST and return the exit code of it.
+ * A command can be a shell builtin or an external binary file called with
+ * `execvp`.
+ * @param ast An `AST_COMMAND` AST to evaluate. It is given as a `struct ast*`
+ * and uses inheritance-like principle.
+ */
+int exec_ast_command(struct ast *ast);
+
+/**
+ * @brief Evaluates the given AST and return the exit code of it.
+ * It performs a lazy evaluation.
+ * @param ast An `AST_LOGICAL` AST to evaluate. It is given as a `struct ast*`
+ * and uses inheritance-like principle.
+ */
+int exec_ast_logical(struct ast *ast);
+
+/**
+ * @brief Evaluates the given AST and return the exit code of the last
+ * `AST_COMMAND`.
+ * @param ast An `AST_LIST` AST to evaluate. It is given as a `struct ast*`
+ * and uses inheritance-like principle.
+ */
+int exec_ast_list(struct ast *ast);
+
+/**
+ * @brief Evaluates the given AST and return the exit code of it.
+ * It performs a lazy evaluation.
+ * @param ast An `AST_IF` AST to evaluate. It is given as a `struct ast*`
+ * and uses inheritance-like principle.
+ */
+int exec_ast_if(struct ast *ast);
+
+/**
+ * @brief Evaluates the given AST and return the exit code of it.
+ * It redirects the standard output of `ast->left` to the standard input of
+ * `ast->right`.
+ * @param ast An `AST_PIPELINE` AST to evaluate. It is given as a `struct ast*`
+ * and uses inheritance-like principle.
+ */
+int exec_ast_pipe(struct ast *ast);
+
+/**
+ * @brief Evaluates the given AST and return the exit code of it.
+ * It gets the redirection details from `ast->redir` which is a `struct
+ * redirect`.
+ * @param ast An `AST_REDIRECTION` AST to evaluate. It is given as a `struct
+ * ast*` and uses inheritance-like principle.
+ */
+int exec_ast_redirection(struct ast *ast);
+
+int exec_ast_while(struct ast *ast);
+
+int exec_ast_assign(struct ast *ast);
+
+int exec_ast_for(struct ast *ast);
+
+/**
+ * @brief Evaluates the given AST and return the exit code of it.
+ * It gets the ast corresponding to the subshell and executes it in a new
+ * environment thanks to the fork(2) function.
+ * @param ast An `AST_SUBSHELL` AST to evaluate It is given as a `struct ast*`
+ * and uses inheritance-like principle.
+ */
+int exec_ast_subshell(struct ast *ast);
+
+#endif /* ! AST_EXEC_FUNCTIONS_H */