From bf97035e8d444c141725c0cf91aaaa285ae712af Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 18 Jun 2020 14:34:27 +0200 Subject: Fixing little bug in env_search --- src/debug.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/debug.c (limited to 'src/debug.c') diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 0000000..cde4e4c --- /dev/null +++ b/src/debug.c @@ -0,0 +1,59 @@ + +#include +#include "lexer.h" +#include "ast.h" + +void token_debug(void *v) +{ + t_token *t; + + t= v; + printf("[%4d %d] (%s)\n", t->tag, !!(t->tag & TAG_STICK), t->content); +} + +void token_put(void *v) +{ + t_token *t; + + t= v; + printf("%s ", t->content); +} + +void print_level(int level) +{ + while (level-- > 0) + printf(" "); +} + +void ast_print(int level, t_ast *ast) +{ + if (ast->tag == AST_CMD) + { + print_level(level); + printf("cmd: [ "); + ft_lstiter(ast->cmd_argv, token_put); + printf(" ] redirs: ["); + ft_lstiter(ast->redirs, token_put); + printf(" ]"); + } + else + { + /* print_level(level); */ + /* printf("SEP: %d\n", ast->op.sep); */ + print_level(level); + printf("{\n"); + + print_level(level); + printf(" left:\n"); + ast_print(level + 1, ast->op.left); + + printf("\n"); + print_level(level); + printf(" right:\n"); + ast_print(level + 1, ast->op.right); + + printf("\n"); + print_level(level); + printf("}\n"); + } +} -- cgit