42_minishell/cmd.c
Camille Chauvet a183971a7a bozo
2023-02-17 18:23:17 +01:00

55 lines
1.6 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
/* Updated: 2023/02/17 17:30:22 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftx/libftx.h"
#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);
}
int ft_cmd_filler(t_list *element, char **args, t_list **env)
{
t_cmd *content;
char *temp;
size_t i;
if (args == NULL)
return (1);
content = (t_cmd *)element->content;
i = 0;
while (args[i] != NULL)
{
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);
i++;
}
content->args = args;
content->executable = args[0];
return (0);
}