fix: merging all the code

This commit is contained in:
Matteo Flebus 2026-01-15 18:49:42 +01:00
parent 2e9e98d343
commit 1eecb1bd42
12 changed files with 86 additions and 61 deletions

View file

@ -12,14 +12,14 @@
* @brief converts a linked list of command arguments to an argv array. Don't
* forget to free the result
*
* @param cmd_list Linked list of command arguments
* @param command_list Linked list of command arguments
* @return char** Array of command arguments suitable for execvp. Terminated by
* NULL
*/
static char **list_to_argv(struct list *cmd_list)
static char **list_to_argv(struct list *command_list)
{
size_t len = 0;
struct list *cur = cmd_list;
struct list *cur = command_list;
while (cur)
{
@ -32,7 +32,7 @@ static char **list_to_argv(struct list *cmd_list)
{
return NULL;
}
cur = cmd_list;
cur = command_list;
for (size_t i = 0; i < len; i++)
{
@ -45,19 +45,19 @@ static char **list_to_argv(struct list *cmd_list)
}
/**
* @brief Executes a command represented by an ast_cmd structure
* @brief Executes a command represented by an ast_command structure
*
* @param cmd The command to execute
* @param command The command to execute
* @return int The exit status of the command
*/
static int exec_command(struct ast_cmd *cmd)
static int exec_command(struct ast_command *command)
{
if (!cmd || !(cmd->cmd))
if (!command || !(command->command))
{
return -1;
}
char **argv = list_to_argv(cmd->cmd);
char **argv = list_to_argv(command->command);
if (!argv || !(argv[0]))
{
@ -112,8 +112,8 @@ int execution(struct ast *ast)
return 0;
}
case AST_CMD: {
struct ast_cmd *cmd = ast_get_cmd(ast);
return exec_command(cmd); // It's recursive
struct ast_command *command = ast_get_command(ast);
return exec_command(command); // It's recursive
}
case AST_IF: {
struct ast_if *if_node = ast_get_if(ast);