commit pour merge

This commit is contained in:
hugogogo
2021-12-17 12:00:32 +01:00
32 changed files with 621 additions and 565 deletions

View File

@@ -6,12 +6,39 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */
/* Updated: 2021/12/10 10:26:31 by hulamy ### ########.fr */
/* Updated: 2021/12/16 14:50:16 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void save_redirections_words(t_token *t);
t_cmd **parsing(t_token *token_list)
{
t_cmd **pipeline;
if (!valid_syntax(token_list))
return (NULL);
// 2.9.1 - 1) Save Words
save_redirections_words(token_list);
// Struct CMD alloc
pipeline = pipeline_alloc(1 + count_pipes(token_list));
if (!pipeline)
return (NULL);
// 2.9.1 - 2) Expansion
if (!expansions(token_list, pipeline))
return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
// 2.9.1 - 3) Redirection
if (!redirections(token_list, pipeline))
return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
// Struct CMD fill
if (!pipeline_fill_argv(token_list, pipeline))
return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
return (pipeline);
}
void save_redirections_words(t_token *t)
{
while (t)
@@ -26,62 +53,20 @@ void save_redirections_words(t_token *t)
}
}
void print_pipeline(t_cmd **pipeline)
{
int i;
/*
2.9.1 Simple Commands
2.9.1 - 1) Save Words
2.9.1 - 2) Expansion
2.9.1 - 3) Redirection
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
#tag_18_09_01
*/
i = 0;
while (pipeline[i])
{
printf("CMD %i, fd_in=%i, fd_out=%i\n", i, pipeline[i]->fd_in, pipeline[i]->fd_out);
ft_putstr_fd(" |", 1);
print_matrix(pipeline[i]->argv, "|\n |");
i++;
if (pipeline[i])
ft_putstr_fd("----------------\n", 1);
}
}
t_cmd **parsing(t_token *token_list)
{
t_cmd **pipeline;
if (!valid_syntax(token_list))
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);
//
// 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
pipeline = pipeline_alloc(1 + count_pipes(token_list));
if (!pipeline)
return (NULL);
// 2.9.1 - 3) Redirection
if (!redirections(token_list, pipeline))
return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
// Struct CMD fill
if (!pipeline_fill_argv(token_list, pipeline))
return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
//print_pipeline(pipeline);
return (pipeline);
}
/*
2.10 Shell Grammar
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
#tag_18_10
*/
/* -------------------------------------------------------
The grammar symbols