/* By: lnikolov <lnikolov@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/21 08:57:54 by ljiriste #+# #+# */
-/* Updated: 2024/08/27 15:29:43 by ljiriste ### ########.fr */
+/* Updated: 2024/08/27 16:32:09 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
return (res);
}
-int add_redirection_file(t_vec *redirections, t_parse_tree_node *io_file, int fd)
+int expand_filename(char **filename, const t_execution_env *env)
+{
+ t_vec advanced_copy;
+
+ if (ft_vec_init(&advanced_copy, sizeof(char)) != success)
+ return (1);
+ if (add_word(&advanced_copy, *filename, env, 0))
+ {
+ ft_vec_free(&advanced_copy, NULL);
+ return (1);
+ }
+ free(*filename);
+ *filename = advanced_copy.vec;
+ filename[0][advanced_copy.size - 1] = '\0';
+ unquote_field(*filename);
+ return (0);
+}
+
+int add_redirection_file(t_vec *redirections, t_parse_tree_node *io_file, int fd, const t_execution_env *env)
{
t_redirection redir;
const t_parse_tree_node *operator;
filename = get_word(ft_vec_caccess(&io_file->children, 1));
if (!filename)
return (1);
+ expand_filename(&filename, env);
operator = ft_vec_caccess(&io_file->children, 0);
if (is_token_type(operator, "LESS"))
{
subnode = ft_vec_access(&redirect->children, 1);
}
if (is_token_type(subnode, "io_file"))
- return (add_redirection_file(redirections, subnode, fd));
+ return (add_redirection_file(redirections, subnode, fd, env));
else
return (add_redirection_here(redirections, subnode, fd, env));
}