diff --git a/42sh/.gitignore b/42sh/.gitignore index cfd0396b..202ebc2f 100644 --- a/42sh/.gitignore +++ b/42sh/.gitignore @@ -13,3 +13,8 @@ debug *.swn STDBUG STDEBUG +display_env +read_on_stdin +write_on_stderr +write_on_stdout +write_on_stdout_and_stderr diff --git a/42sh/Makefile b/42sh/Makefile index 8ebd44b6..acf4b7a3 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/10 17:40:02 by gwojda ### ########.fr # +# Updated: 2017/03/12 15:48:20 by ariard ### ########.fr # # # # **************************************************************************** # diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 6627e316..21c50f1b 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/10 19:59:56 by ariard ### ########.fr */ +/* Updated: 2017/03/12 01:01:44 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index c132a271..207cc49c 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -111,6 +111,7 @@ int add_branch(t_btree **ast, t_list **lst); int add_redir_word(t_btree **ast, t_list **lst); int add_redir_type(t_btree **ast, t_list **lst); int add_redir_condition(t_btree **ast, t_list **lst); +int redir_init(t_type type, t_redir *redir); int add_case_cmd(t_btree **ast, t_list **lst); int add_case_sep(t_btree **ast, t_list **lst); int add_pattern(t_btree **ast, t_list **lst); diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 1254a88f..74b54da2 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/11 16:40:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/12 01:01:33 by ariard ### ########.fr */ /* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft b/42sh/libft index 69084091..9382dc10 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit 690840914077a838e13238356db33e35127baa7d +Subproject commit 9382dc10fdb91892ab26604a5776e5301ab88b71 diff --git a/42sh/src/glob/word_is_assignment.c b/42sh/src/glob/word_is_assignment.c index d0908d23..e4dc0de8 100644 --- a/42sh/src/glob/word_is_assignment.c +++ b/42sh/src/glob/word_is_assignment.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 18:59:11 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:20:53 by wescande ### ########.fr */ +/* Updated: 2017/03/11 20:47:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,4 +32,3 @@ int word_is_assignment(char **content) } return (1); } - diff --git a/42sh/src/lexer/lexer_assignement_word.c b/42sh/src/lexer/lexer_assignement_word.c index 2f802e33..9227565b 100644 --- a/42sh/src/lexer/lexer_assignement_word.c +++ b/42sh/src/lexer/lexer_assignement_word.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 20:28:13 by ariard #+# #+# */ -/* Updated: 2017/03/07 18:36:23 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 20:48:34 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,6 +32,6 @@ int lexer_assignement_word(t_list **alst, t_lexer *lexer) return (lexer_lex(alst, lexer)); if ((lexer->state = get_state_redir(lexer))) return (lexer_lex(alst, lexer)); - lexer->state = ft_isdigit(c) ? NUMBER : ASSIGNEMENT_WORD; + lexer->state = ASSIGNEMENT_WORD; return(lexer_lex(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_number.c b/42sh/src/lexer/lexer_number.c index b63ac61a..80401358 100644 --- a/42sh/src/lexer/lexer_number.c +++ b/42sh/src/lexer/lexer_number.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */ -/* Updated: 2017/03/10 13:12:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 20:48:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index b2643688..1ac6cad3 100644 --- a/42sh/src/lexer/lexer_word.c +++ b/42sh/src/lexer/lexer_word.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ -/* Updated: 2017/03/08 23:36:13 by ariard ### ########.fr */ +/* Updated: 2017/03/11 20:46:32 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 2598ac89..1b0dbf1d 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/13 16:02:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 16:12:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index c0cdadaf..dcd53071 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ -/* Updated: 2017/03/11 15:34:23 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:37:18 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,8 +74,13 @@ int add_cmd(t_btree **ast, t_list **lst) i = -1; while (++i < 19) + { if (g_distrostree[i].test(ast, lst) == 1) + { + DG("add to %d", i); return (g_distrostree[i].add(ast, lst)); + } + } if (!*ast) gen_node(ast); else if (no_del_token(ast, lst)) diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index c49ca8cb..c690145f 100644 --- a/42sh/src/parser/add_loop.c +++ b/42sh/src/parser/add_loop.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 22:17:14 by ariard #+# #+# */ -/* Updated: 2017/03/11 15:44:47 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:23:53 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_number.c b/42sh/src/parser/add_number.c index 34b096b3..7552f585 100644 --- a/42sh/src/parser/add_number.c +++ b/42sh/src/parser/add_number.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 17:28:31 by ariard #+# #+# */ -/* Updated: 2017/03/11 16:45:07 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:21:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,13 +38,13 @@ int add_ionumber(t_btree **ast, t_list **lst) t_token *token; t_redir redir; - DG("add io_number"); if (!*ast) gen_node(ast); token = (*lst)->content; node = (*ast)->item; node->cache = node->type; node->type = token->type; + redir_init(token->type, &redir); redir.n = ft_atoi(token->data); ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir))); return (0); diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 071e177d..9254025e 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ -/* Updated: 2017/03/13 16:11:16 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 16:23:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,7 +52,10 @@ int isdir_word(t_btree **ast, t_list **list) node = (*ast)->item; if (token->type == TK_WORD && node->type == REDIR) { - node->type = node->cache; + if (node->cache != TK_NEWLINE) + node->type = node->cache; + else + node->type = CMD; node->cache = 0; return (1); } @@ -65,7 +68,6 @@ int add_redir_word(t_btree **ast, t_list **lst) t_astnode *node; t_token *token; t_redir *redir; - /* t_redir *temp; */ token = (*lst)->content; node = (*ast)->item; @@ -73,32 +75,26 @@ int add_redir_word(t_btree **ast, t_list **lst) { redir = (ft_lstlast(node->data.cmd.redir))->content; redir->word = ft_strdup(token->data); - /* DG("redir1 @ %p word=[%s]", redir, redir->word); */ - /* if (redir->type == TK_DLESS) */ - /* { */ - /* temp = ft_lstlast((data_singleton()->heredoc_queue))->content; */ - /* temp->word = redir->word; */ - /* } */ } return (0); } static int add_redir_type_number(t_btree **ast, t_list **lst) { - t_redir *temp; - t_redir *temp_heredoc; + t_redir *redir; t_astnode *node; t_token *token; + t_list **queue; + t_list *redir_lst; + queue = &data_singleton()->heredoc_queue; token = (*lst)->content; node = (*ast)->item; - temp = (ft_lstlast(node->data.cmd.redir))->content; - temp->type = token->type; + redir_lst = ft_lstlast(node->data.cmd.redir); + redir = redir_lst->content; + redir->type = token->type; if (token->type == TK_DLESS) - { - temp_heredoc = data_singleton()->heredoc_queue->content; - temp_heredoc->n = temp->n; - } + ft_lsteadd(queue, ft_lstnew(&redir_lst->content, sizeof(t_redir*))); return (0); } @@ -130,12 +126,8 @@ int add_redir_type(t_btree **ast, t_list **lst) redir_init(token->type, &redir); redir_lst = ft_lstnew(&redir, sizeof(redir)); ft_lsteadd(&node->data.cmd.redir, redir_lst); - /* DG("redir1 @ %p word=[%s]", redir_lst->content, ((t_redir*)redir_lst->content)->word); */ if (token->type == TK_DLESS) - { ft_lsteadd(queue, ft_lstnew(&redir_lst->content, sizeof(t_redir*))); - /* DG("redir2 @ %p word=[%s]", *(t_redir**)(*queue)->content, (*(t_redir**)(*queue)->content)->word); */ - } } else add_redir_type_number(ast, lst); diff --git a/42sh/src/parser/add_redir_condition.c b/42sh/src/parser/add_redir_condition.c index 1269cda0..2ccf221d 100644 --- a/42sh/src/parser/add_redir_condition.c +++ b/42sh/src/parser/add_redir_condition.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 14:54:18 by ariard #+# #+# */ -/* Updated: 2017/03/11 15:54:52 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:08:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_subshell.c b/42sh/src/parser/add_subshell.c index 1866f3e2..528a81da 100644 --- a/42sh/src/parser/add_subshell.c +++ b/42sh/src/parser/add_subshell.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 18:41:50 by ariard #+# #+# */ -/* Updated: 2017/03/11 15:56:12 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:25:12 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,10 @@ int issubshell(t_btree **ast, t_list **lst) if (*ast) { node = (*ast)->item; + if ((node->type == TK_NEWLINE || node->type == TK_SEMI + || node->type == TK_AMP || node->type == TK_PIPE) + && issubshell(&(*ast)->right, lst) == 1) + return (1); if (node->type == SUBSHELL && node->full == 0) return (1); if (node->type == TK_LBRACE && node->full == 0) diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 596eb9fa..adce88c6 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 15:58:38 by ariard #+# #+# */ -/* Updated: 2017/03/11 16:05:58 by ariard ### ########.fr */ +/* Updated: 2017/03/12 00:50:41 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 747a3e35..155c7d49 100644 --- a/42sh/src/parser/build_tree.c +++ b/42sh/src/parser/build_tree.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ -/* Updated: 2017/03/11 16:08:26 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:37:11 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -78,6 +78,7 @@ int build_tree(t_btree **ast, t_list **lst) { if ((isseparator(token, cache) && g_treematch[i].type == token->type)) { + DG("build %s", read_state(g_treematch[i].type)); cache = token->type; return (g_treematch[i].add(ast, lst)); } diff --git a/42sh/src/parser/heredoc_parser.c b/42sh/src/parser/heredoc_parser.c index 27704b71..774ee758 100644 --- a/42sh/src/parser/heredoc_parser.c +++ b/42sh/src/parser/heredoc_parser.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 16:21:05 by ariard #+# #+# */ -/* Updated: 2017/03/13 16:10:14 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 16:12:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */