/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* parsing.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */ /* Updated: 2021/11/18 22:35:07 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" // HUGO WIP void handle_path(t_cmd **cmd_arr, char **envp); void find_path(char **argv, char **envp); int handle_builtin(t_cmd *cmd); int fill_builtin(t_cmd *cmd, int (*builtin)(int, char **, t_all *)); // 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 print_cmd_array(t_cmd **cmd_arr) { int i; i = 0; while (cmd_arr[i]) { printf("CMD %i, fd_in=%i, fd_out=%i\n", i, cmd_arr[i]->fd_in, cmd_arr[i]->fd_out); ft_putstr_fd(" |", 1); print_matrix(cmd_arr[i]->argv, "|\n |"); i++; if (cmd_arr[i]) ft_putstr_fd("----------------\n", 1); } } t_cmd **parsing(t_token *token_list) { t_cmd **cmd_arr; 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 cmd_arr = cmd_array_alloc(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, (t_free_f)free_pipeline)); // Struct CMD fill if (!cmd_array_fill_argv(token_list, cmd_arr)) return (ft_retp_free(NULL, &cmd_arr, (t_free_f)free_pipeline)); print_cmd_array(cmd_arr); return (cmd_arr); } /* ------------------------------------------------------- The grammar symbols ------------------------------------------------------- */ /* %token WORD %token LESS // '<' %token GREAT // '>' %token DLESS // '<<' %token DGREAT // '>>' %token PIPE // '|' */ /* ------------------------------------------------------- The Simplified Grammar ------------------------------------------------------- */ /* %start program %% pipeline : command | pipeline '|' command ; command : cmd_prefix cmd_name cmd_suffix | cmd_prefix cmd_name | cmd_name cmd_suffix | cmd_name ; cmd_name : WORD // Apply rule 7a ; cmd_prefix : io_redirect | cmd_prefix io_redirect ; cmd_suffix : io_redirect | cmd_suffix io_redirect | WORD | cmd_suffix WORD ; io_redirect : io_file | io_here ; io_file : '<' filename | '>' filename | DGREAT filename ; filename : WORD // Apply rule 2 ; io_here : DLESS here_end ; here_end : WORD // Apply rule 3 ; */