mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
refactor(redirections): make handle_redirections generic over cmd types
This commit is contained in:
parent
71eb07b4f5
commit
505a96eeef
3 changed files with 8 additions and 10 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/17 11:14:40 by khais #+# #+# */
|
||||
/* Updated: 2025/04/24 13:46:22 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/28 11:38:17 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -56,14 +56,11 @@ void restore_std_fds(t_minishell *app)
|
|||
close(app->stderr);
|
||||
}
|
||||
|
||||
t_simple_cmd *handle_redirections(t_simple_cmd *cmd, t_minishell *app)
|
||||
t_minishell *handle_redirections(t_redirect *redirections, t_minishell *app)
|
||||
{
|
||||
t_redirect *redirections;
|
||||
|
||||
app->stdin = dup(STDIN_FILENO);
|
||||
app->stdout = dup(STDOUT_FILENO);
|
||||
app->stderr = dup(STDERR_FILENO);
|
||||
redirections = cmd->redirections;
|
||||
while (redirections != NULL)
|
||||
{
|
||||
if (do_redirection(redirections) == NULL)
|
||||
|
|
@ -74,5 +71,5 @@ t_simple_cmd *handle_redirections(t_simple_cmd *cmd, t_minishell *app)
|
|||
}
|
||||
redirections = redirections->next;
|
||||
}
|
||||
return (cmd);
|
||||
return (app);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/17 11:14:29 by khais #+# #+# */
|
||||
/* Updated: 2025/04/17 11:15:56 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/28 11:39:41 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
# include "../../minishell.h"
|
||||
|
||||
void restore_std_fds(t_minishell *app);
|
||||
t_simple_cmd *handle_redirections(t_simple_cmd *cmd, t_minishell *app);
|
||||
t_minishell *handle_redirections(t_redirect *redirections,
|
||||
t_minishell *app);
|
||||
|
||||
#endif // HANDLE_REDIRECTIONS_H
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/27 16:21:56 by khais #+# #+# */
|
||||
/* Updated: 2025/04/25 15:47:14 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/28 11:38:41 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app,
|
|||
return ;
|
||||
}
|
||||
simple_cmd_execute_debug(cmd, app);
|
||||
if (handle_redirections(cmd, app) == NULL)
|
||||
if (handle_redirections(cmd->redirections, app) == NULL)
|
||||
return ;
|
||||
if (execute_builtin(cmd, app) == BUILTIN_INVALID)
|
||||
exec_external_cmd(cmd, app);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue