/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* cmds.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cchauvet args = NULL; content->executable = NULL; content->fd_in = -1; content->fd_out = -1; current->content = content; if (!((i + 1) < len)) { current->next = NULL; return (0); } current->next = malloc(sizeof(t_list)); if (current->next == NULL) ft_lstclear(cmds, ft_cmddel); current = current->next; i++; } return (0); } static int ft_cmds_prep(t_list **cmds, const char *line, int infile, int outfile) { size_t len; t_cmd *cmd; t_list *current; len = ft_seglen_quoted(line, '|'); if (len == 0) return (0); if (ft_cmds_init(cmds, ft_seglen_quoted(line, '|'))) { free(cmds); return (1); } cmd = (t_cmd *)(*cmds)->content; cmd->fd_in = infile; current = *cmds; while (current->next != NULL) current = current->next; cmd = (t_cmd *) current->content; cmd->fd_out = outfile; return (0); } static int ft_cmds_fill(t_list **cmds, t_list **env, const char *line) { char **tab; char **args; t_list *current; size_t i; tab = ft_split_quoted(line, '|'); if (tab == NULL) return (1); i = 0; current = *cmds; while (tab[i] != NULL) { args = ft_split_quoted(tab[i], ' '); if (ft_cmd_filler(current, args, env) == 1) { ft_lstclear(cmds, ft_cmddel); ft_freer_tab_ultimate(2, args, tab); return (1); } current = current->next; i++; } ft_freer_tab_ultimate(1, tab); return (0); } t_list **ft_parse_cmds(char *line, t_list **env) { int infile; int outfile; t_list **cmds; cmds = malloc(sizeof(t_list *)); if (ft_cmds_prep(cmds, line, infile, outfile) == 1) return (NULL); if (ft_cmds_fill(cmds, env, line) == 1) return (NULL); return (cmds); }