MiniDevil As beautiful as a shell
ast.c File Reference

AST node creation: allocates command, pipe & redirection nodes. More...

#include "ast.h"
#include "libft.h"
+ Include dependency graph for ast.c:

Detailed Description

AST node creation: allocates command, pipe & redirection nodes.

Definition in file ast.c.

Functions

t_astcreate_cmd_node (char **args, int argc)
 Create a NODE_COMMAND AST node. More...
 
t_astcreate_pipe_node (t_ast *left, t_ast *right)
 Create a pipe AST node connecting 2 subtrees. More...
 
t_astcreate_redir_node (t_node_type type, char *file, t_ast *cmd, int quoted)
 Create a redirection AST node. More...
 

Function Documentation

◆ create_cmd_node()

t_ast* create_cmd_node ( char **  args,
int  argc 
)

Create a NODE_COMMAND AST node.

Parameters
argsArgument array (NULL terminated)
argcArgument count
Returns
New command node or NULL on failure

Definition at line 23 of file ast.c.

References t_cmd_node::argc, t_cmd_node::args, t_ast_data::cmd, t_ast::data, NODE_COMMAND, and t_ast::type.

Referenced by parse_simple_command().

+ Here is the caller graph for this function:

◆ create_pipe_node()

t_ast* create_pipe_node ( t_ast left,
t_ast right 
)

Create a pipe AST node connecting 2 subtrees.

Parameters
leftLeft child (command before the pipe)
rightRight child (command after the pipe)
Returns
New pipe node or NULL on failure

Definition at line 43 of file ast.c.

References t_ast_data::binary, t_ast::data, free_ast(), t_binary_node::left, NODE_PIPE, t_binary_node::right, and t_ast::type.

Referenced by parse_pipeline().

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

◆ create_redir_node()

t_ast* create_redir_node ( t_node_type  type,
char *  file,
t_ast cmd,
int  quoted 
)

Create a redirection AST node.

Initializes heredoc_fd to -1 (not used)

Parameters
typeRedirection type
fileFilename or heredoc delimiter
cmdCommand subtree that this redirection wraps
quoted1 if heredoc delimiter was quoted
Returns
New redirection node or NULL on failure

Definition at line 71 of file ast.c.

References t_redir_node::cmd, t_ast::data, t_redir_node::file, t_redir_node::heredoc_fd, t_redir_node::quote, t_ast_data::redir, t_redir_node::redir_type, and t_ast::type.

Referenced by parse_one_redirection().

+ Here is the caller graph for this function:

Go to the source code of this file.