minishell/src/parser/simple_cmd/simple_cmd.c

57 lines
1.8 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/04/15 14:47:13 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "simple_cmd.h"
#include "libft.h"
#include "../../treedrawing.h"
#include "../redirect/redirect_debug.h"
#include "../cmd/cmd_destroy.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);
2025-04-11 16:49:26 +02:00
redirect_destroy(cmd->redirections);
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("line = %d\n", cmd->line);
dedent(leader, false);
wordlist_debug(cmd->words, leader, false);
redirect_debug(cmd->redirections, leader, true);
dedent(leader, is_last);
}