redirection parsing: use redir_type_from_worddesc

This commit is contained in:
Khaïs COLIN 2025-03-07 14:58:43 +01:00
parent e7946b4192
commit 2a1660865d
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/07 12:30:04 by khais #+# #+# */
/* Updated: 2025/03/07 14:53:22 by khais ### ########.fr */
/* Updated: 2025/03/07 14:58:22 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
#include "redirection.h"
#include "redirection_list.h"
#include <stdlib.h>
#include "libft.h"
#include "redirection_type.h"
/*
** Modify the given simple_cmd in-place, removing all redirection directives
@ -30,12 +30,14 @@ struct s_simple_cmd *parse_redirections(struct s_simple_cmd *cmd)
{
t_worddesc *marker;
t_redirection *redirection;
t_redir_type type;
if (ft_strcmp(">", cmd->words->word->word) == 0)
type = redir_type_from_worddesc(cmd->words->word);
if (type == REDIR_OUTPUT)
{
worddesc_destroy(wordlist_pop(&cmd->words));
marker = wordlist_pop(&cmd->words);
redirection = redirection_create(REDIR_OUTPUT, marker);
redirection = redirection_create(type, marker);
if (redirection == NULL)
return (NULL);
cmd->redirections = redir_list_push(cmd->redirections, redirection);