feat: redirection rules
This commit is contained in:
parent
18c1da6bdf
commit
32f56beb6b
8 changed files with 218 additions and 25 deletions
45
src/utils/ast/ast_word.c
Normal file
45
src/utils/ast/ast_word.c
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue