diff --git a/inc/invoke_cmd/redirect.h b/inc/invoke_cmd/redirect.h index 5d96fe4..f8d81cd 100644 --- a/inc/invoke_cmd/redirect.h +++ b/inc/invoke_cmd/redirect.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* redirect.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: ttsubo +#+ +:+ +#+ */ +/* By: dayano +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/28 15:20:03 by dayano #+# #+# */ -/* Updated: 2025/05/09 11:32:11 by ttsubo ### ########.fr */ +/* Updated: 2025/05/15 13:18:06 by dayano ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,5 +18,6 @@ bool redirect(t_cmd *cmd); bool redirect_stdout(t_cmd *cmd); bool redirect_stdin(t_cmd *cmd); +void here_doc(char *limiter); #endif diff --git a/src/invoke_cmd/exec_pipeline.c b/src/invoke_cmd/exec_pipeline.c index 30578a5..ae29d9e 100644 --- a/src/invoke_cmd/exec_pipeline.c +++ b/src/invoke_cmd/exec_pipeline.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* exec_pipeline.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: ttsubo +#+ +:+ +#+ */ +/* By: dayano +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/21 13:14:15 by dayano #+# #+# */ -/* Updated: 2025/05/12 10:00:14 by ttsubo ### ########.fr */ +/* Updated: 2025/05/15 13:14:23 by dayano ### ########.fr */ /* */ /* ************************************************************************** */ @@ -63,6 +63,8 @@ static pid_t _fork_command(t_cmd *cmd, t_cmd *cmd_head, t_pipe_io *pipefds, } if (pid > 0) return (_setup_process_signals(SIG_IGN), pid); + if (cmd->next && cmd->next->type == REDIR_HEREDOC) + here_doc(cmd->next->argv[0]); _setup_stdin(cmd, cmd_head, pipefds->prev_fds); _setup_stdout(cmd, pipefds->curr_fds); _setup_process_signals(SIG_DFL); @@ -95,8 +97,13 @@ void exec_pipeline(t_cmd *cmd_head, t_minish *minish) cmd = cmd_head; init_fds(pipefds.prev_fds); init_fds(pipefds.curr_fds); - while (cmd && !is_redirect(cmd)) + while (cmd) { + if (is_redirect(cmd)) + { + cmd = cmd->next; + continue ; + } need_pipe = !is_tail(cmd); create_pipe(need_pipe, pipefds.curr_fds, cmd); cmd->pid = _fork_command(cmd, cmd_head, &pipefds, minish); diff --git a/src/invoke_cmd/pipeline_helper.c b/src/invoke_cmd/pipeline_helper.c index 294a120..071bd04 100644 --- a/src/invoke_cmd/pipeline_helper.c +++ b/src/invoke_cmd/pipeline_helper.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* pipeline_helper.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: ttsubo +#+ +:+ +#+ */ +/* By: dayano +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/24 14:29:29 by dayano #+# #+# */ -/* Updated: 2025/05/01 17:08:00 by ttsubo ### ########.fr */ +/* Updated: 2025/05/15 12:34:37 by dayano ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,9 +28,12 @@ bool is_head(t_cmd *cmd, t_cmd *cmd_head) bool is_tail(t_cmd *cmd) { - if (cmd->next == NULL || is_redirect(cmd->next)) - return (true); - return (false); + t_cmd *next; + + next = cmd->next; + while (next && is_redirect(next)) + next = next->next; + return (next == NULL); } static bool str_in_list(char *cmd, char **list) diff --git a/src/invoke_cmd/redirect.c b/src/invoke_cmd/redirect.c index 2995368..14ef025 100644 --- a/src/invoke_cmd/redirect.c +++ b/src/invoke_cmd/redirect.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* redirect.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: ttsubo +#+ +:+ +#+ */ +/* By: dayano +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/28 15:19:19 by dayano #+# #+# */ -/* Updated: 2025/05/09 14:23:25 by ttsubo ### ########.fr */ +/* Updated: 2025/05/15 13:05:46 by dayano ### ########.fr */ /* */ /* ************************************************************************** */ @@ -118,8 +118,10 @@ bool redirect_stdin(t_cmd *cmd) */ bool redirect(t_cmd *cmd) { - if (cmd->type == REDIR_IN || cmd->type == REDIR_HEREDOC) + if (cmd->type == REDIR_IN) return (redirect_stdin(cmd)); + if (cmd->type == REDIR_HEREDOC) + return (true); if (cmd->type == REDIR_OUT || cmd->type == REDIR_APPEND) return (redirect_stdout(cmd)); return (false);