42_minishell/cmd.c

56 lines
1.7 KiB
C
Raw Normal View History

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-21 16:38:00 -05:00
/* Updated: 2023/02/21 22:27:28 by cchauvet ### ########.fr */
2023-02-15 14:52:27 -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);
2023-02-28 07:10:02 -05:00
if (content->fd_in > 2)
close(content->fd_out);
if (content->fd_in > 2)
close(content->fd_out);
2023-02-15 14:52:27 -05:00
free(content);
}
2023-02-24 14:30:01 -05:00
int ft_cmd_filler(t_data *data, t_list *element, char **args)
2023-02-15 14:52:27 -05:00
{
t_cmd *content;
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-24 14:30:01 -05:00
temp = ft_env_filler(data, args[i]);
if (temp == NULL)
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);
}