mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-05 23:18:08 +01:00
cmdgroup: tree debug routine
This commit is contained in:
parent
55d21196b8
commit
8f7e7f7dfe
4 changed files with 49 additions and 7 deletions
|
|
@ -6,10 +6,11 @@
|
|||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 "parser/cmdgroup/cmdgroup.h"
|
||||
#include "parser/wordlist/wordlist.h"
|
||||
|
|
@ -21,6 +22,7 @@ int main(int argc, char *argv[], char **envp)
|
|||
char *line;
|
||||
t_cmdgroup *cmd;
|
||||
t_wordlist *words;
|
||||
t_buffer *indent;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
|
@ -32,7 +34,9 @@ int main(int argc, char *argv[], char **envp)
|
|||
free(line);
|
||||
cmd = cmdgroup_from_wordlist(words);
|
||||
wordlist_destroy(words);
|
||||
cmdgroup_debug(cmd);
|
||||
indent = ft_buffer_new();
|
||||
cmdgroup_debug(cmd, &indent, true);
|
||||
ft_buffer_free(indent);
|
||||
cmdgroup_destroy(cmd);
|
||||
line = get_command();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,14 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdlib.h>
|
||||
#include "libft.h"
|
||||
#include "../../treedrawing.h"
|
||||
|
||||
t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words)
|
||||
{
|
||||
|
|
@ -31,7 +32,21 @@ void cmdgroup_destroy(t_cmdgroup *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); */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 "../command_list/command_list.h"
|
||||
# include "../../buffer/buffer.h"
|
||||
|
||||
/*
|
||||
** A grouping of commands, surrounded by parentheses.
|
||||
|
|
@ -35,6 +36,6 @@ typedef struct s_cmdgroup
|
|||
|
||||
t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words);
|
||||
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
|
||||
|
|
|
|||
22
src/treedrawing.h
Normal file
22
src/treedrawing.h
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue