Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STYLE] Make IO redirect names more clear #339

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions build/source_files.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/03/19 16:15:33 by ldulling #+# #+# #
# Updated: 2024/04/04 23:25:38 by ldulling ### ########.fr #
# Updated: 2024/06/07 07:25:14 by ldulling ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -76,7 +76,7 @@ SRC += $(addprefix $(DIR), \
io_file.c \
pipe.c \
pipe_utils.c \
stdio_bind.c \
stdio_redirect.c \
)

# Debug:
Expand Down
4 changes: 2 additions & 2 deletions include/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/26 15:05:16 by lyeh #+# #+# */
/* Updated: 2024/04/04 23:42:17 by ldulling ### ########.fr */
/* Updated: 2024/06/07 07:25:53 by ldulling ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -37,7 +37,7 @@ bool restore_std_io(int saved_std_io[2]);
bool save_std_io(int saved_std_io[2]);
bool redirect_scmd_io(t_sh *shell, int *read_fd, int *write_fd);
int redirect_subshell_io(t_sh *shell, t_ct *cmd_table);
int handle_io_redirect(
int open_io_files(
t_sh *shell, int *read_fd, int *write_fd, t_list *io_red_list);

/* Redirection - Pipe */
Expand Down
8 changes: 4 additions & 4 deletions source/backend/executor/builtin_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* builtin_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lyeh <lyeh@student.42vienna.com> +#+ +:+ +#+ */
/* By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/09 01:10:43 by lyeh #+# #+# */
/* Updated: 2024/03/21 17:44:04 by lyeh ### ########.fr */
/* Updated: 2024/06/07 07:23:48 by ldulling ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -26,7 +26,7 @@ void handle_builtin(t_sh *shell, t_list_d **cmd_table_node)
int ret;

cmd_table = (*cmd_table_node)->content;
ret = handle_io_redirect(shell,
ret = open_io_files(shell,
&shell->final_cmd_table->read_fd,
&shell->final_cmd_table->write_fd, cmd_table->io_red_list);
if (ret == MALLOC_ERROR)
Expand Down Expand Up @@ -79,7 +79,7 @@ static void redirect_io_and_exec_builtin(t_sh *shell)
if (!redirect_scmd_io(shell, &shell->final_cmd_table->read_fd,
&shell->final_cmd_table->write_fd))
raise_error_to_own_subprocess(
shell, GENERAL_ERROR, "fd bind failed");
shell, GENERAL_ERROR, "fd redirect failed");
exec_builtin_cmd(shell);
}

Expand Down
4 changes: 2 additions & 2 deletions source/backend/executor/external_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/19 15:17:06 by lyeh #+# #+# */
/* Updated: 2024/06/01 11:51:52 by ldulling ### ########.fr */
/* Updated: 2024/06/07 07:17:29 by ldulling ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -25,7 +25,7 @@ void handle_external_cmd(t_sh *shell, t_ct *cmd_table)
int ret;

final_cmd_table = shell->final_cmd_table;
ret = handle_io_redirect(shell,
ret = open_io_files(shell,
&final_cmd_table->read_fd,
&final_cmd_table->write_fd, cmd_table->io_red_list);
if (ret == MALLOC_ERROR)
Expand Down
28 changes: 13 additions & 15 deletions source/backend/redirection/io_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* io_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lyeh <lyeh@student.42vienna.com> +#+ +:+ +#+ */
/* By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/01 19:32:18 by lyeh #+# #+# */
/* Updated: 2024/03/21 17:46:56 by lyeh ### ########.fr */
/* Updated: 2024/06/07 07:28:14 by ldulling ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -16,12 +16,11 @@
#include "clean.h"

static int expand_filename(t_sh *shell, char **filename);
static bool handle_redirect_by_type(
int *read_fd, int *write_fd, t_io_red *io_red);
static bool handle_red_in(int *read_fd, char *filename);
static bool handle_red_out(int *write_fd, char *filename, int o_flags);
static bool open_io_file_by_type(int *read_fd, int *write_fd, t_io_red *io_red);
static bool open_in_file(int *read_fd, char *filename);
static bool open_out_file(int *write_fd, char *filename, int o_flags);

int handle_io_redirect(
int open_io_files(
t_sh *shell, int *read_fd, int *write_fd, t_list *io_red_list)
{
t_io_red *io_red;
Expand All @@ -38,7 +37,7 @@ int handle_io_redirect(
if (ret != SUCCESS)
return (ret);
}
if (!handle_redirect_by_type(read_fd, write_fd, io_red_list->content))
if (!open_io_file_by_type(read_fd, write_fd, io_red_list->content))
return (GENERAL_ERROR);
io_red_list = io_red_list->next;
}
Expand Down Expand Up @@ -69,21 +68,20 @@ static int expand_filename(t_sh *shell, char **filename)
return (SUCCESS);
}

static bool handle_redirect_by_type(
int *read_fd, int *write_fd, t_io_red *io_red)
static bool open_io_file_by_type(int *read_fd, int *write_fd, t_io_red *io_red)
{
if (io_red->type == T_RED_IN || io_red->type == T_HERE_DOC)
return (handle_red_in(read_fd, io_red->filename));
return (open_in_file(read_fd, io_red->filename));
else if (io_red->type == T_RED_OUT)
return (handle_red_out(write_fd,
return (open_out_file(write_fd,
io_red->filename, O_CREAT | O_RDWR | O_TRUNC));
else if (io_red->type == T_APPEND)
return (handle_red_out(write_fd,
return (open_out_file(write_fd,
io_red->filename, O_CREAT | O_RDWR | O_APPEND));
return (true);
}

static bool handle_red_in(int *read_fd, char *filename)
static bool open_in_file(int *read_fd, char *filename)
{
int fd;

Expand All @@ -97,7 +95,7 @@ static bool handle_red_in(int *read_fd, char *filename)
return (true);
}

static bool handle_red_out(int *write_fd, char *filename, int o_flags)
static bool open_out_file(int *write_fd, char *filename, int o_flags)
{
int fd;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stdio_bind.c :+: :+: :+: */
/* stdio_redirect.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lyeh <lyeh@student.42vienna.com> +#+ +:+ +#+ */
/* By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/19 15:09:45 by lyeh #+# #+# */
/* Updated: 2024/05/03 17:18:22 by lyeh ### ########.fr */
/* Updated: 2024/06/07 07:37:45 by ldulling ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -57,8 +57,7 @@ int redirect_subshell_io(t_sh *shell, t_ct *cmd_table)

read_fd = -1;
write_fd = -1;
ret = handle_io_redirect(
shell, &read_fd, &write_fd, cmd_table->io_red_list);
ret = open_io_files(shell, &read_fd, &write_fd, cmd_table->io_red_list);
if (ret == SUCCESS && \
((read_fd != -1 && dup2(read_fd, STDIN_FILENO) == -1) || \
(write_fd != -1 && dup2(write_fd, STDOUT_FILENO) == -1)))
Expand Down
Loading