words_expansions() complete
+ TODO : need refactoring and fix to valgrind invalid read size + redirections() WIP + Generic ft_dup_2d_arr(), ft_split_quotes(), ft_strdup_quotes() + shell_loop() continue on error + various small fix
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/08 01:03:29 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/13 05:13:40 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -25,28 +25,72 @@ int next_cmd(t_token *token);
|
||||
int is_redirection(enum e_token_id id);
|
||||
// HUGO WIP
|
||||
|
||||
void save_redirections_words(t_token *t)
|
||||
{
|
||||
while (t)
|
||||
{
|
||||
if (t->id == '>' || t->id == T_DGREAT
|
||||
|| t->id == '<' || t->id == T_DLESS)
|
||||
{
|
||||
t = t->next;
|
||||
t->id = T_REDIRECTION_WORD;
|
||||
}
|
||||
t = t->next;
|
||||
}
|
||||
}
|
||||
|
||||
void ft_free_cmd_arr(t_cmd **cmd_arr)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (cmd_arr[i])
|
||||
{
|
||||
if (cmd_arr[i]->argv)
|
||||
ft_free_2d_arr(cmd_arr[i]->argv);
|
||||
if (cmd_arr[i]->fd_in != STDIN_FILENO && cmd_arr[i]->fd_in > 0)
|
||||
if (close(cmd_arr[i]->fd_in) == -1)
|
||||
perror("close()");
|
||||
if (cmd_arr[i]->fd_out != STDOUT_FILENO && cmd_arr[i]->fd_out > 0)
|
||||
if (close(cmd_arr[i]->fd_out) == -1)
|
||||
perror("close()");
|
||||
i++;
|
||||
}
|
||||
ft_free_2d_arr(cmd_arr);
|
||||
}
|
||||
|
||||
t_cmd **parsing(t_token *token_list)
|
||||
{
|
||||
t_cmd **cmd_arr;
|
||||
|
||||
if (!valid_syntax(token_list))
|
||||
return (NULL);
|
||||
// Struct CMD alloc
|
||||
cmd_arr = alloc_cmd_array(count_pipes(token_list) + 1);
|
||||
if (!cmd_arr)
|
||||
return (NULL);
|
||||
|
||||
// 2.9.1 - 1) Save Words
|
||||
save_redirections_words(token_list);
|
||||
|
||||
// 2.9.1 - 2) Expansion
|
||||
// TEST TOKENS PRINT
|
||||
ft_putstr_fd("TOKENS LIST :\n-----------\n", 1);
|
||||
ft_lstprint((t_list *)token_list, 1);
|
||||
//
|
||||
words_expansions(token_list);
|
||||
// getenv() ne va pas fonctionner avec le changement d'environnement prévu jusqu'ici.
|
||||
// TODO : Revoir le changement d'environnement (avec extern char **environ ?)
|
||||
// OU Integrer un equivalent perso comme dans pipex
|
||||
if (!words_expansions(token_list))
|
||||
return (NULL);
|
||||
//
|
||||
ft_putstr_fd("TOKENS LIST EXPANDED :\n-----------\n", 1);
|
||||
ft_lstprint((t_list *)token_list, 1);
|
||||
|
||||
// Struct CMD alloc
|
||||
cmd_arr = alloc_cmd_array(1 + count_pipes(token_list));
|
||||
if (!cmd_arr)
|
||||
return (NULL);
|
||||
|
||||
// 2.9.1 - 3) Redirection
|
||||
/* if (!redirections(token_list, cmd_arr))
|
||||
return (ft_retp_free(NULL, cmd_arr, ft_free_cmd_arr)); */
|
||||
|
||||
// Struct CMD fill
|
||||
|
||||
|
||||
Reference in New Issue
Block a user