diff options
| author | Christopher Uhlig | 2024-10-17 15:32:43 +0200 |
|---|---|---|
| committer | Christopher Uhlig | 2024-10-17 15:32:43 +0200 |
| commit | c1ac406e52fe273a0e14b0f079b522e58c04acd3 (patch) | |
| tree | 05d2a6c6c838ade625baf9a13e3a6ff0a3663739 /src/print_ast.c | |
| parent | 9298e72de61af5311678c656c12fc177589671a7 (diff) | |
| parent | 92bdbf67adaf09d1c831db3cee9456e9c447063f (diff) | |
| download | minishell-c1ac406e52fe273a0e14b0f079b522e58c04acd3.tar.gz minishell-c1ac406e52fe273a0e14b0f079b522e58c04acd3.zip | |
Merge branch 'env' of https://github.com/dpu-kaiser/minishell into env
Diffstat (limited to 'src/print_ast.c')
| -rw-r--r-- | src/print_ast.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/print_ast.c b/src/print_ast.c new file mode 100644 index 0000000..d42a67d --- /dev/null +++ b/src/print_ast.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* print_ast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/22 15:16:53 by dkaiser #+# #+# */ +/* Updated: 2024/09/17 15:09:04 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static void print_ast_rec(t_node *ast, int indent); +static void print_cmd_node(t_node *ast, int indent); + +void print_ast(t_node *ast) +{ + if (DEBUG) + { + printf("\e[94m[AST]\n"); + print_ast_rec(ast, 0); + printf("\e[0m\n"); + } +} + +static void print_ast_rec(t_node *ast, int indent) +{ + if (!ast) + panic("Can't print AST!"); + else if (ast->type == CMD_NODE) + print_cmd_node(ast, indent); + else if (ast->type == PIPE_NODE) + { + printf("\n%*s%s", indent, "", "* PIPE"); + print_ast_rec(ast->content.pipe.left, indent + 2); + print_ast_rec(ast->content.pipe.right, indent + 2); + } +} + +static void print_cmd_node(t_node *ast, int indent) +{ + int i; + + printf("\n%*s%s", indent, "", "* CMD"); + i = 0; + printf("\n%*sARGS:", indent + 2, ""); + while (ast->content.cmd.args != NULL && ast->content.cmd.args[i] != NULL) + { + printf(" '%s'", ast->content.cmd.args[i]); + i++; + } + printf("\n%*sREDIRS:", indent + 2, ""); + printf("\n%*sIN: %d %s", indent + 4, "", ast->content.cmd.redirs[0].type, + ast->content.cmd.redirs[0].specifier); + printf("\n%*sOUT: %d %s", indent + 4, "", ast->content.cmd.redirs[1].type, + ast->content.cmd.redirs[1].specifier); +} |
