mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
feat(debug): function to easily treeprint a worddesc
This commit is contained in:
parent
9271b7fa92
commit
701174fc1b
4 changed files with 79 additions and 54 deletions
|
|
@ -6,14 +6,13 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/13 17:20:36 by khais #+# #+# */
|
||||
/* Updated: 2025/04/15 12:10:01 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/18 09:20:14 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "worddesc.h"
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
#include "../../treedrawing.h"
|
||||
|
||||
/*
|
||||
** allocate a new worddesc with given flags, marker, and word.
|
||||
|
|
@ -74,53 +73,3 @@ t_worddesc *worddesc_copy(t_worddesc *worddesc)
|
|||
return (free(out), NULL);
|
||||
return (out);
|
||||
}
|
||||
|
||||
static void token_type_debug(t_token_type type, t_buffer *leader, bool is_last)
|
||||
{
|
||||
indent(leader, is_last);
|
||||
if (type == NOT_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "NOT_TOKEN");
|
||||
if (type == WORD_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "WORD_TOKEN");
|
||||
if (type == OPEN_PARENTH_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "OPEN_PARENTH_TOKEN");
|
||||
if (type == CLOSE_PARENTH_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "CLOSE_PARENTH_TOKEN");
|
||||
if (type == PIPE_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "PIPE_TOKEN");
|
||||
if (type == OR_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "OR_TOKEN");
|
||||
if (type == AND_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "AND_TOKEN");
|
||||
if (type == OUT_TRUNC_REDIR_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "OUT_TRUNC_REDIR_TOKEN");
|
||||
if (type == OUT_APPEND_REDIR_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "OUT_APPEND_REDIR_TOKEN");
|
||||
if (type == IN_REDIR_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "IN_REDIR_TOKEN");
|
||||
if (type == HERE_DOC_REDIR_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "HERE_DOC_REDIR_TOKEN");
|
||||
dedent(leader, is_last);
|
||||
}
|
||||
|
||||
void worddesc_debug(t_worddesc *worddesc, t_buffer *leader, bool is_last)
|
||||
{
|
||||
indent(leader, is_last);
|
||||
if (worddesc == NULL)
|
||||
ft_printf("(null worddesc)\n");
|
||||
else
|
||||
{
|
||||
ft_printf("t_worddesc\n");
|
||||
indent(leader, false);
|
||||
ft_printf("word = [%s]\n", worddesc->word);
|
||||
dedent(leader, false);
|
||||
indent(leader, false);
|
||||
ft_printf("marker = [%s]\n", worddesc->marker);
|
||||
dedent(leader, false);
|
||||
indent(leader, false);
|
||||
ft_printf("flags = %d\n", worddesc->flags);
|
||||
dedent(leader, false);
|
||||
token_type_debug(worddesc->token_type, leader, true);
|
||||
}
|
||||
dedent(leader, is_last);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 12:00/08 by khais #+# #+# */
|
||||
/* Updated: 2025/04/15 12:00:08 by khais ### ########.fr */
|
||||
/* Created: 2025/04/15 12:00:08 by khais #+# #+# */
|
||||
/* Updated: 2025/04/17 14:30:48 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -80,5 +80,6 @@ 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);
|
||||
void worddesc_root_debug(t_worddesc *worddesc);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
74
src/parser/worddesc/worddesc_debug.c
Normal file
74
src/parser/worddesc/worddesc_debug.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* worddesc_debug.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/18 09:19:54 by khais #+# #+# */
|
||||
/* Updated: 2025/04/18 09:20:21 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "worddesc.h"
|
||||
#include "../../treedrawing.h"
|
||||
#include "libft.h"
|
||||
|
||||
static void token_type_debug(t_token_type type, t_buffer *leader, bool is_last)
|
||||
{
|
||||
indent(leader, is_last);
|
||||
if (type == NOT_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "NOT_TOKEN");
|
||||
if (type == WORD_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "WORD_TOKEN");
|
||||
if (type == OPEN_PARENTH_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "OPEN_PARENTH_TOKEN");
|
||||
if (type == CLOSE_PARENTH_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "CLOSE_PARENTH_TOKEN");
|
||||
if (type == PIPE_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "PIPE_TOKEN");
|
||||
if (type == OR_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "OR_TOKEN");
|
||||
if (type == AND_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "AND_TOKEN");
|
||||
if (type == OUT_TRUNC_REDIR_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "OUT_TRUNC_REDIR_TOKEN");
|
||||
if (type == OUT_APPEND_REDIR_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "OUT_APPEND_REDIR_TOKEN");
|
||||
if (type == IN_REDIR_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "IN_REDIR_TOKEN");
|
||||
if (type == HERE_DOC_REDIR_TOKEN)
|
||||
ft_printf("t_token_type = %s\n", "HERE_DOC_REDIR_TOKEN");
|
||||
dedent(leader, is_last);
|
||||
}
|
||||
|
||||
void worddesc_debug(t_worddesc *worddesc, t_buffer *leader, bool is_last)
|
||||
{
|
||||
indent(leader, is_last);
|
||||
if (worddesc == NULL)
|
||||
ft_printf("(null worddesc)\n");
|
||||
else
|
||||
{
|
||||
ft_printf("t_worddesc\n");
|
||||
indent(leader, false);
|
||||
ft_printf("word = [%s]\n", worddesc->word);
|
||||
dedent(leader, false);
|
||||
indent(leader, false);
|
||||
ft_printf("marker = [%s]\n", worddesc->marker);
|
||||
dedent(leader, false);
|
||||
indent(leader, false);
|
||||
ft_printf("flags = %d\n", worddesc->flags);
|
||||
dedent(leader, false);
|
||||
token_type_debug(worddesc->token_type, leader, true);
|
||||
}
|
||||
dedent(leader, is_last);
|
||||
}
|
||||
|
||||
void worddesc_root_debug(t_worddesc *worddesc)
|
||||
{
|
||||
t_buffer *leader;
|
||||
|
||||
leader = ft_buffer_new();
|
||||
worddesc_debug(worddesc, leader, true);
|
||||
ft_buffer_free(leader);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue