|
|
@ -6,7 +6,7 @@ |
|
|
|
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */ |
|
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
|
/* Created: 2022/05/03 11:48:16 by narnaud #+# #+# */ |
|
|
|
/* Updated: 2022/05/11 01:24:29 by narnaud@stude ### ########.fr */ |
|
|
|
/* Updated: 2022/05/11 15:29:42 by narnaud@stude ### ########.fr */ |
|
|
|
/* */ |
|
|
|
/* ************************************************************************** */ |
|
|
|
|
|
|
@ -52,12 +52,19 @@ int builtin_call(t_datas *datas, t_command *cmd) |
|
|
|
return (-1); |
|
|
|
} |
|
|
|
|
|
|
|
int check_skip(t_datas *datas, t_command *cmd) |
|
|
|
{ |
|
|
|
if (cmd->next && ((cmd->ope == AND && !datas->exit_code) \ |
|
|
|
|| (cmd->ope == OR && datas->exit_code))) |
|
|
|
return (0); |
|
|
|
return (1); |
|
|
|
} |
|
|
|
|
|
|
|
int piper(t_datas *datas, t_command *cmd) |
|
|
|
{ |
|
|
|
int pip[2]; |
|
|
|
pid_t pid; |
|
|
|
int status; |
|
|
|
int exit_code; |
|
|
|
|
|
|
|
if (cmd->ope == PIPE) |
|
|
|
{ |
|
|
@ -79,11 +86,11 @@ int piper(t_datas *datas, t_command *cmd) |
|
|
|
else |
|
|
|
{ |
|
|
|
waitpid(pid, &status, 0); |
|
|
|
exit_code = handle_status(datas, status); |
|
|
|
if (cmd->next && ((cmd->ope == AND && !exit_code) \ |
|
|
|
|| (cmd->ope == OR && exit_code))) |
|
|
|
datas->exit_code = handle_status(datas, status); |
|
|
|
while (cmd->next && check_skip(datas, cmd)) |
|
|
|
cmd = cmd->next; |
|
|
|
if (cmd->next) |
|
|
|
piper(datas, cmd->next); |
|
|
|
datas->exit_code = exit_code; |
|
|
|
} |
|
|
|
return (1); |
|
|
|
} |
|
|
|