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

Go to the source code of this file.

Functions

const char * get_token_type_name (t_token_type type)
 
void print_ast_node (t_ast *node, int depth, char *prefix, int is_left)
 
void build_new_prefix (char *new_prefix, char *prefix, int is_left)
 
void print_ast_graphical (t_ast *node, int depth, char *prefix, int is_left)
 
void print_ast_root (t_ast *root)
 

Function Documentation

◆ build_new_prefix()

void build_new_prefix ( char *  new_prefix,
char *  prefix,
int  is_left 
)

Definition at line 63 of file visualiser.c.

64{
65 int i;
66 int j;
67
68 i = 0;
69 j = 0;
70 while (prefix[i])
71 {
72 new_prefix[j] = prefix[i];
73 i++;
74 j++;
75 }
76 if (is_left)
77 {
78 new_prefix[j++] = '|';
79 new_prefix[j++] = ' ';
80 new_prefix[j++] = ' ';
81 }
82 else
83 {
84 new_prefix[j++] = ' ';
85 new_prefix[j++] = ' ';
86 new_prefix[j++] = ' ';
87 }
88 new_prefix[j] = '\0';
89}

Referenced by print_ast_graphical().

Here is the caller graph for this function:

◆ get_token_type_name()

const char * get_token_type_name ( t_token_type  type)

Definition at line 15 of file visualiser.c.

16{
17 if (type == PHRASE)
18 return ("PHRASE");
19 else if (type == PIPE)
20 return ("PIPE");
21 else if (type == ENV_VAR)
22 return ("ENV_VAR");
23 else if (type == REDIR_IN)
24 return ("REDIR_IN");
25 else if (type == REDIR_OUT)
26 return ("REDIR_OUT");
27 else if (type == REDIR_APPEND)
28 return ("REDIR_APPEND");
29 else if (type == REDIR_HEREDOC)
30 return ("REDIR_HEREDOC");
31 else
32 return ("UNKNOWN");
33}
@ REDIR_IN
Definition tokens.h:34
@ PHRASE
Definition tokens.h:31
@ REDIR_HEREDOC
Definition tokens.h:37
@ PIPE
Definition tokens.h:32
@ REDIR_OUT
Definition tokens.h:35
@ REDIR_APPEND
Definition tokens.h:36
@ ENV_VAR
Definition tokens.h:33

References ENV_VAR, PHRASE, PIPE, REDIR_APPEND, REDIR_HEREDOC, REDIR_IN, and REDIR_OUT.

Referenced by print_ast_node().

Here is the caller graph for this function:

◆ print_ast_graphical()

void print_ast_graphical ( t_ast node,
int  depth,
char *  prefix,
int  is_left 
)

Definition at line 91 of file visualiser.c.

92{
93 char new_prefix[256];
94
95 print_ast_node(node, depth, prefix, is_left);
96 build_new_prefix(new_prefix, prefix, is_left);
97 if (node->left)
98 print_ast_graphical(node->left, depth + 1, new_prefix, 1);
99 if (node->right)
100 print_ast_graphical(node->right, depth + 1, new_prefix, 0);
101}
struct s_ast * right
Definition tokens.h:54
struct s_ast * left
Definition tokens.h:53
void print_ast_node(t_ast *node, int depth, char *prefix, int is_left)
Definition visualiser.c:35
void print_ast_graphical(t_ast *node, int depth, char *prefix, int is_left)
Definition visualiser.c:91
void build_new_prefix(char *new_prefix, char *prefix, int is_left)
Definition visualiser.c:63

References build_new_prefix(), s_ast::left, print_ast_graphical(), print_ast_node(), and s_ast::right.

Referenced by print_ast_graphical(), and print_ast_root().

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

◆ print_ast_node()

void print_ast_node ( t_ast node,
int  depth,
char *  prefix,
int  is_left 
)

Definition at line 35 of file visualiser.c.

36{
37 int i;
38
39 if (!node)
40 return ;
41 ft_printf("%s", prefix);
42 if (depth == 0)
43 ft_printf("Root-> ");
44 else
45 {
46 if (is_left)
47 ft_printf("L-> ");
48 else
49 ft_printf("R-> ");
50 }
51 ft_printf("Type: %s\n", get_token_type_name(node->type));
52 if (node->args)
53 {
54 i = 0;
55 while (node->args[i])
56 {
57 ft_printf("%s Arg: %s\n", prefix, node->args[i]);
58 i++;
59 }
60 }
61}
int ft_printf(const char *format,...)
Definition ft_printf.c:37
char ** args
Definition tokens.h:52
t_token_type type
Definition tokens.h:51
const char * get_token_type_name(t_token_type type)
Definition visualiser.c:15

References s_ast::args, ft_printf(), get_token_type_name(), and s_ast::type.

Referenced by print_ast_graphical().

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

◆ print_ast_root()

void print_ast_root ( t_ast root)

Definition at line 103 of file visualiser.c.

104{
105 if (!root)
106 return ;
107 print_ast_graphical(root, 0, "", 0);
108}

References print_ast_graphical().

Here is the call graph for this function: