Implemented some ast handlings...

ast lists, and_or, redirection and builtins
This commit is contained in:
Jean Herail 2026-01-17 17:33:22 +01:00
parent 1fc54e2bf3
commit bf992f2db4
10 changed files with 359 additions and 14 deletions

36
src/utils/ast/ast_redir.c Normal file
View file

@ -0,0 +1,36 @@
#include "utils/ast/ast_redir.h"
#include <stdlib.h>
bool ast_is_redir(struct ast *node)
{
return node != NULL && node->type == AST_REDIR;
}
struct ast_redir *ast_get_redir(struct ast *node)
{
if (ast_is_redir(node))
return (struct ast_redir *)node->data;
return NULL;
}
struct ast *ast_create_redir(struct ast *child, char *filename, int io_number, enum ast_redir_type type)
{
struct ast_redir *redir = malloc(sizeof(struct ast_redir));
if (!redir)
return NULL;
redir->child = child;
redir->filename = filename; // Takes ownership? Usually yes in simple ASTs, or dup. Let's assume pointer copy for now, but user must manage memory.
redir->io_number = io_number;
redir->type = type;
return ast_create(AST_REDIR, redir);
}
void ast_free_redir(struct ast_redir *redir)
{
if (!redir)
return;
ast_free(&redir->child);
free(redir->filename);
free(redir);
}