42sh/src/execution/execution.c
2026-01-29 19:46:22 +00:00

48 lines
1.2 KiB
C

#define _POSIX_C_SOURCE 200809L
#include "execution.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "../expansion/expansion.h"
#include "../utils/ast/ast.h"
#include "../utils/hash_map/hash_map.h"
// Refactored: delegates to helpers in execution_helpers.c
#include "execution_helpers.h"
int execution(struct ast *ast, struct hash_map *vars)
{
if (!ast)
return 0;
switch (ast->type)
{
case AST_VOID:
case AST_END:
return 0;
case AST_CMD: {
struct ast_command *command = ast_get_command(ast);
if (!expand(command, vars))
fprintf(stderr, "Error: Variable expansion failed\n");
return exec_ast_command(command, vars);
}
case AST_IF:
return exec_ast_if(ast_get_if(ast), vars);
case AST_LIST:
return exec_ast_list(ast_get_list(ast), vars);
case AST_AND_OR:
return exec_ast_and_or(ast_get_and_or(ast), vars);
case AST_ASSIGNMENT:
return exec_ast_assignment(ast_get_assignment(ast), vars);
default:
return 127;
}
}