diff --git a/42sh/Makefile b/42sh/Makefile index d9ff1983..9fdd0857 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -236,6 +236,7 @@ parser/add_sep.c\ parser/add_case.c\ parser/add_func.c\ parser/add_redir.c\ +parser/add_pipe.c\ parser/aggregate_sym.c\ parser/build_tree.c\ parser/error_syntax.c\ diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 690e3ac8..0623fd22 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -124,6 +124,7 @@ int add_subshell_sep(t_btree **ast, t_list **lst); int add_func_cmd(t_btree **ast, t_list **lst); int add_func_sep(t_btree **ast, t_list **lst); int add_one_func(t_btree **ast, t_list **lst); +int add_pipe(t_btree **ast, t_list **lst); int isloop(t_btree **ast, t_list **lst); int iscase(t_btree **ast, t_list **lst); int iscondition(t_btree **ast, t_list **lst); @@ -171,9 +172,9 @@ union u_astdata struct s_astnode { - int pattern; - int nest; - int full; + int pattern; + int nest; + int full; t_type type; t_astdata data; }; diff --git a/42sh/libft b/42sh/libft index 8f6e64fa..bfc8ca20 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit 8f6e64fa9b4ac1dd3e3d5200fb93471ddfeedd40 +Subproject commit bfc8ca207ab4d39f0140322c0f1d368137304a3c diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index 7873b14a..c1bbe62e 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -22,7 +22,8 @@ char **token_to_argv(t_astnode *node) if (node->type == TK_WORD || node->type == TK_ASSIGNEMENT_WORD) { - ld = node->data.cmd.token; + ld = NULL; +// ld = node->data.cmd.token; my_tab = NULL; while (ld) { diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index c65a3b69..d3e0cf1b 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -1,29 +1,6 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -" ============================================================================ -" Netrw Directory Listing (netrw v140) -" /Users/antoineriard/42sh -" Sorted by name -" Sort sequence: [\/]$,\,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$ -" Quick Help: :help -:go up dir D:delete R:rename s:sort-by x:exec -" ============================================================================ -../ -.git/ -includes/ -libft/ -pdf/ -sample/ -src/ -.gitignore -.gitmodules -.tags -.valgrind.supp -Makefile -STDBUG -donovan_segaults_06-02 -update_makefile.sh* -.swp /* add_cmd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: ariard +#+ +:+ +#+ */ @@ -39,6 +16,7 @@ int add_cmd(t_btree **ast, t_list **lst) { t_token *token; t_astnode *node; + t_cmd *cmd; char **my_tab; if ((token = (*lst)->content)->type == TK_IN || token->type == TK_PAREN_OPEN) @@ -76,11 +54,17 @@ int add_cmd(t_btree **ast, t_list **lst) node->type = JOB; if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD) { + DG("add data"); + return ; + if (!node->data.cmds) + node->data.cmds = ft_lstnew(&cmd, sizeof(t_ld)); + ft_lstlast(node->data.cmds)->content; my_tab = ft_sstradd(my_tab, token->data); my_tab = ft_sstradd(my_tab, (char *)token->esc); my_tab = ft_sstradd(my_tab, (char *)token->esc2); - ft_ld_pushback(&node->data.cmd.token, my_tab); + + ft_ld_pushback(&cmd->token, my_tab); } return (0); } diff --git a/42sh/src/parser/add_pipe.c b/42sh/src/parser/add_pipe.c new file mode 100644 index 00000000..7615e5d8 --- /dev/null +++ b/42sh/src/parser/add_pipe.c @@ -0,0 +1,12 @@ +#include "parser.h" + +int add_pipe(t_btree **ast, t_list **lst) +{ + t_astnode *node; + t_cmd *cmd; + + (void)lst; + node = (*ast)->item; + ft_lsteadd(&node->data.cmds, ft_lstnew(&cmd, sizeof(cmd))); + return (0); +} diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 71ca1719..1e5a22dc 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -57,17 +57,19 @@ int add_redir_word(t_btree **ast, t_list **lst) t_astnode *node; t_token *token; t_redir *redir; + t_cmd *cmd; token = (*lst)->content; node = (*ast)->item; - if (node->data.cmd.redir) + cmd = (ft_lstlast(node->data.cmds))->content; + if (cmd->redir) { DG("add file"); - redir = (ft_lstlast(node->data.cmd.redir))->content; + redir = (ft_lstlast(cmd->redir))->content; if (redir->type == TK_DLESS) redir->word.word = NULL; - else if (ft_stris((char *)token->data, &ft_isdigit)) - redir->word.fd = ft_atoi(token->data); +// else if (ft_stris((char *)token->data, &ft_isdigit)) +// redir->word.fd = ft_atoi(token->data); else redir->word.word = token->data; } @@ -79,6 +81,7 @@ int add_redir_type(t_btree **ast, t_list **lst) t_astnode *node; t_token *token; t_redir *redir; + t_cmd *cmd; DG("add redir"); if (!*ast) @@ -88,6 +91,9 @@ int add_redir_type(t_btree **ast, t_list **lst) node->type = REDIR; redir = ft_memalloc(sizeof(redir)); redir->type = token->type; - ft_lsteadd(&node->data.cmd.redir, ft_lstnew(redir, sizeof(redir))); + if (!node->data.cmds) + node->data.cmds = ft_lstnew(&cmd, sizeof(cmd)); + cmd = (node->data.cmds)->content; + ft_lsteadd(&cmd->redir, ft_lstnew(redir, sizeof(redir))); return (0); } diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 733129e4..033c3820 100644 --- a/42sh/src/parser/build_tree.c +++ b/42sh/src/parser/build_tree.c @@ -15,7 +15,7 @@ t_treematch g_treematch[] = { {TK_WORD, &add_cmd}, - {TK_PIPE, &add_sep}, + {TK_PIPE, &add_pipe}, {TK_SEMI, &add_sep}, {TK_GREAT, &add_cmd}, {TK_LESS, &add_cmd}, diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index 7de56874..b17b786c 100644 --- a/42sh/src/parser/tree_wrapper.c +++ b/42sh/src/parser/tree_wrapper.c @@ -27,7 +27,6 @@ int gen_node(t_btree **ast) { *ast = btree_create_node(&item, sizeof(item)); ft_bzero((void *)&((t_astnode *)(*ast)->item)->data, sizeof(t_astdata)); -// ((t_astnode *)(*ast)->item)->data.cmd.token = NULL; ((t_astnode *)(*ast)->item)->nest = 0; ((t_astnode *)(*ast)->item)->full = 0; ((t_astnode *)(*ast)->item)->type = 0;