diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/debug.c | 122 | ||||
| -rw-r--r-- | src/debug/lexer.c | 37 | ||||
| -rw-r--r-- | src/debug/parser.c | 112 | ||||
| -rw-r--r-- | src/setup.c | 4 |
4 files changed, 150 insertions, 125 deletions
diff --git a/src/debug.c b/src/debug.c deleted file mode 100644 index a0e6770..0000000 --- a/src/debug.c +++ /dev/null @@ -1,122 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* debug.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/09/16 15:58:35 by charles #+# #+# */ -/* Updated: 2020/10/09 14:27:40 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "lexer.h" -#include "parser.h" - -void debug_tok_lst(t_tok_lst *tokens) -{ - while (tokens != NULL) - { - // FIXME libft for safer correction - printf("[%#06x] |%s|%s\n", tokens->tag, tokens->content, - tokens->tag & TAG_STICK ? " STICK" : ""); - tokens = tokens->next; - } -} - -void debug_tok_lst_line(t_tok_lst *tokens) -{ - while (tokens != NULL) - { - // FIXME libft for safer correction - printf("|%s| ", tokens->content); - tokens = tokens->next; - } -} - -int debug_lexer(char *input) -{ - int status; - t_tok_lst *out; - - status = lexer(input, &out); - if (status != 0) - return (status); - debug_tok_lst(out); - return (status); -} - -void print_level(int level) -{ - while (level-- > 0) - printf(" "); -} - -void ast_print(int level, t_ast *ast) -{ - if (ast == NULL) - return ; - if (ast->tag == AST_PARENT) - { - print_level(level); - printf("parent: redir [ "); - debug_tok_lst_line(ast->redirs); - printf(" ]\n"); - ast_print(level + 1, ast->parent_ast); - } - else if (ast->tag == AST_PIPELINE) - { - print_level(level); - printf("pipeline: {\n"); - t_ftlst *curr = ast->pipeline; - while (curr != NULL) - { - ast_print(level + 1, (t_ast*)curr->data); - printf("\n"); - curr = curr->next; - } - print_level(level); - printf(" }\n"); - } - else if (ast->tag == AST_CMD) - { - print_level(level); - printf("cmd: [ "); - debug_tok_lst_line(ast->cmd_argv); - printf(" ] redirs: ["); - debug_tok_lst_line(ast->redirs); - printf(" ]"); - } - else if (ast->tag == AST_OP) { - 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"); - } -} - -int debug_parser(char *input) -{ - int status; - t_tok_lst *out; - - status = lexer(input, &out); - if (status != 0) - { - printf("Lexer error\n"); - debug_tok_lst(out); - return (status); - } - t_parsed *ret = parse(out); - if (ret == NULL || ret->syntax_error) - return (1); - ast_print(0, ret->ast); - return (status); -} diff --git a/src/debug/lexer.c b/src/debug/lexer.c new file mode 100644 index 0000000..4d25662 --- /dev/null +++ b/src/debug/lexer.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/10/10 07:51:39 by cacharle #+# #+# */ +/* Updated: 2020/10/10 07:56:44 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" +#include "lexer.h" + +#ifdef MINISHELL_TEST + +int debug_lexer(char *input) +{ + int status; + t_tok_lst *out; + + status = lexer(input, &out); + if (status != 0) + return (status); + while (out != NULL) + { + ft_putnbr(out->tag); + ft_putchar(' '); + ft_putstr(out->content); + ft_putendl(out->tag & TAG_STICK ? " STICK" : ""); + out = out->next; + } + return (status); +} + +#endif diff --git a/src/debug/parser.c b/src/debug/parser.c new file mode 100644 index 0000000..4eda29a --- /dev/null +++ b/src/debug/parser.c @@ -0,0 +1,112 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parser.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/10/10 07:53:11 by cacharle #+# #+# */ +/* Updated: 2020/10/10 08:06:35 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "lexer.h" +#include "minishell.h" +#include "parser.h" + +#ifdef MINISHELL_TEST + +static void st_tok_lst_put(t_tok_lst *tokens) +{ + while (tokens != NULL) + { + ft_putchar('|'); + ft_putstr(tokens->content); + ft_putstr("| "); + tokens = tokens->next; + } +} + +static void st_print_level(int level) +{ + while (level-- > 0) + ft_putstr(" "); +} + +void st_ast_print_parent_pipeline(int level, t_ast *ast) +{ + t_ftlst *curr; + + if (ast->tag == AST_PARENT) + { + st_print_level(level); + ft_putstr("parent: redir [ "); + st_tok_lst_put(ast->redirs); + ft_putstr(" ]\n"); + ast_print(level + 1, ast->parent_ast); + } + else if (ast->tag == AST_PIPELINE) + { + st_print_level(level); + ft_putstr("pipeline: {\n"); + curr = ast->pipeline; + while (curr != NULL) + { + ast_print(level + 1, (t_ast *)curr->data); + ft_putstr("\n"); + curr = curr->next; + } + st_print_level(level); + ft_putstr(" }\n"); + } +} + +void ast_print(int level, t_ast *ast) +{ + if (ast->tag == AST_PARENT || ast->tag == AST_PIPELINE) + st_ast_print_parent_pipeline(level, ast); + else if (ast->tag == AST_CMD) + { + st_print_level(level); + ft_putstr("cmd: [ "); + st_tok_lst_put(ast->cmd_argv); + ft_putstr(" ] redirs: ["); + st_tok_lst_put(ast->redirs); + ft_putstr(" ]"); + } + else if (ast->tag == AST_OP) + { + ft_putstr("{\n"); + st_print_level(level); + ft_putstr(" left:\n"); + ast_print(level + 1, ast->op.left); + ft_putstr("\n"); + st_print_level(level); + ft_putstr(" right:\n"); + ast_print(level + 1, ast->op.right); + ft_putstr("\n"); + st_print_level(level); + ft_putstr("}\n"); + } +} + +int debug_parser(char *input) +{ + int status; + t_tok_lst *out; + t_parsed *ret; + + status = lexer(input, &out); + if (status != 0) + { + ft_putendl("Lexer error\n"); + return (status); + } + ret = parse(out); + if (ret == NULL || ret->syntax_error) + return (1); + ast_print(0, ret->ast); + return (status); +} + +#endif diff --git a/src/setup.c b/src/setup.c index 844b9e4..2830e2d 100644 --- a/src/setup.c +++ b/src/setup.c @@ -6,7 +6,7 @@ /* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/09/16 15:46:09 by charles #+# #+# */ -/* Updated: 2020/10/09 13:38:34 by cacharle ### ########.fr */ +/* Updated: 2020/10/10 08:08:35 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,7 +66,5 @@ bool setup(char *first_arg, t_env env) signal(SIGQUIT, signal_sigquit); signal(SIGTERM, signal_sigterm); setup_progname(first_arg); - ft_bzero(g_state.pids, STATE_PIDS_MAX_SIZE); - g_state.pids_len = 0; return (setup_env(env) || setup_shlvl(env)); } |
