2025-02-21 12:35:51 +01:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
|
|
|
|
/* simple_cmd.c :+: :+: :+: */
|
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
|
/* Created: 2025/02/21 12:30:07 by khais #+# #+# */
|
2025-04-09 15:38:13 +02:00
|
|
|
/* Updated: 2025/04/15 14:47:13 by khais ### ########.fr */
|
2025-02-21 12:35:51 +01:00
|
|
|
/* */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
|
|
#include "simple_cmd.h"
|
|
|
|
|
#include "libft.h"
|
2025-03-19 12:08:53 +01:00
|
|
|
#include "../../treedrawing.h"
|
2025-04-08 16:18:57 +02:00
|
|
|
#include "../redirect/redirect_debug.h"
|
2025-04-08 16:18:57 +02:00
|
|
|
#include "../cmd/cmd_destroy.h"
|
2025-02-21 12:35:51 +01:00
|
|
|
|
|
|
|
|
/*
|
2025-02-21 12:48:35 +01:00
|
|
|
** parse a wordlist and yield a simple command.
|
|
|
|
|
**
|
|
|
|
|
** takes ownership of words
|
2025-02-21 12:35:51 +01:00
|
|
|
*/
|
|
|
|
|
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);
|
2025-02-21 12:35:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2025-02-21 12:35:51 +01:00
|
|
|
free(cmd);
|
|
|
|
|
}
|
2025-03-19 12:08:53 +01:00
|
|
|
|
|
|
|
|
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");
|
2025-04-09 15:38:13 +02:00
|
|
|
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);
|
2025-03-19 12:08:53 +01:00
|
|
|
dedent(leader, is_last);
|
|
|
|
|
}
|