Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions inc/invoke_cmd/redirect.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* redirect.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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
13 changes: 10 additions & 3 deletions src/invoke_cmd/exec_pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* exec_pipeline.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 8 additions & 5 deletions src/invoke_cmd/pipeline_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* pipeline_helper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/invoke_cmd/redirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* redirect.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ */
/* By: dayano <dayano@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand Down