42sh/src/utils/ast/ast.c
Jean Herail e9b6d39760 Implemented some ast handlings...
ast lists, and_or, redirection and builtins
2026-01-17 23:55:59 +00:00

35 lines
806 B
C

#include "ast.h"
#include <stdbool.h>
void ast_free(struct ast **node)
{
if (*node == NULL)
return;
// ast void does not need to be freed.
if (ast_is_if(*node))
ast_free_if(ast_get_if(*node));
else if (ast_is_command(*node))
ast_free_command(ast_get_command(*node));
else if (ast_is_list(*node))
ast_free_list(ast_get_list(*node));
else if (ast_is_and_or(*node))
ast_free_and_or(ast_get_and_or(*node));
else if (ast_is_redir(*node))
ast_free_redir(ast_get_redir(*node));
free(*node);
*node = NULL;
}
struct ast *ast_create(enum ast_type type, void *data)
{
struct ast *node = malloc(sizeof(struct ast));
if (node == NULL)
return NULL;
node->type = type;
node->data = data;
return node;
}