feat(postprocess/redir): remove quotes in redirection targets

This commit is contained in:
Khaïs COLIN 2025-04-21 15:12:25 +02:00
parent ac198727e9
commit 8d60113351
2 changed files with 71 additions and 1 deletions

View file

@ -6,11 +6,43 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/20 17:36:20 by khais #+# #+# */
/* Updated: 2025/04/15 11:12:11 by khais ### ########.fr */
/* Updated: 2025/04/22 15:37:15 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "remove_quotes.h"
#include "../redirect/redirect.h"
#include "../cmd/cmd_destroy.h"
#include "../../ft_errno.h"
static t_redirect *redirection_remove_quotes(t_redirect *in_list)
{
t_redirect *out_list;
t_redirect *current;
t_worddesc *result;
out_list = NULL;
while (in_list)
{
current = redirect_pop(&in_list);
if (current->type != FT_HEREDOC)
{
result
= remove_quotes(current->redirectee.filename);
worddesc_destroy(current->redirectee.filename);
current->redirectee.filename = result;
if (current->redirectee.filename == NULL)
{
redirect_destroy(in_list);
redirect_destroy(out_list);
ft_errno(FT_EERRNO);
return (redirect_destroy(current), NULL);
}
}
out_list = t_redirect_add_back(&out_list, current);
}
return (out_list);
}
/*
** do quote removal on all words of this simple cmd
@ -35,5 +67,9 @@ t_simple_cmd *simple_cmd_remove_quotes(t_simple_cmd *cmd)
current = wordlist_pop(&cmd->words);
}
cmd->words = new;
ft_errno(FT_ESUCCESS);
cmd->redirections = redirection_remove_quotes(cmd->redirections);
if (cmd->redirections == NULL && ft_errno_get() != FT_ESUCCESS)
return (NULL);
return (cmd);
}