diff --git a/42sh/Makefile b/42sh/Makefile index 6dd30607..9929b18b 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 16:42:16 by ariard ### ########.fr # # # # **************************************************************************** # @@ -230,11 +230,11 @@ 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\ 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/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/includes/parser.h b/42sh/includes/parser.h index 1812e496..7001687d 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 22:39:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -86,7 +87,7 @@ 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); /* @@ -107,13 +108,14 @@ 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_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,14 +125,16 @@ 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 isdir(t_btree **ast); +int iscondition(t_btree **ast, t_list **list); +int isdir_sep(t_btree **ast, t_list **list); +int isdir_word(t_btree **ast, t_list **list); /* * Build AST @@ -151,10 +155,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; @@ -162,10 +171,9 @@ union u_astdata struct s_astnode { - + int pattern; 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 e0f7ade6..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/02/25 19:37:31 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:39:16 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; @@ -157,6 +158,7 @@ enum e_sym PATTERN_CASE, FUNC_NAME, CLOSE_LIST, + REDIR, ALL = 200, }; 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 5d1f9b07..3d0807b5 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/21 22:41:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/02 12:36:28 by jhalford ### ########.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/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/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/line-editing/readline.c b/42sh/src/line-editing/readline.c index 8ccc2fdb..8f79d589 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:30:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/02 12:36:35 by jhalford ### ########.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 bcd21b3c..f0a1e2d9 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/02 12:37:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,8 +28,10 @@ int handle_instruction(int fd) ast = NULL; while (1) { - if ((ret = readline(fd, get_lexer_stack(lexer), &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); @@ -57,7 +59,7 @@ int handle_instruction(int fd) else if (parser.state == ERROR && !SH_IS_INTERACTIVE(data_singleton()->opts)) return (error_syntax(&token)); else if (parser.state == ERROR) - error_syntax(&token); + error_syntax(&token); token = NULL; ast = NULL; } diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index d2e3e825..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/02/25 18:50:30 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:46:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,13 +18,14 @@ 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 (isdir_sep(ast, lst)) + return (add_redir_type(ast, lst)); else if (!*ast) gen_node(ast); - else if (isdir(ast, lst)) - return (add_file(ast, lst)); + else if (isdir_word(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 +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_PAREN_CLOSE && node->type != TK_WORD + && node->type != REDIR) return (add_cmd(&(*ast)->right, lst)); my_tab = NULL; node = (*ast)->item; node->type = token->type; 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); - 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 52% rename from 42sh/src/parser/add_file.c rename to 42sh/src/parser/add_redir.c index c056049c..ae36029c 100644 --- a/42sh/src/parser/add_file.c +++ b/42sh/src/parser/add_redir.c @@ -6,13 +6,13 @@ /* 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 22:44:53 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "parser.h" -int isdir(t_btree **ast, t_list **list) +int isdir_sep(t_btree **ast, t_list **list) { t_astnode *node; t_token *token; @@ -20,25 +20,39 @@ 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) + node = (*ast)->item; + if ((node->type == TK_WORD || node->type == REDIR) && (token->type == TK_LESS || token->type == TK_GREAT - || token->type == TK_LESSAND || token->type == TK_GREATAND - || token->type == TK_DGREAT)) - return (2); + || token->type == TK_GREATAND || token->type == TK_LESSAND + || 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); } -int add_file(t_btree **ast, t_list **lst) +int isdir_word(t_btree **ast, t_list **list) +{ + t_astnode *node; + t_token *token; + + token = (*list)->content; + if (*ast) + { + node = (*ast)->item; + if (token->type == TK_WORD && node->type == REDIR) + return (1); + } + return (0); +} + +int add_redir_word(t_btree **ast, t_list **lst) { t_astnode *node; t_token *token; @@ -46,28 +60,34 @@ 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, &ft_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; t_redir *redir; DG("add redir"); - if (!ast) + if (!*ast) 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 a80093f4..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/02/25 19:28:47 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 dba05036..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/02/25 13:53:57 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:55:14 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -92,9 +92,6 @@ t_aggrematch g_aggrematch[] = {NEWLINE_LIST, FOR_WORDLIST, SEQUENTIAL_SEP, 0}, //to check - {HERE_END, TK_DLESS, IO_HERE, TK_DLESS}, - {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}, @@ -103,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/build_tree.c b/42sh/src/parser/build_tree.c index 2d8a7e70..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/02/25 19:21:05 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:39:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,12 +17,13 @@ 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_AMP, &add_sep}, {TK_WHILE, &add_cmd}, {TK_UNTIL, &add_cmd}, {TK_DO, &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..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/02/21 20:01:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/01 22:54:37 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ 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..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/02/25 00:15:00 by ariard ### ########.fr */ +/* Updated: 2017/03/01 22:53:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,10 @@ char *read_state(t_sym current) { + if (current == LINEBREAK) + return ("LINEBREAK"); + if (current == CLOSE_LIST) + return ("CLOSE_LIST"); if (current == BRACE_CLAUSE) return ("BRACE_CLAUSE"); if (current == FUNC_NAME) @@ -190,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) diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index ac2d3d5b..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/02/25 19:10:34 by ariard ### ########.fr */ +/* Updated: 2017/03/01 16:47:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,14 +26,12 @@ 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.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); -} - - +}