maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
AST.c File Reference
#include "tokens.h"
Include dependency graph for AST.c:

Go to the source code of this file.

Functions

t_astmanage_redirs (t_token **tokens, t_ms_data *data)
 
t_astcreate_redir_node (t_token *token)
 
int is_redir_node (t_token *tokens)
 
t_astnew_ast_node (void)
 
void set_command_args (t_ast *command_node, t_token **tokens, int arg_count)
 

Function Documentation

◆ create_redir_node()

t_ast * create_redir_node ( t_token token)

Definition at line 62 of file AST.c.

63{
64 t_ast *node;
65
66 node = new_ast_node();
67 node->type = token->type;
68 node->args = malloc(sizeof(char *) * 2);
69 if (!node->args)
70 {
71 free(node);
72 return (NULL);
73 }
74 node->args[0] = ft_strdup(token->data);
75 node->args[1] = NULL;
76 return (node);
77}
t_ast * new_ast_node(void)
Definition AST.c:89
char * ft_strdup(const char *s)
Definition ft_strdup.c:23
Definition tokens.h:50
char ** args
Definition tokens.h:52
t_token_type type
Definition tokens.h:51
t_token_type type
Definition tokens.h:43
char * data
Definition tokens.h:44

References s_ast::args, s_token::data, ft_strdup(), new_ast_node(), s_token::type, and s_ast::type.

Referenced by manage_redirs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_redir_node()

int is_redir_node ( t_token tokens)

Definition at line 79 of file AST.c.

80{
81 if (tokens->type == REDIR_IN
82 || tokens->type == REDIR_OUT
83 || tokens->type == REDIR_APPEND
84 || tokens->type == REDIR_HEREDOC)
85 return (1);
86 return (0);
87}
@ REDIR_IN
Definition tokens.h:34
@ REDIR_HEREDOC
Definition tokens.h:37
@ REDIR_OUT
Definition tokens.h:35
@ REDIR_APPEND
Definition tokens.h:36

References REDIR_APPEND, REDIR_HEREDOC, REDIR_IN, REDIR_OUT, and s_token::type.

Referenced by manage_redirs().

Here is the caller graph for this function:

◆ manage_redirs()

t_ast * manage_redirs ( t_token **  tokens,
t_ms_data data 
)

Definition at line 20 of file AST.c.

21{
22 t_ast *command_node;
23 t_ast *redirect_node;
24 t_token *current_token;
25
26 if (!tokens || !*tokens)
27 return (NULL);
28 command_node = manage_commands(tokens, data);
29 current_token = *tokens;
30 while (current_token && is_redir_node(current_token))
31 {
32 redirect_node = create_redir_node(current_token);
33 redirect_node->left = command_node;
34 *tokens = current_token->next;
35 if (*tokens)
36 {
37 redirect_node->right = create_redir_node(*tokens);
38 *tokens = (*tokens)->next;
39 }
40 else
41 redirect_node->right = NULL;
42 command_node = redirect_node;
43 current_token = *tokens;
44 }
45 return (command_node);
46}
t_ast * create_redir_node(t_token *token)
Definition AST.c:62
int is_redir_node(t_token *tokens)
Definition AST.c:79
struct s_ast * right
Definition tokens.h:54
struct s_ast * left
Definition tokens.h:53
struct s_token * next
Definition tokens.h:45
t_ast * manage_commands(t_token **tokens, t_ms_data *data)
Definition AST_utils.c:72

References create_redir_node(), is_redir_node(), s_ast::left, manage_commands(), s_token::next, and s_ast::right.

Referenced by create_pipe_node(), and manage_pipe().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ new_ast_node()

t_ast * new_ast_node ( void  )

Definition at line 89 of file AST.c.

90{
91 t_ast *node;
92
93 node = malloc(sizeof(t_ast));
94 if (!node)
95 return (NULL);
96 node->type = NONE;
97 node->args = NULL;
98 node->left = NULL;
99 node->right = NULL;
100 return (node);
101}
@ NONE
Definition tokens.h:38

References s_ast::args, s_ast::left, NONE, s_ast::right, and s_ast::type.

Referenced by create_pipe_node(), create_redir_node(), and manage_commands().

Here is the caller graph for this function:

◆ set_command_args()

void set_command_args ( t_ast command_node,
t_token **  tokens,
int  arg_count 
)

Definition at line 48 of file AST.c.

49{
50 int i;
51
52 i = 0;
53 while (i < arg_count)
54 {
55 command_node->args[i] = ft_strdup((*tokens)->data);
56 *tokens = (*tokens)->next;
57 i++;
58 }
59 command_node->args[arg_count] = NULL;
60}

References s_ast::args, ft_strdup(), and s_token::next.

Referenced by manage_commands().

Here is the call graph for this function:
Here is the caller graph for this function: