From 871b4da00010fc0a45069ad48d453fcdb44d0c13 Mon Sep 17 00:00:00 2001 From: "ariard@student.42.fr" Date: Tue, 28 Feb 2017 19:28:01 +0100 Subject: [PATCH 1/5] test --- 42sh/file | 2 -- 42sh/file1 | 0 42sh/includes/builtin.h | 2 +- 42sh/src/exec/set_exitstatus.c | 2 +- 42sh/src/lexer/lexer_default.c | 2 +- 42sh/src/lexer/lexer_number.c | 2 +- 42sh/src/parser/add_sep.c | 2 +- 42sh/wide | 1 - 42sh/yolo | 2 -- 9 files changed, 5 insertions(+), 10 deletions(-) delete mode 100644 42sh/file delete mode 100644 42sh/file1 delete mode 100644 42sh/wide delete mode 100644 42sh/yolo diff --git a/42sh/file b/42sh/file deleted file mode 100644 index 1d552218..00000000 --- a/42sh/file +++ /dev/null @@ -1,2 +0,0 @@ -ls: feew: No such file or directory -ls: feew: No such file or directory diff --git a/42sh/file1 b/42sh/file1 deleted file mode 100644 index e69de29b..00000000 diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index 61336315..5efa6dff 100644 --- a/42sh/includes/builtin.h +++ b/42sh/includes/builtin.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */ -/* Updated: 2017/02/20 20:21:05 by ariard ### ########.fr */ +/* Updated: 2017/02/27 20:28:37 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_exitstatus.c b/42sh/src/exec/set_exitstatus.c index ffb502da..efbbba45 100644 --- a/42sh/src/exec/set_exitstatus.c +++ b/42sh/src/exec/set_exitstatus.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ -/* Updated: 2017/02/20 20:43:03 by ariard ### ########.fr */ +/* Updated: 2017/02/27 23:20:22 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_default.c b/42sh/src/lexer/lexer_default.c index d8799ebe..d5688999 100644 --- a/42sh/src/lexer/lexer_default.c +++ b/42sh/src/lexer/lexer_default.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */ -/* Updated: 2017/02/25 20:04:41 by ariard ### ########.fr */ +/* Updated: 2017/02/25 20:39:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_number.c b/42sh/src/lexer/lexer_number.c index 11e9eb6e..3bb079b7 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/02/25 19:55:30 by ariard ### ########.fr */ +/* Updated: 2017/02/25 20:39:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index a80093f4..b2954785 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/02/25 19:28:47 by ariard ### ########.fr */ +/* Updated: 2017/02/25 20:39:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/wide b/42sh/wide deleted file mode 100644 index 6efd26c6..00000000 --- a/42sh/wide +++ /dev/null @@ -1 +0,0 @@ -ls: ewfef: No such file or directory diff --git a/42sh/yolo b/42sh/yolo deleted file mode 100644 index 627968d4..00000000 --- a/42sh/yolo +++ /dev/null @@ -1,2 +0,0 @@ -ls: wefewf: No such file or directory -ls: wefewf: No such file or directory From f5fafb4c191d0e31e67db5f5b745d79313a9556a Mon Sep 17 00:00:00 2001 From: "ariard@student.42.fr" Date: Wed, 1 Mar 2017 16:25:53 +0100 Subject: [PATCH 2/5] before pull --- 42sh/Makefile | 3 +- 42sh/includes/parser.h | 36 +++++++-------- 42sh/includes/types.h | 4 +- 42sh/src/lexer/lexer_word.c | 3 +- 42sh/src/lexer/token_print.c | 2 +- 42sh/src/main/ft_putast.c | 4 +- 42sh/src/main/main.c | 2 +- 42sh/src/parser/add_cmd.c | 10 ++-- 42sh/src/parser/add_condition.c | 2 +- 42sh/src/parser/{add_file.c => add_redir.c} | 51 ++++++++++++--------- 42sh/src/parser/add_sep.c | 2 +- 42sh/src/parser/aggregate_sym.c | 7 +-- 42sh/src/parser/produce_sym.c | 2 +- 42sh/src/parser/read_stack.c | 2 +- 42sh/src/parser/tree_wrapper.c | 5 +- 15 files changed, 71 insertions(+), 64 deletions(-) rename 42sh/src/parser/{add_file.c => add_redir.c} (59%) diff --git a/42sh/Makefile b/42sh/Makefile index e42b63b4..1971ae9d 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/02/25 00:13:39 by ariard ### ########.fr # +# Updated: 2017/03/01 15:37:46 by ariard ### ########.fr # # # # **************************************************************************** # @@ -234,6 +234,7 @@ parser/add_loop.c\ parser/add_sep.c\ parser/add_case.c\ parser/add_func.c\ +parser/add_redir.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 80ffcebb..c138fcd0 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -6,6 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */ +/* Updated: 2017/03/01 16:24:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,9 +22,9 @@ enum e_parstate { - ERROR = 0, UNDEFINED, SUCCESS, + ERROR, }; # define TK_REDIR(x) (TK_LESS <= x && x <= TK_GREATAND) @@ -83,7 +84,6 @@ int push_stack(t_sym *stack, t_sym new_sym); int pop_stack(t_sym **stack, t_sym erase_sym); int error_syntax(t_list **token); -int error_EOF(void); int ft_read_stack(t_sym *stack); char *read_state(t_sym current); @@ -107,26 +107,18 @@ int build_tree(t_btree **ast, t_list **lst); int add_sep(t_btree **ast, t_list **lst); int add_cmd(t_btree **ast, t_list **lst); int add_file(t_btree **ast, t_list **lst); -int add_redir(t_btree **ast, t_list **lst); int add_loop_cmd(t_btree **ast, t_list **lst); int add_loop_sep(t_btree **ast, t_list **lst); -int add_loop_condition(t_btree **ast, t_list **lst); int add_condition_cmd(t_btree **ast, t_list **lst); int add_condition_sep(t_btree **ast, t_list **lst); int add_branch(t_btree **ast, t_list **lst); -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); -int add_subshell_cmd(t_btree **ast, t_list **lst); -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 isloop(t_btree **ast, t_list **lst); -int isdir(t_btree **ast, t_list **lst); -int iscase(t_btree **ast, t_list **lst); -int iscondition(t_btree **ast, t_list **lst); -int issubshell(t_btree **ast, t_list **lst); -int isfunc(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 isloop(t_btree **ast); +int isdir(t_btree **ast); +int iscondition(t_btree **ast, t_list **list); +int isdir_sep(t_list **list); +int isdir_word(t_btree **ast, t_list **list); int join_ast(t_btree **ast, t_btree **new_node); int gen_node(t_btree **ast); @@ -150,10 +142,15 @@ struct s_redir int close; }; +struct s_cmd +{ + t_list * redir; + t_ld *token; +} + union u_astdata { - t_redir redir; - t_ld *token; + t_cmd *cmd; t_list *wordlist; char **sstr; char *str; @@ -164,7 +161,6 @@ struct s_astnode int nest; int full; - int pattern; t_type type; t_astdata data; }; diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 474b8b7a..b3a417ca 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/02/25 19:37:31 by ariard ### ########.fr */ +/* Updated: 2017/03/01 16:19:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,7 @@ typedef struct s_token t_token; typedef struct s_ld t_ld; typedef struct s_astnode t_astnode; typedef struct s_redir t_redir; +typedef struct s_cmd t_cmd; typedef union u_astdata t_astdata; typedef union u_word t_word; typedef long long t_type; @@ -156,6 +157,7 @@ enum e_sym PATTERN_CASE, FUNC_NAME, CLOSE_LIST, + REDIR, ALL = 200, }; diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index 157668ba..25f2e6ef 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/02/25 20:10:39 by ariard ### ########.fr */ +/* Updated: 2017/03/01 14:06:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,6 @@ int lexer_word(t_list **alst, t_lexer *lexer) token = (*alst)->content; token->type = TK_WORD; - DG("lexer word"); if ((state = get_state_global(lexer))) { lexer->state = state; diff --git a/42sh/src/lexer/token_print.c b/42sh/src/lexer/token_print.c index 0c2ca145..98c29591 100644 --- a/42sh/src/lexer/token_print.c +++ b/42sh/src/lexer/token_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */ -/* Updated: 2017/02/24 21:48:47 by ariard ### ########.fr */ +/* Updated: 2017/03/01 16:25:30 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index 60d40e35..6b35fe87 100644 --- a/42sh/src/main/ft_putast.c +++ b/42sh/src/main/ft_putast.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */ -/* Updated: 2017/02/25 00:17:44 by ariard ### ########.fr */ +/* Updated: 2017/03/01 15:56:54 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,8 @@ char *ft_putast(void *nodein) t_astnode *node; node = nodein; + if (node->type == REDIR) + return ("REDIR"); if (node->type == CLOSE_LIST) return ("CLOSE_LIST"); if (node->type == FNAME) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 76e2b3a5..b10509f4 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/02/25 20:34:27 by ariard ### ########.fr */ +/* Updated: 2017/03/01 15:55:23 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index d372954d..d4f7542c 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/02/25 18:50:30 by ariard ### ########.fr */ +/* Updated: 2017/03/01 16:25:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,13 +18,12 @@ int add_cmd(t_btree **ast, t_list **lst) t_astnode *node; char **my_tab; - DG("add cmd"); if ((token = (*lst)->content)->type == TK_IN || token->type == TK_PAREN_OPEN) return (0); else if (!*ast) gen_node(ast); else if (isdir(ast, lst)) - return (add_file(ast, lst)); + return (add_redir_word(ast, lst)); else if (isloop(ast, lst) == 3) return (add_loop_condition(ast, lst)); else if (isloop(ast, lst)) @@ -44,16 +43,17 @@ int add_cmd(t_btree **ast, t_list **lst) else if (isfunc(ast, lst)) return (add_func_cmd(ast, lst)); else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN - && node->type != TK_PAREN_CLOSE) + && node->type != TK_PAREN_CLOSE && node->type != TK_WORD) return (add_cmd(&(*ast)->right, lst)); my_tab = NULL; node = (*ast)->item; node->type = token->type; if (token->type == TK_WORD) { + DG("add data"); my_tab = ft_sstradd(my_tab, token->data); my_tab = ft_sstradd(my_tab, (char *)token->esc); - ft_ld_pushback(&node->data.token, my_tab); + ft_ld_pushback(&node->data.cmd.token, my_tab); } return (0); } diff --git a/42sh/src/parser/add_condition.c b/42sh/src/parser/add_condition.c index abadea9c..a3987a98 100644 --- a/42sh/src/parser/add_condition.c +++ b/42sh/src/parser/add_condition.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/19 18:12:52 by ariard #+# #+# */ -/* Updated: 2017/02/25 00:11:09 by ariard ### ########.fr */ +/* Updated: 2017/03/01 15:59:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_file.c b/42sh/src/parser/add_redir.c similarity index 59% rename from 42sh/src/parser/add_file.c rename to 42sh/src/parser/add_redir.c index c056049c..bb750272 100644 --- a/42sh/src/parser/add_file.c +++ b/42sh/src/parser/add_redir.c @@ -6,13 +6,25 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ -/* Updated: 2017/02/25 20:33:12 by ariard ### ########.fr */ +/* Updated: 2017/03/01 16:25:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "parser.h" -int isdir(t_btree **ast, t_list **list) +int isdir_sep(t_list **list) +{ + t_token *token; + + token = (*list)->content; + if (token->type == TK_LESS || token->type == TK_GREAT || + || token->type == TK_GREATAND || token->type == TK_LESSAND + || token->type == TK_DLESS || TK_DGREAT) + return (1); + return (0); +} + +int isdir_word(t_btree **ast, t_list **list) { t_astnode *node; t_token *token; @@ -20,25 +32,14 @@ int isdir(t_btree **ast, t_list **list) token = (*list)->content; if (*ast) { - DG("isdir"); node = (*ast)->item; - if ((node->type == TK_LESS || node->type == TK_GREAT - || node->type == TK_LESSAND || node->type == TK_GREATAND - || node->type == TK_DGREAT) - && token->type == TK_WORD) - return (1); - if ((node->type == TK_LESS || node->type == TK_GREAT - || node->type == TK_LESSAND || node->type == TK_GREATAND - || node->type == TK_DGREAT) - && (token->type == TK_LESS || token->type == TK_GREAT - || token->type == TK_LESSAND || token->type == TK_GREATAND - || token->type == TK_DGREAT)) - return (2); + if (token->type == TK_WORD && node->type == REDIR) + return (1); } return (0); } -int add_file(t_btree **ast, t_list **lst) +int add_redir_word(t_btree **ast, t_list **lst) { t_astnode *node; t_token *token; @@ -46,16 +47,21 @@ int add_file(t_btree **ast, t_list **lst) token = (*lst)->content; node = (*ast)->item; - if (node->data.wordlist) + if (node->data.cmd.redir) { DG("add file"); - redir = (ft_lstlast(node->data.wordlist))->content; - redir->word.word = token->data; - } + redir = (ft_lstlast(node->data.cmd.redir))->content; + if (redir->type == TK_DLESS) + redir->word.word = NULL; + else if (ft_stris((char *)token->data, &isdigit)) + redir->word.fd = ft_atoi(token->data); + else + redir->word.word = token->data; + } return (0); } -int add_redir(t_btree **ast, t_list **lst) +int add_redir_type(t_btree **ast, t_list **lst) { t_astnode *node; t_token *token; @@ -66,8 +72,9 @@ int add_redir(t_btree **ast, t_list **lst) gen_node(ast); token = (*lst)->content; node = (*ast)->item; + node->type = REDIR; redir = ft_memalloc(sizeof(redir)); redir->type = token->type; - ft_lsteadd(&node->data.wordlist, ft_lstnew(redir, sizeof(redir))); + ft_lsteadd(&node->data.cmd.redir, ft_lstnew(redir, sizeof(redir))); return (0); } diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index b2954785..54b8e3fa 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/02/25 20:39:38 by ariard ### ########.fr */ +/* Updated: 2017/03/01 16:25:35 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 879045ca..3da1846f 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:39:18 by ariard #+# #+# */ -/* Updated: 2017/02/25 13:53:57 by ariard ### ########.fr */ +/* Updated: 2017/03/01 14:45:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -92,8 +92,6 @@ t_aggrematch g_aggrematch[] = {NEWLINE_LIST, FOR_WORDLIST, SEQUENTIAL_SEP, 0}, //to check - {IO_HERE, TK_IO_NUMBER, IO_REDIRECT, TK_IO_NUMBER}, - {IO_HERE, ALL, IO_REDIRECT, 0}, {FILENAME, TK_LESS, IO_FILE, TK_LESS}, {FILENAME, TK_LESSAND, IO_FILE, TK_LESSAND}, {FILENAME, TK_GREAT, IO_FILE, TK_GREAT}, @@ -102,9 +100,12 @@ t_aggrematch g_aggrematch[] = {FILENAME, TK_LESSGREAT, IO_FILE, TK_LESSGREAT}, {FILENAME, TK_CLOBBER, IO_FILE, TK_CLOBBER}, + {HERE_END, TK_DLESS, IO_HERE, TK_DLESS}, //to check {IO_FILE, TK_IO_NUMBER, IO_REDIRECT, TK_IO_NUMBER}, {IO_FILE, ALL, IO_REDIRECT, 0}, + {IO_HERE, TK_IO_NUMBER, IO_REDIRECT, TK_IO_NUMBER}, + {IO_HERE, ALL, IO_REDIRECT, 0}, {IO_REDIRECT, CMD_SUPERIOR, CMD_SUPERIOR, CMD_SUPERIOR}, {IO_REDIRECT, COMPOUND_COMMAND, REDIRECT_LIST, REDIRECT_LIST}, diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index 4a2cbad4..26a0448b 100644 --- a/42sh/src/parser/produce_sym.c +++ b/42sh/src/parser/produce_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:58:34 by ariard #+# #+# */ -/* Updated: 2017/02/25 13:54:08 by ariard ### ########.fr */ +/* Updated: 2017/03/01 14:40:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index ebb6e4d8..a92a8b9d 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/02/25 00:15:00 by ariard ### ########.fr */ +/* Updated: 2017/03/01 16:25:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index ac2d3d5b..0928d24a 100644 --- a/42sh/src/parser/tree_wrapper.c +++ b/42sh/src/parser/tree_wrapper.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:57:44 by ariard #+# #+# */ -/* Updated: 2017/02/25 19:10:34 by ariard ### ########.fr */ +/* Updated: 2017/03/01 15:59:32 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,8 +26,7 @@ int gen_node(t_btree **ast) if (!*ast) { *ast = btree_create_node(&item, sizeof(item)); - ((t_astnode *)(*ast)->item)->data.token = NULL; - ((t_astnode *)(*ast)->item)->data.redir.word.word = NULL; + ((t_astnode *)(*ast)->item)->data.cmd = NULL; ((t_astnode *)(*ast)->item)->nest = 0; ((t_astnode *)(*ast)->item)->full = 0; ((t_astnode *)(*ast)->item)->type = 0; From aa9097575da99f3dae5f568715a120c9c02cabb6 Mon Sep 17 00:00:00 2001 From: "ariard@student.42.fr" Date: Wed, 1 Mar 2017 18:04:29 +0100 Subject: [PATCH 3/5] rewef --- 42sh/F | 0 42sh/Makefile | 3 +-- 42sh/includes/parser.h | 22 +++++++++++----------- 42sh/includes/types.h | 2 +- 42sh/src/exec/ast_free.c | 11 ++++++++--- 42sh/src/exec/exec_case.c | 2 +- 42sh/src/exec/exec_command.c | 4 ++-- 42sh/src/exec/exec_less.c | 5 +++-- 42sh/src/exec/exec_redir.c | 6 +++--- 42sh/src/line-editing/readline.c | 2 +- 42sh/src/main/main.c | 4 ++-- 42sh/src/parser/add_cmd.c | 9 ++++++--- 42sh/src/parser/add_redir.c | 22 ++++++++++++++-------- 42sh/src/parser/add_sep.c | 4 +--- 42sh/src/parser/aggregate_sym.c | 2 +- 42sh/src/parser/build_tree.c | 10 +++++----- 42sh/src/parser/error_syntax.c | 2 +- 42sh/src/parser/ft_parse.c | 1 + 42sh/src/parser/parser_init.c | 2 +- 42sh/src/parser/read_stack.c | 4 +++- 42sh/src/parser/tree_wrapper.c | 9 ++++----- 21 files changed, 70 insertions(+), 56 deletions(-) create mode 100644 42sh/F diff --git a/42sh/F b/42sh/F new file mode 100644 index 00000000..e69de29b diff --git a/42sh/Makefile b/42sh/Makefile index 771e4176..d9ff1983 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/01 15:37:46 by ariard ### ########.fr # +# Updated: 2017/03/01 16:42:16 by ariard ### ########.fr # # # # **************************************************************************** # @@ -231,7 +231,6 @@ main/shell_init.c\ parser/add_cmd.c\ parser/add_subshell.c\ parser/add_condition.c\ -parser/add_file.c\ parser/add_loop.c\ parser/add_sep.c\ parser/add_case.c\ diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index a64a7cbb..93e4eb83 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */ -/* Updated: 2017/03/01 16:28:29 by ariard ### ########.fr */ +/* Updated: 2017/03/01 18:02:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,9 +22,9 @@ enum e_parstate { + ERROR = 0, UNDEFINED, SUCCESS, - ERROR, }; # define TK_REDIR(x) (TK_LESS <= x && x <= TK_GREATAND) @@ -84,9 +84,10 @@ int push_stack(t_sym *stack, t_sym new_sym); int pop_stack(t_sym **stack, t_sym erase_sym); int error_syntax(t_list **token); +int error_EOF(void); int ft_read_stack(t_sym *stack); -char *read_state(t_sym current); +char *read_state(t_sym current); /* @@ -109,11 +110,12 @@ int add_cmd(t_btree **ast, t_list **lst); int add_file(t_btree **ast, t_list **lst); int add_loop_cmd(t_btree **ast, t_list **lst); int add_loop_sep(t_btree **ast, t_list **lst); +int add_loop_condition(t_btree **ast, t_list **lst); int add_condition_cmd(t_btree **ast, t_list **lst); int add_condition_sep(t_btree **ast, t_list **lst); 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_word(t_btree **ast, t_list **lst); +int add_redir_type(t_btree **ast, t_list **lst); 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); @@ -123,17 +125,15 @@ 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 isloop(t_btree **ast, t_list **lst); -int isdir(t_btree **ast, t_list **lst); int iscase(t_btree **ast, t_list **lst); int iscondition(t_btree **ast, t_list **lst); int issubshell(t_btree **ast, t_list **lst); int isfunc(t_btree **ast, t_list **lst); int join_ast(t_btree **ast, t_btree **new_node); int gen_node(t_btree **ast); -int isloop(t_btree **ast); int isdir(t_btree **ast); int iscondition(t_btree **ast, t_list **list); -int isdir_sep(t_list **list); +int isdir_sep(t_btree **ast, t_list **list); int isdir_word(t_btree **ast, t_list **list); /* @@ -157,13 +157,13 @@ struct s_redir struct s_cmd { - t_list * redir; + t_list *redir; t_ld *token; -} +}; union u_astdata { - t_cmd *cmd; + t_cmd cmd; t_list *wordlist; char **sstr; char *str; diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 04a80dc8..b5d64f79 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/01 16:19:09 by ariard ### ########.fr */ +/* Updated: 2017/03/01 16:55:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ast_free.c b/42sh/src/exec/ast_free.c index 7f7d9591..66abd247 100644 --- a/42sh/src/exec/ast_free.c +++ b/42sh/src/exec/ast_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */ -/* Updated: 2017/02/03 14:41:26 by ariard ### ########.fr */ +/* Updated: 2017/03/01 16:36:20 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,10 +16,14 @@ void ast_free(void *data, size_t content_size) { t_astnode *node; + (void)node; + (void)data; + (void)content_size; +/* (void)content_size; node = data; if (node->type == TK_COMMAND) - ft_ld_clear(&node->data.token, &ft_tabdel); + ft_ld_clear(&node->data.cmd.token, &ft_tabdel); else if (node->type == TK_SUBSHELL) { ft_sstrfree(node->data.sstr); @@ -27,6 +31,7 @@ void ast_free(void *data, size_t content_size) } else if (node->type == TK_LESS || node->type == TK_GREAT || node->type == TK_DGREAT) { - ft_strdel(&node->data.redir.word.word); + ft_strdel(&node->data.cmd.redir.word.word); } +*/ } diff --git a/42sh/src/exec/exec_case.c b/42sh/src/exec/exec_case.c index 3a2847f8..dd671440 100644 --- a/42sh/src/exec/exec_case.c +++ b/42sh/src/exec/exec_case.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */ -/* Updated: 2017/02/20 22:31:46 by jhalford ### ########.fr */ +/* Updated: 2017/03/01 16:29:20 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index 358e5887..7873b14a 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ -/* Updated: 2017/02/20 22:43:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/01 16:32:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ char **token_to_argv(t_astnode *node) if (node->type == TK_WORD || node->type == TK_ASSIGNEMENT_WORD) { - ld = node->data.token; + ld = node->data.cmd.token; my_tab = NULL; while (ld) { diff --git a/42sh/src/exec/exec_less.c b/42sh/src/exec/exec_less.c index 50797abd..1bbdb78c 100644 --- a/42sh/src/exec/exec_less.c +++ b/42sh/src/exec/exec_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:27:08 by jhalford #+# #+# */ -/* Updated: 2017/02/20 20:32:26 by ariard ### ########.fr */ +/* Updated: 2017/03/01 16:37:28 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,8 +17,9 @@ int exec_less(t_btree **ast) t_astnode *node; int fd; + fd = 0; node = (*ast)->item; - fd = open(node->data.redir.word.word, O_RDONLY); +// fd = open(node->data.redir.word.word, O_RDONLY); data_singleton()->exec.process.fdin = fd; /* ft_strappend(&data->exec.process.command, "<"); */ /* ft_strappend(&data->exec.process.command, node->data.redir.word.word); */ diff --git a/42sh/src/exec/exec_redir.c b/42sh/src/exec/exec_redir.c index c5816600..52b8c96d 100644 --- a/42sh/src/exec/exec_redir.c +++ b/42sh/src/exec/exec_redir.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:27:51 by jhalford #+# #+# */ -/* Updated: 2017/02/21 20:14:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/01 16:38:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,8 @@ int exec_redir(t_btree **ast) p = &data_singleton()->exec.process; node = (*ast)->item; - node->data.redir.type = node->type; - ft_lsteadd(&p->redirs, ft_lstnew(&node->data.redir,sizeof(node->data.redir))); +// node->data.redir.type = node->type; +// ft_lsteadd(&p->redirs, ft_lstnew(&node->data.redir,sizeof(node->data.redir))); ft_exec(&(*ast)->left); // btree_delone(ast, &ast_free); return (0); diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 383a4001..bbdd75f2 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/02/21 20:04:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/01 17:19:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index b10509f4..a9cbbd1a 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/01 15:55:23 by ariard ### ########.fr */ +/* Updated: 2017/03/01 17:50:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ int handle_instruction(int fd) DG("START: state=%i", parser.state); while (1) { - if ((ret = readline(fd, get_lexer_stack(lexer), &str))) + if ((ret = readline(fd, get_lexer_stack(lexer) || parser.state == UNDEFINED, &str))) { if (ret == -1) return (-1); diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 5eaa97a0..5ba1159d 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/01 16:25:27 by ariard ### ########.fr */ +/* Updated: 2017/03/01 18:02:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,8 +22,10 @@ int add_cmd(t_btree **ast, t_list **lst) return (0); else if (!*ast) gen_node(ast); - else if (isdir(ast, lst)) + else if (isdir_word(ast, lst)) return (add_redir_word(ast, lst)); + else if (isdir_sep(ast, lst)) + return (add_redir_type(ast, lst)); else if (isloop(ast, lst) == 3) return (add_loop_condition(ast, lst)); else if (isloop(ast, lst)) @@ -43,7 +45,8 @@ int add_cmd(t_btree **ast, t_list **lst) else if (isfunc(ast, lst)) return (add_func_cmd(ast, lst)); else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN - && node->type != TK_PAREN_CLOSE && node->type != TK_WORD) + && node->type != TK_PAREN_CLOSE && node->type != TK_WORD + && node->type != REDIR) return (add_cmd(&(*ast)->right, lst)); my_tab = NULL; node = (*ast)->item; diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index bb750272..41c1eec6 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -6,21 +6,27 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ -/* Updated: 2017/03/01 16:25:15 by ariard ### ########.fr */ +/* Updated: 2017/03/01 17:59:17 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "parser.h" -int isdir_sep(t_list **list) +int isdir_sep(t_btree **ast, t_list **list) { + t_astnode *node; t_token *token; token = (*list)->content; - if (token->type == TK_LESS || token->type == TK_GREAT || - || token->type == TK_GREATAND || token->type == TK_LESSAND - || token->type == TK_DLESS || TK_DGREAT) - return (1); + if (*ast) + { + node = (*ast)->item; + if ((node->type == TK_WORD || node->type == REDIR) + && (token->type == TK_LESS || token->type == TK_GREAT + || token->type == TK_GREATAND || token->type == TK_LESSAND + || token->type == TK_DLESS || token->type == TK_DGREAT)) + return (1); + } return (0); } @@ -53,7 +59,7 @@ int add_redir_word(t_btree **ast, t_list **lst) redir = (ft_lstlast(node->data.cmd.redir))->content; if (redir->type == TK_DLESS) redir->word.word = NULL; - else if (ft_stris((char *)token->data, &isdigit)) + else if (ft_stris((char *)token->data, &ft_isdigit)) redir->word.fd = ft_atoi(token->data); else redir->word.word = token->data; @@ -68,7 +74,7 @@ int add_redir_type(t_btree **ast, t_list **lst) t_redir *redir; DG("add redir"); - if (!ast) + if (!*ast) gen_node(ast); token = (*lst)->content; node = (*ast)->item; diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index 54b8e3fa..076f16f8 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/03/01 16:25:35 by ariard ### ########.fr */ +/* Updated: 2017/03/01 18:02:14 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,8 +27,6 @@ int add_sep(t_btree **ast, t_list **lst) return (add_case_sep(ast, lst)); else if (issubshell(ast, lst)) return (add_subshell_sep(ast, lst)); - else if (isdir(ast, lst) == 2) - return (add_redir(ast, lst)); else if (isfunc(ast, lst)) return (add_func_sep(ast, lst)); if (!*ast) diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 3cba259f..0ddc11af 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:39:18 by ariard #+# #+# */ -/* Updated: 2017/03/01 16:27:17 by ariard ### ########.fr */ +/* Updated: 2017/03/01 17:00:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 2d8a7e70..5b584160 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/02/25 19:21:05 by ariard ### ########.fr */ +/* Updated: 2017/03/01 18:01:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,10 +17,10 @@ t_treematch g_treematch[] = {TK_WORD, &add_cmd}, {TK_PIPE, &add_sep}, {TK_SEMI, &add_sep}, - {TK_GREAT, &add_sep}, - {TK_LESS, &add_sep}, - {TK_DGREAT, &add_sep}, - {TK_DLESS, &add_sep}, + {TK_GREAT, &add_cmd}, + {TK_LESS, &add_cmd}, + {TK_DGREAT, &add_cmd}, + {TK_DLESS, &add_cmd}, {TK_OR_IF, &add_sep}, {TK_AND_IF, &add_sep}, {TK_WHILE, &add_cmd}, diff --git a/42sh/src/parser/error_syntax.c b/42sh/src/parser/error_syntax.c index 169be95f..7dde6502 100644 --- a/42sh/src/parser/error_syntax.c +++ b/42sh/src/parser/error_syntax.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:15:35 by ariard #+# #+# */ -/* Updated: 2017/02/24 19:12:35 by ariard ### ########.fr */ +/* Updated: 2017/03/01 16:53:53 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 01f978b8..fbf5b2da 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -58,5 +58,6 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) } if (parser->state == SUCCESS) DG("sucessful parsing"); + DG("yolo"); return (0); } diff --git a/42sh/src/parser/parser_init.c b/42sh/src/parser/parser_init.c index 49998c26..f9e87aec 100644 --- a/42sh/src/parser/parser_init.c +++ b/42sh/src/parser/parser_init.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/21 16:14:04 by ariard #+# #+# */ -/* Updated: 2017/02/21 20:01:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/01 17:43:08 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index a92a8b9d..9910a4fc 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/03/01 16:25:33 by ariard ### ########.fr */ +/* Updated: 2017/03/01 17:17:20 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,8 @@ char *read_state(t_sym current) { + if (current == UNDEFINED) + return ("UNDEFINED"); if (current == BRACE_CLAUSE) return ("BRACE_CLAUSE"); if (current == FUNC_NAME) diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index 0928d24a..4a17daca 100644 --- a/42sh/src/parser/tree_wrapper.c +++ b/42sh/src/parser/tree_wrapper.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:57:44 by ariard #+# #+# */ -/* Updated: 2017/03/01 15:59:32 by ariard ### ########.fr */ +/* Updated: 2017/03/01 16:47:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,13 +26,12 @@ int gen_node(t_btree **ast) if (!*ast) { *ast = btree_create_node(&item, sizeof(item)); - ((t_astnode *)(*ast)->item)->data.cmd = NULL; + ((t_astnode *)(*ast)->item)->data.cmd.redir = NULL; + ((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; ((t_astnode *)(*ast)->item)->pattern = 0; } return (0); -} - - +} From 722a290aee2a5ee0b93ccbadd53f8ce2dd6a3935 Mon Sep 17 00:00:00 2001 From: "ariard@student.42.fr" Date: Wed, 1 Mar 2017 23:01:43 +0100 Subject: [PATCH 4/5] yale sauf subshell --- 42sh/F | 0 42sh/includes/parser.h | 2 +- 42sh/includes/types.h | 2 +- 42sh/src/main/main.c | 6 ++++-- 42sh/src/parser/add_cmd.c | 6 +++--- 42sh/src/parser/add_redir.c | 9 ++++++++- 42sh/src/parser/aggregate_sym.c | 2 +- 42sh/src/parser/build_tree.c | 3 ++- 42sh/src/parser/parser_init.c | 2 +- 42sh/src/parser/read_stack.c | 10 +++++----- 10 files changed, 26 insertions(+), 16 deletions(-) delete mode 100644 42sh/F diff --git a/42sh/F b/42sh/F deleted file mode 100644 index e69de29b..00000000 diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 93e4eb83..7001687d 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */ -/* Updated: 2017/03/01 18:02:01 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:39:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/types.h b/42sh/includes/types.h index b5d64f79..3445dc7b 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/01 16:55:33 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:39:16 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index a9cbbd1a..1050a47c 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/01 17:50:59 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:59:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,8 +30,10 @@ int handle_instruction(int fd) DG("START: state=%i", parser.state); while (1) { - if ((ret = readline(fd, get_lexer_stack(lexer) || parser.state == UNDEFINED, &str))) + if ((ret = readline(fd, get_lexer_stack(lexer) || + parser.state == UNDEFINED, &str))) { + ft_putstr("bonjour"); if (ret == -1) return (-1); return (parser.state == UNDEFINED ? error_EOF() : 1); diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 5ba1159d..3faa94a2 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/01 18:02:27 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:46:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,12 +20,12 @@ int add_cmd(t_btree **ast, t_list **lst) if ((token = (*lst)->content)->type == TK_IN || token->type == TK_PAREN_OPEN) return (0); + else if (isdir_sep(ast, lst)) + return (add_redir_type(ast, lst)); else if (!*ast) gen_node(ast); else if (isdir_word(ast, lst)) return (add_redir_word(ast, lst)); - else if (isdir_sep(ast, lst)) - return (add_redir_type(ast, lst)); else if (isloop(ast, lst) == 3) return (add_loop_condition(ast, lst)); else if (isloop(ast, lst)) diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 41c1eec6..ae36029c 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/01 17:59:17 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:44:53 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,13 @@ int isdir_sep(t_btree **ast, t_list **list) || token->type == TK_DLESS || token->type == TK_DGREAT)) return (1); } + if (!*ast) + { + if (token->type == TK_LESS || token->type == TK_GREAT + || token->type == TK_GREATAND || token->type == TK_LESSAND + || token->type == TK_DLESS || token->type == TK_DGREAT) + return (1); + } return (0); } diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 0ddc11af..07bcf532 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:39:18 by ariard #+# #+# */ -/* Updated: 2017/03/01 17:00:05 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:55:14 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 5b584160..f1360913 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/01 18:01:38 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:39:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ t_treematch g_treematch[] = {TK_DLESS, &add_cmd}, {TK_OR_IF, &add_sep}, {TK_AND_IF, &add_sep}, + {TK_AMP, &add_sep}, {TK_WHILE, &add_cmd}, {TK_UNTIL, &add_cmd}, {TK_DO, &add_cmd}, diff --git a/42sh/src/parser/parser_init.c b/42sh/src/parser/parser_init.c index f9e87aec..3e78e937 100644 --- a/42sh/src/parser/parser_init.c +++ b/42sh/src/parser/parser_init.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/21 16:14:04 by ariard #+# #+# */ -/* Updated: 2017/03/01 17:43:08 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:54:37 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index 9910a4fc..8373fc1f 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/03/01 17:17:20 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:53:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,10 @@ char *read_state(t_sym current) { - if (current == UNDEFINED) - return ("UNDEFINED"); + if (current == LINEBREAK) + return ("LINEBREAK"); + if (current == CLOSE_LIST) + return ("CLOSE_LIST"); if (current == BRACE_CLAUSE) return ("BRACE_CLAUSE"); if (current == FUNC_NAME) @@ -192,8 +194,6 @@ char *read_state(t_sym current) return ("ALL"); if (current == NEWLINE_LIST) return ("NEWLINE_LIST"); - if (current == LINEBREAK) - return ("LINEBREAK"); if (current != 0) return ("NON-DEFINED"); if (current == 0) From 37d9898f5955359a99965a851ac5e12739d774b6 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Thu, 2 Mar 2017 22:02:53 +0100 Subject: [PATCH 5/5] doing pipe + lst cmds --- 42sh/file1 | 0 42sh/file2 | 14 ++++++++++++++ 42sh/includes/parser.h | 4 ++-- 42sh/includes/types.h | 3 ++- 42sh/libft | 2 +- 42sh/src/exec/ast_free.c | 4 +++- 42sh/src/lexer/lexer_default.c | 2 +- 42sh/src/lexer/lexer_number.c | 12 ++++++++++-- 42sh/src/lexer/lexer_word.c | 2 +- 42sh/src/main/ft_putast.c | 4 +++- 42sh/src/main/main.c | 4 ++-- 42sh/src/parser/add_cmd.c | 7 ++++--- 42sh/src/parser/add_condition.c | 2 +- 42sh/src/parser/add_func.c | 2 +- 42sh/src/parser/add_loop.c | 2 +- 42sh/src/parser/add_redir.c | 6 +++--- 42sh/src/parser/add_sep.c | 2 +- 42sh/src/parser/add_subshell.c | 3 +-- 42sh/src/parser/aggregate_sym.c | 11 ++++++----- 42sh/src/parser/build_tree.c | 2 +- 42sh/src/parser/eval_sym.c | 2 +- 42sh/src/parser/ft_parse.c | 11 ++++------- 42sh/src/parser/parser_init.c | 2 +- 42sh/src/parser/produce_sym.c | 8 ++++---- 42sh/src/parser/push_stack.c | 2 +- 42sh/src/parser/read_stack.c | 2 +- 42sh/src/parser/tree_wrapper.c | 6 +++--- 27 files changed, 73 insertions(+), 48 deletions(-) create mode 100644 42sh/file1 create mode 100644 42sh/file2 diff --git a/42sh/file1 b/42sh/file1 new file mode 100644 index 00000000..e69de29b diff --git a/42sh/file2 b/42sh/file2 new file mode 100644 index 00000000..37e50d1b --- /dev/null +++ b/42sh/file2 @@ -0,0 +1,14 @@ +total 576 +-rwxr-xr-x 1 ariard 2016_paris 690 Feb 21 15:30 update_makefile.sh +drwxr-xr-x 13 ariard 2016_paris 442 Feb 21 15:30 src +drwxr-xr-x 28 ariard 2016_paris 952 Feb 25 18:21 sample +drwxr-xr-x 6 ariard 2016_paris 204 Feb 21 15:30 pdf +drwxr-xr-x 13 ariard 2016_paris 442 Mar 2 20:15 objs +drwxr-xr-x 12 ariard 2016_paris 408 Mar 2 20:15 libft +drwxr-xr-x 19 ariard 2016_paris 646 Mar 2 20:36 includes +-rw-r--r-- 1 ariard 2016_paris 0 Mar 2 20:40 file2 +-rw-r--r-- 1 ariard 2016_paris 0 Mar 2 20:40 file1 +-rw-r--r-- 1 ariard 2016_paris 4396 Feb 21 15:40 donovan_segaults_06-02 +-rw-r--r-- 1 ariard 2016_paris 21985 Mar 2 20:39 STDBUG +-rw-r--r-- 1 ariard 2016_paris 8051 Mar 1 16:42 Makefile +-rwxr-xr-x 1 ariard 2016_paris 246884 Mar 2 20:38 42sh diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 7001687d..690e3ac8 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */ -/* Updated: 2017/03/01 22:39:00 by ariard ### ########.fr */ +/* Updated: 2017/03/02 22:02:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -163,7 +163,7 @@ struct s_cmd union u_astdata { - t_cmd cmd; + t_list *cmds; t_list *wordlist; char **sstr; char *str; diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 3445dc7b..398625af 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/01 22:39:16 by ariard ### ########.fr */ +/* Updated: 2017/03/02 20:36:25 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -159,6 +159,7 @@ enum e_sym FUNC_NAME, CLOSE_LIST, REDIR, + JOB, ALL = 200, }; diff --git a/42sh/libft b/42sh/libft index bfc8ca20..8f6e64fa 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit bfc8ca207ab4d39f0140322c0f1d368137304a3c +Subproject commit 8f6e64fa9b4ac1dd3e3d5200fb93471ddfeedd40 diff --git a/42sh/src/exec/ast_free.c b/42sh/src/exec/ast_free.c index 66abd247..de356f4f 100644 --- a/42sh/src/exec/ast_free.c +++ b/42sh/src/exec/ast_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */ -/* Updated: 2017/03/01 16:36:20 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:40:54 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,8 @@ void ast_free(void *data, size_t content_size) (void)node; (void)data; (void)content_size; + + return ; /* (void)content_size; node = data; diff --git a/42sh/src/lexer/lexer_default.c b/42sh/src/lexer/lexer_default.c index d5688999..d2acede7 100644 --- a/42sh/src/lexer/lexer_default.c +++ b/42sh/src/lexer/lexer_default.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */ -/* Updated: 2017/02/25 20:39:29 by ariard ### ########.fr */ +/* Updated: 2017/03/01 23:40:16 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_number.c b/42sh/src/lexer/lexer_number.c index 3bb079b7..8759c156 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/02/25 20:39:33 by ariard ### ########.fr */ +/* Updated: 2017/03/01 23:39:37 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,12 +29,20 @@ int lexer_number(t_list **alst, t_lexer *lexer) lexer->state = state; return (lexer_lex(alst, lexer)); } - else if (ft_isdigit(lexer->str[lexer->pos])) + else if (ft_isdigit(lexer->str[lexer->pos]) + && (lexer->str[lexer->pos + 1] == '>' || lexer->str[lexer->pos + 1] == '<')) { token_append(token, lexer, 0, 0); lexer->pos++; return (lexer_number(alst, lexer)); } + else + { + token->type = TK_WORD; + token_append(token, lexer, 0, 0); + lexer->pos++; + return (lexer_lex(alst, lexer)); + } lexer->state = DEFAULT; return (lexer_lex(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index 25f2e6ef..37d82adc 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/01 14:06:03 by ariard ### ########.fr */ +/* Updated: 2017/03/01 23:32:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index 6b35fe87..b9731110 100644 --- a/42sh/src/main/ft_putast.c +++ b/42sh/src/main/ft_putast.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */ -/* Updated: 2017/03/01 15:56:54 by ariard ### ########.fr */ +/* Updated: 2017/03/02 20:39:36 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,8 @@ char *ft_putast(void *nodein) t_astnode *node; node = nodein; + if (node->type == JOB) + return ("JOB"); if (node->type == REDIR) return ("REDIR"); if (node->type == CLOSE_LIST) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 1050a47c..a4ca3108 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/01 22:59:40 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:40:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -63,12 +63,12 @@ int handle_instruction(int fd) else if (parser.state == ERROR) error_syntax(&token); token = NULL; - ast = NULL; } DG("succesful parsing:"); btree_print(STDBUG, ast, &ft_putast); /* if (ft_exec(&ast)) */ /* return (1); */ + btree_del(&ast, &ast_free); ft_add_str_in_history(lexer.str); return (0); } diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 3faa94a2..e07d5ffc 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/01 22:46:31 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:53:48 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,17 +45,18 @@ int add_cmd(t_btree **ast, t_list **lst) else if (isfunc(ast, lst)) return (add_func_cmd(ast, lst)); else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN - && node->type != TK_PAREN_CLOSE && node->type != TK_WORD + && node->type != TK_PAREN_CLOSE && node->type != JOB && node->type != REDIR) return (add_cmd(&(*ast)->right, lst)); my_tab = NULL; node = (*ast)->item; - node->type = token->type; + node->type = JOB; if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD) { DG("add data"); 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); } return (0); diff --git a/42sh/src/parser/add_condition.c b/42sh/src/parser/add_condition.c index a3987a98..400c85f9 100644 --- a/42sh/src/parser/add_condition.c +++ b/42sh/src/parser/add_condition.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/19 18:12:52 by ariard #+# #+# */ -/* Updated: 2017/03/01 15:59:58 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:40:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index ada2a7be..1680e828 100644 --- a/42sh/src/parser/add_func.c +++ b/42sh/src/parser/add_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ -/* Updated: 2017/02/25 00:32:00 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:41:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index 78608a48..b141fe65 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/02/25 19:18:01 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:41:02 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index ae36029c..71ca1719 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/01 22:44:53 by ariard ### ########.fr */ +/* Updated: 2017/03/02 22:01:51 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ int isdir_sep(t_btree **ast, t_list **list) if (*ast) { node = (*ast)->item; - if ((node->type == TK_WORD || node->type == REDIR) + if (node->type == JOB && (token->type == TK_LESS || token->type == TK_GREAT || token->type == TK_GREATAND || token->type == TK_LESSAND || token->type == TK_DLESS || token->type == TK_DGREAT)) @@ -47,7 +47,7 @@ int isdir_word(t_btree **ast, t_list **list) { node = (*ast)->item; if (token->type == TK_WORD && node->type == REDIR) - return (1); + return ((node->type = JOB)); } return (0); } diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index 076f16f8..65a93ce7 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/03/01 18:02:14 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:41:07 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_subshell.c b/42sh/src/parser/add_subshell.c index 17e83953..63f1ecde 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/02/24 23:38:40 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:41:11 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,6 @@ int issubshell(t_btree **ast, t_list **lst) node = NULL; token = (*lst)->content; - DG("test loop"); if (*ast) { node = (*ast)->item; diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 07bcf532..87e64a66 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:39:18 by ariard #+# #+# */ -/* Updated: 2017/03/01 22:55:14 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:41:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -107,6 +107,7 @@ t_aggrematch g_aggrematch[] = {IO_HERE, TK_IO_NUMBER, IO_REDIRECT, TK_IO_NUMBER}, {IO_HERE, ALL, IO_REDIRECT, 0}, {IO_REDIRECT, CMD_SUPERIOR, CMD_SUPERIOR, CMD_SUPERIOR}, + {IO_REDIRECT, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE}, {IO_REDIRECT, COMPOUND_COMMAND, REDIRECT_LIST, REDIRECT_LIST}, //to check @@ -305,20 +306,20 @@ int aggregate_sym(t_sym **stack, t_sym *new_sym, t_parstate *state) int i; i = 0; - DG("aggregate head %s && sym %s", - read_state(**stack), read_state(*new_sym)); +// DG("aggregate head %s && sym %s", +// read_state(**stack), read_state(*new_sym)); while (g_aggrematch[i].top) { if (*new_sym == g_aggrematch[i].top && MATCH_STACK(**stack, g_aggrematch[i].under)) { - DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); +// DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); *new_sym = g_aggrematch[i].new_sym; if (g_aggrematch[i].erase_sym) { pop_stack(stack, g_aggrematch[i].erase_sym); - DG("stack after pop: %s", read_state(**stack)); +// DG("stack after pop: %s", read_state(**stack)); } if (eval_sym(**stack, *new_sym)) return ((*state = ERROR)); diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index f1360913..733129e4 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/01 22:39:39 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:41:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 4c0fc578..cae28a05 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -1009,7 +1009,7 @@ int eval_sym(t_sym stack, t_sym new_sym) { int i; - DG("eval head %s && sym %s", read_state(stack), read_state(new_sym)); +// DG("eval head %s && sym %s", read_state(stack), read_state(new_sym)); i = 0; while (g_stackmatch[i].top) { diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index fbf5b2da..ef80af07 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -29,13 +29,11 @@ static int end_instruction(t_sym sym) int ft_parse(t_btree **ast, t_list **token, t_parser *parser) { - (void)ast; - if (parser->state == SUCCESS || parser->state == ERROR) - parser_init(parser); while (*token) { produce_sym(*parser->stack, parser->new_sym, token); - DG("new sym %s", read_state(*parser->new_sym)); + //DG("new sym %s", read_state(*parser->new_sym)); + if (eval_sym(*parser->stack, *parser->new_sym)) return ((parser->state = ERROR)); else @@ -43,14 +41,14 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) aggregate_sym(&parser->stack, parser->new_sym, &parser->state); push_stack(++parser->stack, *parser->new_sym); } - ft_read_stack(parser->stack); +// ft_read_stack(parser->stack); DG("\n"); if (*parser->stack == PROGRAM) parser->state = SUCCESS; else parser->state = UNDEFINED; build_tree(ast, token); - btree_print(STDBUG, *ast, &ft_putast); + // btree_print(STDBUG, *ast, &ft_putast); if ((end_instruction(*parser->stack) && !(*token)->next)) insert_linebreak(token); else @@ -58,6 +56,5 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) } if (parser->state == SUCCESS) DG("sucessful parsing"); - DG("yolo"); return (0); } diff --git a/42sh/src/parser/parser_init.c b/42sh/src/parser/parser_init.c index 3e78e937..b15a1fce 100644 --- a/42sh/src/parser/parser_init.c +++ b/42sh/src/parser/parser_init.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/21 16:14:04 by ariard #+# #+# */ -/* Updated: 2017/03/01 22:54:37 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:40:37 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index 26a0448b..ae71c3fd 100644 --- a/42sh/src/parser/produce_sym.c +++ b/42sh/src/parser/produce_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:58:34 by ariard #+# #+# */ -/* Updated: 2017/03/01 14:40:24 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:40:41 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -105,8 +105,8 @@ int produce_sym(t_sym stack, t_sym *new_sym, t_list **lst) int i; token = (*lst)->content; - DG("produce stack : %s && token : %s", read_state(stack), - read_state(token->type)); +// DG("produce stack : %s && token : %s", read_state(stack), +// read_state(token->type)); i = 0; *new_sym = 0; while (g_prodmatch[i].new_sym) @@ -114,7 +114,7 @@ int produce_sym(t_sym stack, t_sym *new_sym, t_list **lst) if (token->type == g_prodmatch[i].token && stack == g_prodmatch[i].stack) { - DG("MATCH : %s", read_state(g_prodmatch[i].new_sym)); +// DG("MATCH : %s", read_state(g_prodmatch[i].new_sym)); *new_sym = g_prodmatch[i].new_sym; } i++; diff --git a/42sh/src/parser/push_stack.c b/42sh/src/parser/push_stack.c index 1d0d9278..11b0576d 100644 --- a/42sh/src/parser/push_stack.c +++ b/42sh/src/parser/push_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 16:48:30 by ariard #+# #+# */ -/* Updated: 2017/02/13 20:19:33 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:40:45 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index 8373fc1f..0c845b90 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/03/01 22:53:39 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:40:47 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index 4a17daca..7de56874 100644 --- a/42sh/src/parser/tree_wrapper.c +++ b/42sh/src/parser/tree_wrapper.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:57:44 by ariard #+# #+# */ -/* Updated: 2017/03/01 16:47:13 by ariard ### ########.fr */ +/* Updated: 2017/03/02 21:40:48 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,8 +26,8 @@ int gen_node(t_btree **ast) if (!*ast) { *ast = btree_create_node(&item, sizeof(item)); - ((t_astnode *)(*ast)->item)->data.cmd.redir = NULL; - ((t_astnode *)(*ast)->item)->data.cmd.token = NULL; + 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;