implement tree debug for redirections

This commit is contained in:
Khaïs COLIN 2025-03-19 16:26:45 +01:00
parent 88ed66e138
commit 9fb4e13420
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
5 changed files with 49 additions and 8 deletions

View file

@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/21 14:40:02 by khais #+# #+# */ /* Created: 2025/02/13 17:20:36 by khais #+# #+# */
/* Updated: 2025/03/21 14:40:07 by khais ### ########.fr */ /* Updated: 2025/03/27 13:57:29 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,6 +14,7 @@
#include "libft.h" #include "libft.h"
#include "libft/libft.h" #include "libft/libft.h"
#include <stdlib.h> #include <stdlib.h>
#include "../../treedrawing.h"
/* /*
** allocate a new worddesc with given flags, marker, and word. ** 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 (free(out), NULL);
return (out); 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);
}

View file

@ -3,16 +3,19 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* worddesc.h :+: :+: :+: */ /* worddesc.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/13 15:47:58 by khais #+# #+# */ /* Created: 2025/03/27 13:57:44 by khais #+# #+# */
/* Updated: 2025/03/21 10:09:06 by jguelen ### ########.fr */ /* Updated: 2025/03/27 13:57:49 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef WORDDESC_H #ifndef WORDDESC_H
# define WORDDESC_H # define WORDDESC_H
# include "../../buffer/buffer.h"
# include <stdbool.h>
/* Possible values for the `flags' field of a WORD_DESC. */ /* Possible values for the `flags' field of a WORD_DESC. */
# define W_HASDOLLAR 0b1 /* Dollar sign present. */ # define W_HASDOLLAR 0b1 /* Dollar sign present. */
# define W_QUOTED 0b10 /* Some form of quote character is 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); t_worddesc *worddesc_create(char *word, char flags, char *marker);
void worddesc_destroy(t_worddesc *worddesc); void worddesc_destroy(t_worddesc *worddesc);
t_worddesc *worddesc_copy(t_worddesc *worddesc); t_worddesc *worddesc_copy(t_worddesc *worddesc);
void worddesc_debug(t_worddesc *worddesc, t_buffer *leader,
bool is_last);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/07 14:26:26 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 ; return ;
} }
ft_printf("%s\n", "t_redirection"); 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); dedent(leader, is_last);
} }

View file

@ -6,12 +6,13 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/07 14:56:29 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 "redirection_type.h"
#include "libft.h" #include "libft.h"
#include "../../treedrawing.h"
t_redir_type redir_type_from_worddesc(t_worddesc *word) 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_APPEND);
return (REDIR_INVALID); 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);
}

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/07 14:37:12 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 # define REDIRECTION_TYPE_H
# include "../../parser/worddesc/worddesc.h" # include "../../parser/worddesc/worddesc.h"
# include "../../buffer/buffer.h"
# include <stdbool.h>
/* /*
** Type of redirection. ** Type of redirection.
@ -33,5 +35,7 @@ typedef enum e_redirection_type
} t_redir_type; } t_redir_type;
t_redir_type redir_type_from_worddesc(t_worddesc *word); 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 #endif // REDIRECTION_TYPE_H