42sh/src/execution/execution.c

47 lines
1.1 KiB
C
Raw Normal View History

#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>
2026-01-22 12:09:18 +00:00
#include "../expansion/expansion.h"
#include "../utils/ast/ast.h"
2026-01-22 12:09:18 +00:00
#include "../utils/hash_map/hash_map.h"
// Refactored: delegates to helpers in execution_helpers.c
#include "execution_helpers.h"
2026-01-22 12:09:18 +00:00
int execution(struct ast *ast, struct hash_map *vars)
{
if (!ast)
return 0;
switch (ast->type)
{
2026-01-22 13:10:23 +00:00
case AST_VOID:
case AST_END:
return 0;
case AST_CMD: {
2026-01-15 18:49:42 +01:00
struct ast_command *command = ast_get_command(ast);
2026-01-22 12:09:18 +00:00
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);
default:
return 127;
}
}