From 76b569580d2525761b7ba0665e4df2a7436d5795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatmanur=20=C3=87etinta=C5=9F?= <99668549+fatmanur7@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:45:30 +0300 Subject: [PATCH] style: edit the norminette --- src/execute/execute.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/execute/execute.c b/src/execute/execute.c index 7716b99..c9b0f6e 100644 --- a/src/execute/execute.c +++ b/src/execute/execute.c @@ -6,7 +6,7 @@ /* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/17 17:34:07 by facetint #+# #+# */ -/* Updated: 2024/03/28 17:15:40 by facetint ### ########.fr */ +/* Updated: 2024/03/28 17:44:54 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,12 @@ #include "../../includes/env.h" #include "../../memory-allocator/allocator.h" -int should_run_in_child(t_command *cmd) +int should_run_in_child(t_command *cmd) { - return cmd->prev || cmd->next || !isbuiltin(cmd->args[0]); + return (cmd->prev || cmd->next || !isbuiltin(cmd->args[0])); } -void handle_command(int inp_fd, int out_fd, t_command *cmd, int *prev_p, int *next_p) +void handle_command(int inp_fd, int out_fd, t_command *cmd, int *prev_p, int *next_p) { int pid; char *path_cmd; @@ -33,7 +33,7 @@ void handle_command(int inp_fd, int out_fd, t_command *cmd, int *prev_p, int *ne pid = fork(); if (pid < 0) pid_error(pid, prev_p, next_p); - if (pid > 0) + if (pid > 0) { cmd->pid = pid; return ; @@ -58,10 +58,10 @@ int get_input_fd(int *pipe, t_command *cmd) int get_output_fd(int *pipe, t_command *cmd) { if (cmd->output != STDOUT_FILENO) - return cmd->output; + return (cmd->output); if (pipe == NULL) - return STDOUT_FILENO; - return pipe[1]; + return (STDOUT_FILENO); + return (pipe[1]); } void execute(t_command *cmds) @@ -69,25 +69,32 @@ void execute(t_command *cmds) t_command *cur; t_command *latest; int exit_status; - int *prev_p = NULL; - int *next_p = NULL; + int *prev_p; + int *next_p; if (!cmds->next && isbuiltin(cmds->args[0]) && cmds->args[0]) - return (handle_builtin(cmds, (int[]){STDIN_FILENO, STDOUT_FILENO})); + return (handle_builtin (cmds, (int []) + {STDIN_FILENO, STDOUT_FILENO})); *get_exit_status() = 0; + prev_p = NULL; + next_p = NULL; cur = cmds; latest = NULL; while (cur) { - if (prev_p) { + if (prev_p) + { close(prev_p[0]); close(prev_p[1]); } prev_p = next_p; - if (cur->next){ + if (cur->next) + { next_p = safe_malloc(sizeof(int) * 2); pipe(next_p); - } else if (next_p) { + } + else if (next_p) + { next_p = NULL; } handle_command(get_input_fd(prev_p, cur), get_output_fd(next_p, cur), cur, prev_p, next_p); @@ -99,14 +106,13 @@ void execute(t_command *cmds) close(prev_p[0]); close(prev_p[1]); } - if (latest->pid == 0) { *get_exit_status() = 1; - return; + return ; } waitpid(latest->pid, &exit_status, 0); if (!*get_exit_status()) - *get_exit_status() = exit_status >> 8;; - while(wait(NULL) > 0); + *get_exit_status() = exit_status >> 8; + while (wait(NULL) > 0); }