feat: redirection rules

This commit is contained in:
Gu://em_ 2026-01-24 15:34:10 +01:00
parent 18c1da6bdf
commit 32f56beb6b
8 changed files with 218 additions and 25 deletions

View file

@ -9,6 +9,7 @@
#include "ast_list.h"
#include "ast_redir.h"
#include "ast_void.h"
#include "ast_word.h"
/**
* Prints the Graphviz DOT representation of the given AST to stdout.

View file

@ -11,7 +11,8 @@ enum ast_type
AST_AND_OR,
AST_REDIR,
AST_VOID,
AST_CMD
AST_CMD,
AST_WORD
};
struct ast

45
src/utils/ast/ast_word.c Normal file
View file

@ -0,0 +1,45 @@
#include "ast_word.h"
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
struct ast *ast_create_word(char *word)
{
struct ast_word *ast_node = malloc(sizeof(struct ast_word));
if (ast_node == NULL)
return NULL;
ast_node->type = AST_WORD;
ast_node->word = strdup(word);
struct ast *res = ast_create(AST_WORD, ast_node);
if (res == NULL)
{
free(ast_node);
return NULL;
}
return res;
}
struct ast_word *ast_get_word(struct ast *node)
{
if (node == NULL || node->type != AST_WORD)
return NULL;
return node->data;
}
bool ast_is_word(struct ast *node)
{
return node && node->type == AST_WORD;
}
void ast_free_word(struct ast_word *ast_node)
{
if (ast_node == NULL)
return;
free(ast_node->word);
free(ast_node);
}

35
src/utils/ast/ast_word.h Normal file
View file

@ -0,0 +1,35 @@
#ifndef AST_WORD_H
#define AST_WORD_H
#include <stdbool.h>
#include "ast_base.h"
struct ast_word
{
enum ast_type type;
char *word;
};
/**
* Checks if the given AST node is a command.
*/
bool ast_is_word(struct ast *node);
/**
* Retrieves the command data from the given AST node.
* Assumes that the node is of type AST_CMD.
*/
struct ast_word *ast_get_word(struct ast *node);
/**
* Creates a new AST node representing a command.
*/
struct ast *ast_create_word(char* word);
/*
* @brief: frees the given ast_command and sets the pointer to NULL.
*/
void ast_free_word(struct ast_word *ast_node);
#endif /* ! AST_WORD_H */