minishell/src/parser/simple_cmd/simple_cmd.c

53 lines
1.6 KiB
C
Raw Normal View History

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* simple_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/21 12:30:07 by khais #+# #+# */
/* Updated: 2025/03/28 15:02:17 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "simple_cmd.h"
#include "libft.h"
#include "../../treedrawing.h"
/*
2025-02-21 12:48:35 +01:00
** parse a wordlist and yield a simple command.
**
** takes ownership of words
*/
t_simple_cmd *simple_cmd_from_wordlist(t_wordlist *words)
{
2025-02-21 12:48:35 +01:00
t_simple_cmd *cmd;
cmd = ft_calloc(1, sizeof(t_simple_cmd));
if (cmd == NULL)
return (NULL);
cmd->words = words;
return (cmd);
}
void simple_cmd_destroy(t_simple_cmd *cmd)
{
2025-02-21 12:48:35 +01:00
if (cmd == NULL)
return ;
wordlist_destroy(cmd->words);
free(cmd);
}
void simple_cmd_debug(t_simple_cmd *cmd, t_buffer *leader, bool is_last)
{
if (cmd == NULL)
return ;
indent(leader, is_last);
ft_printf("%s\n", "t_simple_cmd");
indent(leader, false);
ft_printf("words = ");
wordlist_debug(cmd->words);
dedent(leader, true);
dedent(leader, is_last);
}