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

Go to the source code of this file.

Functions

t_astparse_tokens (t_token **tokens, t_ms_data *data)
 
t_astcreate_pipe_node (t_token *next_token, t_token **tokens, t_ms_data *data, t_token *tmp)
 
t_astmanage_pipe (t_token **tokens, t_ms_data *data)
 
t_astmanage_commands (t_token **tokens, t_ms_data *data)
 
int cmd_arg_len (t_token *current)
 

Function Documentation

◆ cmd_arg_len()

int cmd_arg_len ( t_token current)

Definition at line 88 of file AST_utils.c.

89{
90 int i;
91
92 i = 0;
93 while (current && current->type == PHRASE)
94 {
95 i++;
96 current = current->next;
97 }
98 return (i);
99}
t_token_type type
Definition tokens.h:43
struct s_token * next
Definition tokens.h:45
@ PHRASE
Definition tokens.h:31

References s_token::next, PHRASE, and s_token::type.

Referenced by manage_commands().

Here is the caller graph for this function:

◆ create_pipe_node()

t_ast * create_pipe_node ( t_token next_token,
t_token **  tokens,
t_ms_data data,
t_token tmp 
)

Definition at line 30 of file AST_utils.c.

32{
33 t_ast *pipe_node;
34
35 pipe_node = new_ast_node();
36 if (!pipe_node)
37 return (NULL);
38 pipe_node->type = next_token->type;
39 pipe_node->args = malloc(sizeof(char *) * 2);
40 if (!pipe_node->args)
41 {
42 free(pipe_node);
43 return (NULL);
44 }
45 pipe_node->args[0] = ft_strdup(next_token->data);
46 pipe_node->args[1] = NULL;
47 pipe_node->left = manage_redirs(&tmp, data);
48 *tokens = next_token->next;
49 if (next_token->next)
50 pipe_node->right = manage_pipe(tokens, data);
51 else
52 pipe_node->right = NULL;
53 return (pipe_node);
54}
t_ast * manage_pipe(t_token **tokens, t_ms_data *data)
Definition AST_utils.c:56
char * ft_strdup(const char *s)
Definition ft_strdup.c:23
Definition tokens.h:50
char ** args
Definition tokens.h:52
struct s_ast * right
Definition tokens.h:54
struct s_ast * left
Definition tokens.h:53
t_token_type type
Definition tokens.h:51
char * data
Definition tokens.h:44
t_ast * new_ast_node(void)
Definition AST.c:89
t_ast * manage_redirs(t_token **tokens, t_ms_data *data)
Definition AST.c:20

References s_ast::args, s_token::data, ft_strdup(), s_ast::left, manage_pipe(), manage_redirs(), new_ast_node(), s_token::next, s_ast::right, s_token::type, and s_ast::type.

Referenced by manage_pipe().

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

◆ manage_commands()

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

Definition at line 72 of file AST_utils.c.

73{
74 t_ast *command_node;
75 int cmd_arg_count;
76
77 command_node = new_ast_node();
78 command_node->type = PHRASE;
79 cmd_arg_count = cmd_arg_len(*tokens);
80 command_node->args = malloc(sizeof(char *) * (cmd_arg_count + 1));
81 if (!command_node->args)
82 return (NULL);
83 set_command_args(command_node, tokens, cmd_arg_count);
84 post_process_command_args(command_node, cmd_arg_count, data);
85 return (command_node);
86}
int cmd_arg_len(t_token *current)
Definition AST_utils.c:88
void set_command_args(t_ast *command_node, t_token **tokens, int arg_count)
Definition AST.c:48
void post_process_command_args(t_ast *command_node, int arg_count, t_ms_data *data)

References s_ast::args, cmd_arg_len(), new_ast_node(), PHRASE, post_process_command_args(), set_command_args(), and s_ast::type.

Referenced by manage_redirs().

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

◆ manage_pipe()

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

Definition at line 56 of file AST_utils.c.

57{
58 t_token *tmp;
59 t_token *next_token;
60
61 tmp = *tokens;
62 while (*tokens && (*tokens)->next)
63 {
64 next_token = (*tokens)->next;
65 if (next_token->type == PIPE)
66 return (create_pipe_node(next_token, tokens, data, tmp));
67 *tokens = next_token;
68 }
69 return (manage_redirs(&tmp, data));
70}
t_ast * create_pipe_node(t_token *next_token, t_token **tokens, t_ms_data *data, t_token *tmp)
Definition AST_utils.c:30
@ PIPE
Definition tokens.h:32

References create_pipe_node(), manage_redirs(), s_token::next, PIPE, and s_token::type.

Referenced by create_pipe_node(), and parse_tokens().

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

◆ parse_tokens()

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

Definition at line 23 of file AST_utils.c.

24{
25 if (!tokens || !*tokens)
26 return (NULL);
27 return (manage_pipe(tokens, data));
28}

References manage_pipe().

Referenced by main_loop().

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