cmdgroup: tree debug routine

This commit is contained in:
Khaïs COLIN 2025-03-18 12:31:36 +01:00
parent 55d21196b8
commit 8f7e7f7dfe
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
4 changed files with 49 additions and 7 deletions

View file

@ -6,10 +6,11 @@
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */ /* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */
/* Updated: 2025/03/18 12:00:23 by khais ### ########.fr */ /* Updated: 2025/03/18 12:33:21 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "buffer/buffer.h"
#include "get_command.h" #include "get_command.h"
#include "parser/cmdgroup/cmdgroup.h" #include "parser/cmdgroup/cmdgroup.h"
#include "parser/wordlist/wordlist.h" #include "parser/wordlist/wordlist.h"
@ -21,6 +22,7 @@ int main(int argc, char *argv[], char **envp)
char *line; char *line;
t_cmdgroup *cmd; t_cmdgroup *cmd;
t_wordlist *words; t_wordlist *words;
t_buffer *indent;
(void)argc; (void)argc;
(void)argv; (void)argv;
@ -32,7 +34,9 @@ int main(int argc, char *argv[], char **envp)
free(line); free(line);
cmd = cmdgroup_from_wordlist(words); cmd = cmdgroup_from_wordlist(words);
wordlist_destroy(words); wordlist_destroy(words);
cmdgroup_debug(cmd); indent = ft_buffer_new();
cmdgroup_debug(cmd, &indent, true);
ft_buffer_free(indent);
cmdgroup_destroy(cmd); cmdgroup_destroy(cmd);
line = get_command(); line = get_command();
} }

View file

@ -6,13 +6,14 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/11 15:18:02 by khais #+# #+# */ /* Created: 2025/03/11 15:18:02 by khais #+# #+# */
/* Updated: 2025/03/18 12:08:36 by khais ### ########.fr */ /* Updated: 2025/03/18 12:32:12 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "cmdgroup.h" #include "cmdgroup.h"
#include <stdlib.h> #include <stdlib.h>
#include "libft.h" #include "libft.h"
#include "../../treedrawing.h"
t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words) t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words)
{ {
@ -31,7 +32,21 @@ void cmdgroup_destroy(t_cmdgroup *cmd)
free(cmd); free(cmd);
} }
void cmdgroup_debug(t_cmdgroup *cmd) void cmdgroup_debug(t_cmdgroup *cmd, t_buffer **indent, bool is_last)
{ {
ft_printf("%p\n", cmd); 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);
}
ft_printf("%s\n", "t_cmdgroup");
(void)cmd;
/* cmdlist_debug(cmd->item, indent, false); */
/* redirection_list_debug(cmd->redirections, indent, true); */
} }

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/11 15:11:57 by khais #+# #+# */ /* Created: 2025/03/11 15:11:57 by khais #+# #+# */
/* Updated: 2025/03/18 12:07:47 by khais ### ########.fr */ /* Updated: 2025/03/18 12:27:27 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,6 +15,7 @@
# include "../wordlist/wordlist.h" # include "../wordlist/wordlist.h"
# include "../command_list/command_list.h" # include "../command_list/command_list.h"
# include "../../buffer/buffer.h"
/* /*
** A grouping of commands, surrounded by parentheses. ** A grouping of commands, surrounded by parentheses.
@ -35,6 +36,6 @@ typedef struct s_cmdgroup
t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words); t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words);
void cmdgroup_destroy(t_cmdgroup *cmd); void cmdgroup_destroy(t_cmdgroup *cmd);
void cmdgroup_debug(t_cmdgroup *cmd); void cmdgroup_debug(t_cmdgroup *cmd, t_buffer **indent, bool is_last);
#endif // CMDGROUP_H #endif // CMDGROUP_H

22
src/treedrawing.h Normal file
View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* treedrawing.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/18 12:24:25 by khais #+# #+# */
/* Updated: 2025/03/18 12:28:54 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TREEDRAWING_H
# define TREEDRAWING_H
# define CROSS " ├─"
# define CORNER " ╰─"
# define VERTICAL " │ "
# define SPACE " "
# define TREEDRAW_LENGTH 3
#endif // TREEDRAWING_H