mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
tree debug: create library for easy indent/dedent
This commit is contained in:
parent
47a61699ab
commit
40c5164eef
7 changed files with 84 additions and 35 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/11 15:18:02 by khais #+# #+# */
|
||||
/* Updated: 2025/03/18 12:37:51 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/18 15:32:01 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,8 @@
|
|||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
#include "../../treedrawing.h"
|
||||
#include "../../postprocess/redirections/redirection_list.h"
|
||||
#include "libft/libft.h"
|
||||
|
||||
t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words)
|
||||
{
|
||||
|
|
@ -32,20 +34,11 @@ void cmdgroup_destroy(t_cmdgroup *cmd)
|
|||
free(cmd);
|
||||
}
|
||||
|
||||
void cmdgroup_debug(t_cmdgroup *cmd, t_buffer **indent, bool is_last)
|
||||
void cmdgroup_debug(t_cmdgroup *cmd, t_buffer **leader, bool is_last)
|
||||
{
|
||||
ft_printf("%s", (*indent)->buffer);
|
||||
if (is_last)
|
||||
{
|
||||
ft_printf("%s", CORNER);
|
||||
*indent = ft_buffer_push_buf(*indent, SPACE, TREEDRAW_LENGTH);
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_printf("%s", CROSS);
|
||||
*indent = ft_buffer_push_buf(*indent, VERTICAL, TREEDRAW_LENGTH);
|
||||
}
|
||||
indent(leader, is_last);
|
||||
ft_printf("%s\n", "t_cmdgroup");
|
||||
cmdlist_debug(&cmd->item, indent, false);
|
||||
/* redirection_list_debug(cmd->redirections, indent, true); */
|
||||
cmdlist_debug(&cmd->item, leader, false);
|
||||
redir_list_debug(cmd->redirections, leader, true);
|
||||
dedent(leader, is_last);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/24 17:49:46 by khais #+# #+# */
|
||||
/* Updated: 2025/03/18 15:08:30 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/18 15:31:31 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -118,19 +118,10 @@ void cmdlist_destroy(t_cmdlist *cmd)
|
|||
free(cmd);
|
||||
}
|
||||
|
||||
void cmdlist_debug(t_cmdlist *cmd, t_buffer **indent, bool is_last)
|
||||
void cmdlist_debug(t_cmdlist *cmd, t_buffer **leader, bool is_last)
|
||||
{
|
||||
ft_printf("%s", (*indent)->buffer);
|
||||
if (is_last)
|
||||
{
|
||||
ft_printf("%s", CORNER);
|
||||
*indent = ft_buffer_push_buf(*indent, SPACE, TREEDRAW_LENGTH);
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_printf("%s", CROSS);
|
||||
*indent = ft_buffer_push_buf(*indent, VERTICAL, TREEDRAW_LENGTH);
|
||||
}
|
||||
indent(leader, is_last);
|
||||
ft_printf("%s\n", "t_cmdlist");
|
||||
(void)cmd; // TODO
|
||||
dedent(leader, is_last);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,14 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/07 14:29:53 by khais #+# #+# */
|
||||
/* Updated: 2025/03/07 14:48:20 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/18 15:33:10 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "redirection_list.h"
|
||||
#include "redirection.h"
|
||||
#include "libft.h"
|
||||
#include "../../treedrawing.h"
|
||||
|
||||
/*
|
||||
** create a new redir list item, with the given item
|
||||
|
|
@ -65,3 +66,11 @@ t_redir_list *redir_list_push(t_redir_list *lst, t_redirection *item)
|
|||
return (redir_list_destroy(start), NULL);
|
||||
return (start);
|
||||
}
|
||||
|
||||
void redir_list_debug(t_redir_list *lst, t_buffer **leader, bool is_last)
|
||||
{
|
||||
indent(leader, is_last);
|
||||
ft_printf("%s\n", "t_redir_list");
|
||||
(void)lst;
|
||||
dedent(leader, is_last);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/07 14:29:32 by khais #+# #+# */
|
||||
/* Updated: 2025/03/07 14:48:41 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/18 15:34:17 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,8 @@
|
|||
# define REDIRECTION_LIST_H
|
||||
|
||||
# include "redirection.h"
|
||||
# include "../../buffer/buffer.h"
|
||||
# include <stdbool.h>
|
||||
|
||||
typedef struct s_redirection_list
|
||||
{
|
||||
|
|
@ -22,5 +24,7 @@ typedef struct s_redirection_list
|
|||
} t_redir_list;
|
||||
|
||||
t_redir_list *redir_list_push(t_redir_list *lst, t_redirection *item);
|
||||
void redir_list_debug(t_redir_list *lst,
|
||||
t_buffer **indent, bool is_last);
|
||||
|
||||
#endif // REDIRECTION_LIST_H
|
||||
|
|
|
|||
46
src/treedrawing.c
Normal file
46
src/treedrawing.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* treedrawing.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/18 15:24:50 by khais #+# #+# */
|
||||
/* Updated: 2025/03/18 15:33:39 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "treedrawing.h"
|
||||
#include "libft.h"
|
||||
|
||||
void indent(t_buffer **leader, bool is_last)
|
||||
{
|
||||
ft_printf("%s", (*leader)->buffer);
|
||||
if (is_last)
|
||||
{
|
||||
ft_printf("%s", CORNER);
|
||||
*leader = ft_buffer_push_buf(*leader, SPACE, ft_strlen(SPACE));
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_printf("%s", CROSS);
|
||||
*leader = ft_buffer_push_buf(*leader, VERTICAL, ft_strlen(VERTICAL));
|
||||
}
|
||||
}
|
||||
|
||||
void dedent(t_buffer **leader, bool is_last)
|
||||
{
|
||||
size_t length_to_remove;
|
||||
size_t idx;
|
||||
|
||||
if (is_last)
|
||||
length_to_remove = ft_strlen(SPACE);
|
||||
else
|
||||
length_to_remove = ft_strlen(VERTICAL);
|
||||
idx = (*leader)->length - length_to_remove;
|
||||
if (idx >= 0)
|
||||
{
|
||||
(*leader)->buffer[idx] = '\0';
|
||||
(*leader)->length = idx;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,17 +6,22 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/18 12:24:25 by khais #+# #+# */
|
||||
/* Updated: 2025/03/18 12:28:54 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/18 15:24:40 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TREEDRAWING_H
|
||||
# define TREEDRAWING_H
|
||||
|
||||
# include <stdbool.h>
|
||||
# include "buffer/buffer.h"
|
||||
|
||||
# define CROSS " ├─"
|
||||
# define CORNER " ╰─"
|
||||
# define VERTICAL " │ "
|
||||
# define SPACE " "
|
||||
# define TREEDRAW_LENGTH 3
|
||||
|
||||
void indent(t_buffer **indent, bool is_last);
|
||||
void dedent(t_buffer **indent, bool is_last);
|
||||
|
||||
#endif // TREEDRAWING_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue