mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
72 lines
2.3 KiB
C
72 lines
2.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* cmdgroup_remove_quotes.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/03/20 17:36:20 by kcolin #+# #+# */
|
|
/* Updated: 2025/05/02 12:53:03 by jguelen ### ########.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);
|
|
}
|
|
|
|
t_simple_cmd *simple_cmd_remove_quotes(t_simple_cmd *cmd)
|
|
{
|
|
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);
|
|
return (cmd);
|
|
}
|