diff --git a/src/invoke_cmd/invoke_command.c b/src/invoke_cmd/invoke_command.c index d11fbff..c89c643 100644 --- a/src/invoke_cmd/invoke_command.c +++ b/src/invoke_cmd/invoke_command.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* invoke_command.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: ttsubo +#+ +:+ +#+ */ +/* By: dayano +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/20 21:19:33 by dayano #+# #+# */ -/* Updated: 2025/05/09 11:43:50 by ttsubo ### ########.fr */ +/* Updated: 2025/05/09 16:14:34 by dayano ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,13 +26,14 @@ static bool is_unit_builtin(t_cmd *cmd_head) t_cmd *cmd; cmd = cmd_head; - if (is_redirect(cmd)) - cmd = cmd->next; - if ((is_builtin(cmd) && cmd->next == NULL) || (is_builtin(cmd) - && is_redirect(cmd->next))) - return (true); - else + if (cmd == NULL) + return (false); + if (!is_builtin(cmd)) return (false); + cmd = cmd->next; + while (cmd != NULL && is_redirect(cmd)) + cmd = cmd->next; + return (cmd == NULL); } int execute_builtin(t_cmd *cmd, t_minish *minish) @@ -69,18 +70,15 @@ int exec_unit_builtin(t_cmd *cmd, t_minish *minish) redir_result = true; builtin_cmd = cmd; - if (cmd && is_redirect(cmd)) + if (cmd && cmd->next && is_redirect(cmd->next)) { - redir_result = redirect(cmd); + redir_result = redirect(cmd->next); if (redir_result && cmd->next) - { cmd = cmd->next; - builtin_cmd = cmd; - } else return (print_error(cmd->argv[0]), EXIT_FAILURE); } - if (cmd->next && is_redirect(cmd->next)) + if (cmd && cmd->next && is_redirect(cmd->next)) redir_result = redirect(cmd->next); if (!redir_result) return (EXIT_FAILURE);