#include "ast.h" #include 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; }