do postprocessing for each simple_cmd before execution

This commit is contained in:
Khaïs COLIN 2025-04-08 16:10:34 +02:00
parent 386d2bcb3a
commit ba9751e089
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 24 additions and 2 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/27 16:21:56 by khais #+# #+# */
/* Updated: 2025/04/04 19:56:34 by khais ### ########.fr */
/* Updated: 2025/04/07 17:56:56 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,6 +21,10 @@
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include "../../parser/remove_quotes/remove_quotes.h"
#include "../../postprocess/expansion/expand_vars.h"
#include "../../postprocess/fieldsplit/fieldsplit.h"
#include "../../postprocess/expansion/expand_wildcard.h"
static void command_not_found(t_simple_cmd *cmd)
{
@ -62,6 +66,22 @@ static t_simple_cmd *handle_redirections(t_simple_cmd *cmd, t_minishell *app)
return (cmd);
}
/*
** Do all the post-processing steps relating to a command.
*/
static t_simple_cmd *post_process_command(t_simple_cmd *cmd, t_minishell *app)
{
if (simple_cmd_expand_vars(cmd, app) == NULL)
return (simple_cmd_destroy(cmd), NULL);
if (simple_cmd_fieldsplit(cmd) == NULL)
return (simple_cmd_destroy(cmd), NULL);
if (simple_cmd_expand_wildcards(cmd) == NULL)
return (simple_cmd_destroy(cmd), NULL);
if (simple_cmd_remove_quotes(cmd) == NULL)
return (simple_cmd_destroy(cmd), NULL);
return (cmd);
}
void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
{
char *exe;
@ -69,6 +89,8 @@ void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
if (cmd == NULL || cmd->words == NULL || cmd->words->word == NULL)
return ;
if (post_process_command(cmd, app) == NULL)
return ;
if (handle_redirections(cmd, app) == NULL)
return ;
if (execute_builtin(cmd, app) != BUILTIN_INVALID)

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */
/* Updated: 2025/04/15 11:53:49 by khais ### ########.fr */
/* Updated: 2025/04/15 11:54:46 by khais ### ########.fr */
/* */
/* ************************************************************************** */