diff --git a/src/parser/remove_quotes/cmdgroup_remove_quotes.c b/src/parser/remove_quotes/cmdgroup_remove_quotes.c index e9602fc..a4d72bc 100644 --- a/src/parser/remove_quotes/cmdgroup_remove_quotes.c +++ b/src/parser/remove_quotes/cmdgroup_remove_quotes.c @@ -6,11 +6,43 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } diff --git a/test.sh b/test.sh index 5bdb150..14f5cf1 100755 --- a/test.sh +++ b/test.sh @@ -936,4 +936,38 @@ expecting < "the answer" +echo $? +ls +echo 42 >> "the answer" +echo $? +cat < "the answer" +echo $? +EOF +expecting < $target +echo hello >> $target +cat < $target +ls +EOF +expecting <<"EOF" +the answer +hi +hello +the answer +EOF + finalize