57 lines
1.8 KiB
C
57 lines
1.8 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* parser_get_commands.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/02/11 14:06:02 by qmennen #+# #+# */
|
|
/* Updated: 2025/02/11 16:25:36 by qmennen ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "minishell.h"
|
|
|
|
static void print_cmds(void *content)
|
|
{
|
|
t_command *cmd;
|
|
int i;
|
|
|
|
cmd = (t_command *)content;
|
|
printf("cmd: %s\n", cmd->command);
|
|
printf("args: ");
|
|
i = 0;
|
|
while (cmd->args[i])
|
|
{
|
|
printf("%s ", cmd->args[i]);
|
|
i++;
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
t_list *parser_get_commands(t_list *list)
|
|
{
|
|
t_list *command_list;
|
|
t_list *current;
|
|
t_command *command;
|
|
t_token *token;
|
|
|
|
command_list = NULL;
|
|
if (!list)
|
|
return (NULL);
|
|
current = list;
|
|
while (current)
|
|
{
|
|
token = (t_token *) current->content;
|
|
command = parser_command_new(ft_strdup(token->value));
|
|
command->args = parser_get_arguments(current);
|
|
ft_lstadd_back(&command_list, ft_lstnew(command));
|
|
while (current && ((t_token *)current->content)->type == T_WORD)
|
|
current = current->next;
|
|
if (current && ((t_token *)current->content)->type != T_WORD)
|
|
current = current->next;
|
|
}
|
|
ft_lstiter(command_list, print_cmds);
|
|
return (command_list);
|
|
}
|