From 9fb4e13420289dc1fefd8941ace04f871a58ef4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Wed, 19 Mar 2025 16:26:45 +0100 Subject: [PATCH] implement tree debug for redirections --- src/parser/worddesc/worddesc.c | 15 +++++++++++++-- src/parser/worddesc/worddesc.h | 11 ++++++++--- src/postprocess/redirections/redirection.c | 6 +++++- .../redirections/redirection_type.c | 19 ++++++++++++++++++- .../redirections/redirection_type.h | 6 +++++- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/parser/worddesc/worddesc.c b/src/parser/worddesc/worddesc.c index 2cf8f60..97944ed 100644 --- a/src/parser/worddesc/worddesc.c +++ b/src/parser/worddesc/worddesc.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/03/21 14:40:02 by khais #+# #+# */ -/* Updated: 2025/03/21 14:40:07 by khais ### ########.fr */ +/* Created: 2025/02/13 17:20:36 by khais #+# #+# */ +/* Updated: 2025/03/27 13:57:29 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #include "libft.h" #include "libft/libft.h" #include +#include "../../treedrawing.h" /* ** allocate a new worddesc with given flags, marker, and word. @@ -71,3 +72,13 @@ t_worddesc *worddesc_copy(t_worddesc *worddesc) return (free(out), NULL); return (out); } + +void worddesc_debug(t_worddesc *worddesc, t_buffer *leader, bool is_last) +{ + indent(leader, is_last); + if (worddesc == NULL) + ft_printf("%s\n", "(nil)"); + else + ft_printf("[%s]\n", worddesc->word); + dedent(leader, is_last); +} diff --git a/src/parser/worddesc/worddesc.h b/src/parser/worddesc/worddesc.h index 3cc67ad..cbb2e9e 100644 --- a/src/parser/worddesc/worddesc.h +++ b/src/parser/worddesc/worddesc.h @@ -3,16 +3,19 @@ /* ::: :::::::: */ /* worddesc.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/13 15:47:58 by khais #+# #+# */ -/* Updated: 2025/03/21 10:09:06 by jguelen ### ########.fr */ +/* Created: 2025/03/27 13:57:44 by khais #+# #+# */ +/* Updated: 2025/03/27 13:57:49 by khais ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef WORDDESC_H # define WORDDESC_H +# include "../../buffer/buffer.h" +# include + /* Possible values for the `flags' field of a WORD_DESC. */ # define W_HASDOLLAR 0b1 /* Dollar sign present. */ # define W_QUOTED 0b10 /* Some form of quote character is present. */ @@ -58,5 +61,7 @@ typedef struct s_worddesc t_worddesc *worddesc_create(char *word, char flags, char *marker); void worddesc_destroy(t_worddesc *worddesc); t_worddesc *worddesc_copy(t_worddesc *worddesc); +void worddesc_debug(t_worddesc *worddesc, t_buffer *leader, + bool is_last); #endif diff --git a/src/postprocess/redirections/redirection.c b/src/postprocess/redirections/redirection.c index b38dec2..ea65c24 100644 --- a/src/postprocess/redirections/redirection.c +++ b/src/postprocess/redirections/redirection.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/07 14:26:26 by khais #+# #+# */ -/* Updated: 2025/03/19 14:38:10 by khais ### ########.fr */ +/* Updated: 2025/03/19 16:58:50 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,5 +54,9 @@ void redirection_debug(t_redirection *redirection, t_buffer *leader, return ; } ft_printf("%s\n", "t_redirection"); + redir_type_debug(redirection->type, leader, false); + indent(leader, true); + ft_printf("%s = [%s]\n", "marker", redirection->marker->word); + dedent(leader, true); dedent(leader, is_last); } diff --git a/src/postprocess/redirections/redirection_type.c b/src/postprocess/redirections/redirection_type.c index 46ef148..79614e9 100644 --- a/src/postprocess/redirections/redirection_type.c +++ b/src/postprocess/redirections/redirection_type.c @@ -6,12 +6,13 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/07 14:56:29 by khais #+# #+# */ -/* Updated: 2025/03/10 16:51:39 by khais ### ########.fr */ +/* Updated: 2025/03/19 16:59:14 by khais ### ########.fr */ /* */ /* ************************************************************************** */ #include "redirection_type.h" #include "libft.h" +#include "../../treedrawing.h" t_redir_type redir_type_from_worddesc(t_worddesc *word) { @@ -25,3 +26,19 @@ t_redir_type redir_type_from_worddesc(t_worddesc *word) return (REDIR_APPEND); return (REDIR_INVALID); } + +void redir_type_debug(t_redir_type type, t_buffer *leader, + bool is_last) +{ + indent(leader, is_last); + ft_printf("t_redir_type = "); + if (type == REDIR_OUTPUT) + ft_printf("%s\n", "REDIR_OUTPUT"); + if (type == REDIR_INPUT) + ft_printf("%s\n", "REDIR_INPUT"); + if (type == REDIR_HERE_DOC) + ft_printf("%s\n", "REDIR_HERE_DOC"); + if (type == REDIR_APPEND) + ft_printf("%s\n", "REDIR_APPEND"); + dedent(leader, is_last); +} diff --git a/src/postprocess/redirections/redirection_type.h b/src/postprocess/redirections/redirection_type.h index c9b6de4..1a996eb 100644 --- a/src/postprocess/redirections/redirection_type.h +++ b/src/postprocess/redirections/redirection_type.h @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/07 14:37:12 by khais #+# #+# */ -/* Updated: 2025/03/07 14:56:07 by khais ### ########.fr */ +/* Updated: 2025/03/19 16:52:09 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,8 @@ # define REDIRECTION_TYPE_H # include "../../parser/worddesc/worddesc.h" +# include "../../buffer/buffer.h" +# include /* ** Type of redirection. @@ -33,5 +35,7 @@ typedef enum e_redirection_type } t_redir_type; t_redir_type redir_type_from_worddesc(t_worddesc *word); +void redir_type_debug(t_redir_type type, t_buffer *leader, + bool is_last); #endif // REDIRECTION_TYPE_H