-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.c
More file actions
106 lines (100 loc) · 2.81 KB
/
debug.c
File metadata and controls
106 lines (100 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* debug.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sel-abbo <sel-abbo@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/07 18:05:36 by sel-abbo #+# #+# */
/* Updated: 2025/08/07 18:05:36 by sel-abbo ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/minishell.h"
void print_tokens(t_shell *shell)
{
t_token *current;
char *type_str;
current = shell->tokens;
printf("\nTokens:\n-----------------\n");
while (current)
{
if (current->type == WORD)
type_str = "WORD";
else if (current->type == PIPE)
type_str = "PIPE";
else if (current->type == INPUT)
type_str = "INPUT";
else if (current->type == OUTPUT)
type_str = "OUTPUT";
else if (current->type == HEREDOC)
type_str = "HEREDOC";
else if (current->type == APPEND)
type_str = "APPEND";
else if (current->type == SPACES)
type_str = "SPACES";
else if (current->type == AMBGUS)
type_str = "AMBGUS";
printf("[%-6s] = %s\n", type_str, current->value);
current = current->next;
}
printf("-----------------\n");
}
const char *get_redir_type_string(int type)
{
if (type == INPUT)
return ("REDIR_IN");
else if (type == OUTPUT)
return ("REDIR_OUT");
else if (type == APPEND)
return ("APPEND");
else if (type == HEREDOC)
return ("HEREDOC");
return ("UNKNOWN");
}
void print_redirs_fancy(t_redir *redir)
{
while (redir)
{
printf(" └─🔁 Redirection\n");
printf(" ├─ Type : %s\n",
get_redir_type_string(redir->type));
printf(" ├─ Target : %s\n",
redir->target ? redir->target : "(null)");
printf(" └─ HereDoc : %s\n",
redir->h_filename ? redir->h_filename : "(null)");
redir = redir->next;
}
}
void print_commands(t_command *cmd)
{
while (cmd)
{
printf(" ├─ Args: ");
if (cmd->args && cmd->args[0])
{
for (int i = 0; cmd->args[i]; i++)
{
printf("%s", cmd->args[i]);
if (cmd->args[i + 1])
printf(" ");
}
printf("\n");
}
else
{
printf(" ├─ Args : (null)\n");
}
if (cmd->redirs)
{
printf(" └─ Redirections:\n");
print_redirs_fancy(cmd->redirs);
}
else
{
printf(" └─ Redirections: (none)\n");
}
if (cmd->next)
printf(" ↓\n");
cmd = cmd->next;
}
}