/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* parser_words.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: sede-san content; arg = arg->next; i++; } argv[i] = NULL; ft_lstclear_nodes(args); return (argv); } /** * @brief Adds all consecutive word tokens to a command's argv and updates its * argc accordingly. * * @param command The command to add the word tokens to. * @param tokens The list of tokens to add to the command. */ void words_add( t_list **tokens, t_command **command ) { t_list *args; t_list *arg; t_token *token; args = NULL; arg = *tokens; token = (t_token *)arg->content; while (arg != NULL && token->type == TOKEN_WORD) { ft_lstadd_back(&args, ft_lstnew(ft_strdup(token->value))); (*command)->argc++; arg = arg->next; if (arg != NULL) token = (t_token *)arg->content; } *tokens = arg; (*command)->argv = args_to_array(&args, (*command)->argc); ft_lstclear_nodes(&args); } void command_clear_argv( t_command *command ) { int i; if (command->argv != NULL) { i = 0; while (i < command->argc) { free(command->argv[i]); i++; } free(command->argv); command->argv = NULL; } } /** * @brief Clears a command, freeing all associated memory. * * @param command The command to clear. */ void command_clear( t_command *command ) { if (command != NULL) { command_clear_argv(command); ft_lstclear(&command->redirections, (void (*)(void *))redirection_clear); ft_lstclear(&command->heredocs, (void (*)(void *))redirection_clear); free(command); } }