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] 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); -} - - +}