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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: ttsubo <ttsubo@student.42.fr> +#+ +:+ +#+ #
# By: dayano <dayano@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/04/03 12:55:20 by ttsubo #+# #+# #
# Updated: 2025/05/12 10:00:36 by ttsubo ### ########.fr #
# Updated: 2025/05/15 21:18:25 by dayano ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -63,7 +63,7 @@ ROOT_SRC = main.c minish_signal.c initialize.c error.c
COMMON_SRC = validate_key.c close_fd.c error_mes.c is_quote.c free_functions.c free_functions_2.c
INVOKE_CMD_SRC = create_envp.c exec_pipeline.c execute_cmd.c \
execute_cmd_helper.c invoke_command.c pipeline_helper.c \
redirect.c fds.c wait_pipeline.c pipeline_exit.c
redirect.c fds.c wait_pipeline.c pipeline_exit.c redirect_handler.c
TOKENIZER_SRC = tokenizer.c tokenizer_error.c read_token.c \
is_quote_closed.c get_token_capa.c is_redirect_validate.c
PARSER_SRC = allocate_cmds.c parser.c parser_utils.c setup_cmds.c \
Expand Down
6 changes: 5 additions & 1 deletion inc/invoke_cmd/redirect.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: dayano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/28 15:20:03 by dayano #+# #+# */
/* Updated: 2025/05/15 13:18:06 by dayano ### ########.fr */
/* Updated: 2025/05/15 21:30:20 by dayano ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,9 +15,13 @@

# include "common.h"

// redirect.c
bool redirect(t_cmd *cmd);
bool redirect_stdout(t_cmd *cmd);
bool redirect_stdin(t_cmd *cmd);
void here_doc(char *limiter);

// redirect_handler.c
void handle_all_redirection(t_cmd *cmd, t_minish *minish);

#endif
6 changes: 2 additions & 4 deletions src/invoke_cmd/exec_pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: dayano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/21 13:14:15 by dayano #+# #+# */
/* Updated: 2025/05/15 15:01:57 by dayano ### ########.fr */
/* Updated: 2025/05/15 21:17:55 by dayano ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -68,9 +68,7 @@ static pid_t _fork_command(t_cmd *cmd, t_cmd *cmd_head, t_pipe_io *pipefds,
_setup_stdin(cmd, cmd_head, pipefds->prev_fds);
_setup_stdout(cmd, pipefds->curr_fds);
_setup_process_signals(SIG_DFL);
if ((cmd->next != NULL) && is_redirect(cmd->next))
if (!redirect(cmd->next))
pipeline_exit(EXIT_FAILURE, minish);
handle_all_redirection(cmd, minish);
if (is_builtin(cmd))
pipeline_exit(execute_builtin(cmd, minish), minish);
execute_cmd(cmd, minish);
Expand Down
27 changes: 27 additions & 0 deletions src/invoke_cmd/redirect_handler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirect_handler.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dayano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/15 21:12:09 by dayano #+# #+# */
/* Updated: 2025/05/15 21:31:16 by dayano ### ########.fr */
/* */
/* ************************************************************************** */

#include "main.h"

void handle_all_redirection(t_cmd *cmd, t_minish *minish)
{
t_cmd *redir;

while (cmd->next && is_redirect(cmd->next))
{
redir = cmd->next;
if (!redirect(redir))
pipeline_exit(EXIT_FAILURE, minish);
cmd->next = cmd->next->next;
free_cmd(&redir);
}
}