2023-02-15 14:52:27 -05:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* cmd.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
|
2023-02-17 12:23:17 -05:00
|
|
|
/* Updated: 2023/02/17 17:30:22 by cchauvet ### ########.fr */
|
2023-02-15 14:52:27 -05:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
2023-02-16 12:28:10 -05:00
|
|
|
#include "libftx/libftx.h"
|
2023-02-15 14:52:27 -05:00
|
|
|
#include "minishell.h"
|
|
|
|
|
|
|
|
void ft_cmddel(void *ptr)
|
|
|
|
{
|
|
|
|
t_cmd *content;
|
|
|
|
|
|
|
|
content = (t_cmd *) ptr;
|
|
|
|
if (content->args != NULL)
|
|
|
|
ft_freer_tab_ultimate(1, content->args);
|
|
|
|
if (content->executable != NULL)
|
|
|
|
free(content->executable);
|
|
|
|
free(content);
|
|
|
|
}
|
|
|
|
|
2023-02-16 12:28:10 -05:00
|
|
|
int ft_cmd_filler(t_list *element, char **args, t_list **env)
|
2023-02-15 14:52:27 -05:00
|
|
|
{
|
|
|
|
t_cmd *content;
|
2023-02-16 12:28:10 -05:00
|
|
|
char *temp;
|
2023-02-15 14:52:27 -05:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (args == NULL)
|
|
|
|
return (1);
|
|
|
|
content = (t_cmd *)element->content;
|
|
|
|
i = 0;
|
|
|
|
while (args[i] != NULL)
|
|
|
|
{
|
2023-02-16 12:28:10 -05:00
|
|
|
temp = ft_env_filler(env, args[i]);
|
|
|
|
if (temp == NULL)
|
|
|
|
{
|
|
|
|
ft_eprintf("minishell: malloc failed\n");
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
free(args[i]);
|
|
|
|
args[i] = temp;
|
|
|
|
ft_quote_remover(temp);
|
2023-02-15 14:52:27 -05:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
content->args = args;
|
|
|
|
content->executable = args[0];
|
|
|
|
return (0);
|
|
|
|
}
|