From 55b72823cb2c6c2f407656fdb80bdcb8da744eb5 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Mon, 13 Mar 2017 14:06:54 +0100 Subject: [PATCH 1/3] before pull --- 42sh/.gitignore | 5 +++++ 42sh/Makefile | 2 +- 42sh/fewefwfew | 1 + 42sh/file | 1 + 42sh/includes/minishell.h | 2 +- 42sh/includes/types.h | 2 +- 42sh/new_file_stderr_and_stdout | 2 ++ 42sh/src/glob/word_is_assignment.c | 3 +-- 42sh/src/lexer/lexer_assignement_word.c | 4 ++-- 42sh/src/lexer/lexer_number.c | 2 +- 42sh/src/lexer/lexer_word.c | 2 +- 42sh/src/main/main.c | 4 ++-- 42sh/src/parser/add_cmd.c | 7 ++++++- 42sh/src/parser/add_redir.c | 7 +++++-- 42sh/src/parser/add_redir_condition.c | 2 +- 42sh/src/parser/aggregate_sym.c | 2 +- 42sh/src/parser/heredoc_parser.c | 2 +- 17 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 42sh/fewefwfew create mode 100644 42sh/file create mode 100644 42sh/new_file_stderr_and_stdout 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/fewefwfew b/42sh/fewefwfew new file mode 100644 index 00000000..6a017133 --- /dev/null +++ b/42sh/fewefwfew @@ -0,0 +1 @@ +cat: weffwe: No such file or directory diff --git a/42sh/file b/42sh/file new file mode 100644 index 00000000..dd20028e --- /dev/null +++ b/42sh/file @@ -0,0 +1 @@ +ffewfe2 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/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/new_file_stderr_and_stdout b/42sh/new_file_stderr_and_stdout new file mode 100644 index 00000000..0eab0827 --- /dev/null +++ b/42sh/new_file_stderr_and_stdout @@ -0,0 +1,2 @@ +TOKEN201703111831_1 +TOKEN201703111831_2 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 a5fb2b2e..adbc9de5 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/11 19:56:53 by ariard ### ########.fr */ +/* Updated: 2017/03/11 20:05:07 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,7 +70,7 @@ int handle_instruction(int fd) return (error_syntax(&token, &parser, &ast)); } } - ft_show_heredoc_data(&ast); +// ft_show_heredoc_data(&ast); btree_print(STDBUG, ast, &ft_putast); if (ft_exec(&ast)) return (1); diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index c0cdadaf..929ad950 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/11 20:07:57 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_redir.c b/42sh/src/parser/add_redir.c index 9737eea1..4775300b 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/11 19:57:02 by ariard ### ########.fr */ +/* Updated: 2017/03/11 20:36:19 by ariard ### ########.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); } diff --git a/42sh/src/parser/add_redir_condition.c b/42sh/src/parser/add_redir_condition.c index bf1a1ed4..30569f8d 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/11 20:05:41 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ 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/heredoc_parser.c b/42sh/src/parser/heredoc_parser.c index ee34ac8c..6a483318 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/11 19:40:43 by ariard ### ########.fr */ +/* Updated: 2017/03/11 20:01:42 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ From 77991dbd4cc7a468df11ee1374e64002b7ff91f0 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Mon, 13 Mar 2017 14:07:15 +0100 Subject: [PATCH 2/3] before pull --- 42sh/fewefwfew | 1 - 42sh/file | 1 - 42sh/new_file_stderr_and_stdout | 2 -- 3 files changed, 4 deletions(-) delete mode 100644 42sh/fewefwfew delete mode 100644 42sh/file delete mode 100644 42sh/new_file_stderr_and_stdout diff --git a/42sh/fewefwfew b/42sh/fewefwfew deleted file mode 100644 index 6a017133..00000000 --- a/42sh/fewefwfew +++ /dev/null @@ -1 +0,0 @@ -cat: weffwe: No such file or directory diff --git a/42sh/file b/42sh/file deleted file mode 100644 index dd20028e..00000000 --- a/42sh/file +++ /dev/null @@ -1 +0,0 @@ -ffewfe2 diff --git a/42sh/new_file_stderr_and_stdout b/42sh/new_file_stderr_and_stdout deleted file mode 100644 index 0eab0827..00000000 --- a/42sh/new_file_stderr_and_stdout +++ /dev/null @@ -1,2 +0,0 @@ -TOKEN201703111831_1 -TOKEN201703111831_2 From 484621f786bd128ab93c74dc22e0ff18fddeaa9a Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Mon, 13 Mar 2017 15:01:54 +0100 Subject: [PATCH 3/3] heredoc + subshell correction --- 42sh/src/parser/add_cmd.c | 2 +- 42sh/src/parser/add_loop.c | 2 +- 42sh/src/parser/add_number.c | 5 +++-- 42sh/src/parser/add_redir.c | 27 +++++++++++++-------------- 42sh/src/parser/add_subshell.c | 6 +++++- 42sh/src/parser/build_tree.c | 3 ++- 42sh/src/parser/heredoc_parser.c | 10 ++-------- 7 files changed, 27 insertions(+), 28 deletions(-) diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 929ad950..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 20:07:57 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:37:18 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ 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..190a8f03 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 15:01:22 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,7 +38,6 @@ 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; @@ -46,6 +45,8 @@ int add_ionumber(t_btree **ast, t_list **lst) node->cache = node->type; node->type = token->type; redir.n = ft_atoi(token->data); + redir.word = NULL; + redir.heredoc_data = NULL; 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 4775300b..90eda442 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/11 20:36:19 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:58:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,39 +68,41 @@ int add_redir_word(t_btree **ast, t_list **lst) t_astnode *node; t_token *token; t_redir *redir; - t_redir *temp; + t_redir *other; token = (*lst)->content; node = (*ast)->item; + other = NULL; if (node->data.cmd.redir) { redir = (ft_lstlast(node->data.cmd.redir))->content; redir->word = ft_strdup(token->data); - if (redir->type == TK_DLESS) + if (TK_DLESS) { - temp = ft_lstlast((data_singleton()->heredoc_queue))->content; - temp->word = redir->word; + DG(); + other = ft_lstlast(data_singleton()->heredoc_queue)->content; + DG(); + DG("type is %s", read_state(other->type)); + DG("word is %s", other->word); } - } + } return (0); } static int add_redir_type_number(t_btree **ast, t_list **lst) { t_redir *temp; - t_redir *temp_heredoc; +// t_redir *temp_heredoc; t_astnode *node; t_token *token; + DG(); token = (*lst)->content; node = (*ast)->item; temp = (ft_lstlast(node->data.cmd.redir))->content; temp->type = token->type; if (token->type == TK_DLESS) - { - temp_heredoc = data_singleton()->heredoc_queue->content; - temp_heredoc->n = temp->n; - } + ft_lsteadd(&data_singleton()->heredoc_queue, ft_lstlast(node->data.cmd.redir)); return (0); } @@ -123,12 +125,9 @@ int add_redir_type(t_btree **ast, t_list **lst) redir.heredoc_data = NULL; redir.word = NULL; temp = ft_lstnew(&redir, sizeof(redir)); - DG("adr is %p", temp); ft_lsteadd(&node->data.cmd.redir, temp); - DG("adr is %p", node->data.cmd.redir); if (token->type == TK_DLESS) ft_lsteadd(&data_singleton()->heredoc_queue, temp); - DG("adr is %p", data_singleton()->heredoc_queue); } else add_redir_type_number(ast, lst); 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/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 6a483318..eb4f8b68 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/11 20:01:42 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:58:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,6 @@ int pop_heredoc(t_list **lst) { t_token *token; t_list *temp; - t_list *temp2; t_redir *head; temp = NULL; @@ -28,12 +27,7 @@ int pop_heredoc(t_list **lst) if (head && token) { if (ft_strcmp((char *)token->data, head->word) == 0) - { - temp2 = temp->next; -// free(temp); - data_singleton()->heredoc_queue = temp2; - DG("data is %s et adr %p", head->heredoc_data, temp); - } + data_singleton()->heredoc_queue = temp->next; else { head->heredoc_data = ft_strjoin(head->heredoc_data,