minishell/src/parser/remove_quotes/cmdgroup_remove_quotes.c

73 lines
2.3 KiB
C
Raw Normal View History

2025-03-20 17:34:07 +01:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmdgroup_remove_quotes.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
2025-03-20 17:34:07 +01:00
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/20 17:36:20 by kcolin #+# #+# */
2025-05-02 13:16:26 +02:00
/* Updated: 2025/05/02 12:53:03 by jguelen ### ########.fr */
2025-03-20 17:34:07 +01:00
/* */
/* ************************************************************************** */
#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);
}
2025-03-20 17:34:07 +01:00
2025-03-27 15:57:32 +01:00
t_simple_cmd *simple_cmd_remove_quotes(t_simple_cmd *cmd)
2025-03-20 17:34:07 +01:00
{
t_wordlist *new;
t_worddesc *result;
t_worddesc *current;
if (cmd == NULL)
return (NULL);
new = NULL;
current = wordlist_pop(&cmd->words);
while (current != NULL)
{
result = remove_quotes(current);
worddesc_destroy(current);
if (result == NULL)
return (NULL);
new = wordlist_push(new, result);
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);
2025-03-20 17:34:07 +01:00
return (cmd);
}