diff --git a/42sh/sample/while.sh b/42sh/sample/while.sh index 8c6fb2e9..bb41f8ed 100644 --- a/42sh/sample/while.sh +++ b/42sh/sample/while.sh @@ -1,20 +1,11 @@ echo "begin loop" -while [ 1 ] -do - echo "inner loop1" +while [ 1 ] +do + echo "begin inner loop" while [ 1 ] do - echo "love 42" + echo "end scd loop" done - echo "inner loop2" - while [ 1 ] - do - echo "inner loop2-1" - while [ 1 ] - do - echo "hello world" - done - echo "salut monde" - done -done + echo "end inner loop" +done echo "end loop" diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index 5a47ff90..80176ee5 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/01/30 23:25:44 by ariard ### ########.fr */ +/* Updated: 2017/02/02 17:25:52 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,7 +38,6 @@ int exec_command(t_btree **ast) p->pid = 0; p->attributes = PROCESS_PIPESTART | PROCESS_PIPEEND; - if (!(p->script & SCRIPT_LOOP)) - btree_delone(ast, &ast_free); +// btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_default.c b/42sh/src/exec/exec_default.c index 57489149..c37f3d73 100644 --- a/42sh/src/exec/exec_default.c +++ b/42sh/src/exec/exec_default.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/31 19:29:59 by ariard #+# #+# */ -/* Updated: 2017/01/31 19:57:44 by ariard ### ########.fr */ +/* Updated: 2017/02/02 15:54:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,8 @@ int exec_default(t_btree **ast) { - t_process *p; - - p = &data_singleton()->exec.process; - if (!(p->script & SCRIPT_LOOP)) - btree_delone(ast, &ast_free); + + (void)ast; +// btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_list.c b/42sh/src/exec/exec_list.c index aab8b1ce..061c4291 100644 --- a/42sh/src/exec/exec_list.c +++ b/42sh/src/exec/exec_list.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 20:19:29 by ariard #+# #+# */ -/* Updated: 2017/01/30 20:57:51 by ariard ### ########.fr */ +/* Updated: 2017/02/02 16:00:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,7 @@ int exec_list(t_btree **ast) { - t_process *p; - - p = &data_singleton()->exec.process; - if (!(p->script & SCRIPT_LOOP)) - btree_delone(ast, &ast_free); + (void)ast; +// btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_while.c b/42sh/src/exec/exec_while.c index c7cd2d58..40ce2599 100644 --- a/42sh/src/exec/exec_while.c +++ b/42sh/src/exec/exec_while.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 17:33:53 by ariard #+# #+# */ -/* Updated: 2017/01/31 23:20:33 by ariard ### ########.fr */ +/* Updated: 2017/02/02 16:30:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,30 +14,23 @@ int exec_while(t_btree **ast) { - t_list **test_commands; t_list **consequent_commands; t_astnode *node; - t_process *p; int test; - node = ((*ast)->left)->item; - DG("test command data '%s'", node->data.str); - test_commands = shell_get_ast(node->data.str); node = ((*ast)->right)->item; - DG("consequent command data '%s'", node->data.str); consequent_commands = shell_get_ast(node->data.str); - - p = &data_singleton()->exec.process; - p->script |= SCRIPT_LOOP; - test = 10; while (test--) + { loop_exec(*consequent_commands); - loop_del(*consequent_commands); - p->script &= 0; - btree_delone(ast, &ast_free); + DG("end loop : '%d'", test); + } + +// loop_del(*consequent_commands); +// btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/lexer/ft_post_tokenize.c b/42sh/src/lexer/ft_post_tokenize.c index 3de67de3..881b03fe 100644 --- a/42sh/src/lexer/ft_post_tokenize.c +++ b/42sh/src/lexer/ft_post_tokenize.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:11:11 by jhalford #+# #+# */ -/* Updated: 2017/01/22 23:33:04 by ariard ### ########.fr */ +/* Updated: 2017/02/02 17:50:45 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ int ft_post_tokenize(t_list **alst, char *str) { int ret; +// get_reserverd_words(alst, str); while ((ret = reduce_parens(alst, str))) if (ret == -1) return (-1); diff --git a/42sh/src/lexer/ft_tokenize.c b/42sh/src/lexer/ft_tokenize.c index 4da8fbdf..6e9aaea2 100644 --- a/42sh/src/lexer/ft_tokenize.c +++ b/42sh/src/lexer/ft_tokenize.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */ -/* Updated: 2017/01/31 23:58:41 by ariard ### ########.fr */ +/* Updated: 2017/02/02 17:50:28 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,13 +29,6 @@ int (*g_lexer[])(t_list **alst, char *str) = &lexer_backslash, &lexer_var, &lexer_special, - &lexer_while, - &lexer_do, - &lexer_done, - &lexer_if, - &lexer_then, - &lexer_fi, - &lexer_list, &lexer_comment, }; diff --git a/42sh/src/lexer/get_reserved_words.c b/42sh/src/lexer/get_reserved_words.c index 79dc8b62..996ce9b1 100644 --- a/42sh/src/lexer/get_reserved_words.c +++ b/42sh/src/lexer/get_reserved_words.c @@ -6,25 +6,35 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ -/* Updated: 2017/01/31 23:51:56 by ariard ### ########.fr */ +/* Updated: 2017/02/02 17:50:17 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -t_lexstate get_reserved_words(char *str) +int get_reserved_words(t_list **alst) { - if (ft_strncmp(str, "while", 5) == 0) - return (WHILE); - else if (ft_strncmp(str, "done", 4) == 0 && ft_isalpha(*(str + 4)) == 0) - return (DONE); - else if (ft_strncmp(str, "do" , 2) == 0 && ft_isalpha(*(str + 2)) == 0) - return (DO); - else if (ft_strncmp(str, "if", 2) == 0 && ft_isalpha(*(str + 2)) == 0) - return (IF); - else if (ft_strncmp(str, "then", 4) == 0 && ft_isalpha(*(str + 4)) == 0) - return (THEN); - else if (ft_strncmp(str, "fi", 2) == 0 && ft_isalpha(*(str + 2)) == 0) - return (FI); + t_token token; + + while (*alst) + { + token = (*alst)->content; + if (token->type = TK_WORD); + { + if (ft_strncmp(str, "while", 5) == 0 && ft_isalpha(*(str + 5)) == 0) + lexer_while( + else if (ft_strncmp(str, "done", 4) == 0 && ft_isalpha(*(str + 4)) == 0) + return (DONE); + else if (ft_strncmp(str, "do" , 2) == 0 && ft_isalpha(*(str + 2)) == 0) + return (DO); +// else if (ft_strncmp(str, "if", 2) == 0 && ft_isalpha(*(str + 2)) == 0) +// return (IF); +// else if (ft_strncmp(str, "then", 4) == 0 && ft_isalpha(*(str + 4)) == 0) +// return (THEN); +// else if (ft_strncmp(str, "fi", 2) == 0 && ft_isalpha(*(str + 2)) == 0) +// return (FI); + } + (*alst) = (*alst)->next; + } return (0); } diff --git a/42sh/src/lexer/lexer_list.c b/42sh/src/lexer/lexer_list.c index fc2b30d7..31e470b9 100644 --- a/42sh/src/lexer/lexer_list.c +++ b/42sh/src/lexer/lexer_list.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:55:33 by ariard #+# #+# */ -/* Updated: 2017/01/31 23:58:50 by ariard ### ########.fr */ +/* Updated: 2017/02/02 17:31:07 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,8 +25,7 @@ int lexer_list(t_list **alst, char *str) token_append(token, *str++); while (ft_is_delim(*str) || *str == '\n') str++; - if (ft_strncmp(str, "done", 4) == 0 && (ft_is_delim_list(*(str + 4)) - || *(str + 4) == ' ')) + if (ft_strncmp(str, "done", 4) == 0 && ft_isalpha(*(str + 4)) == 0) return (ft_tokenize(alst, str, DONE)); else if (ft_strncmp(str, "do", 2) == 0 && (ft_is_delim_list(*(str + 2)) || *(str + 2) == ' ')) @@ -34,8 +33,7 @@ int lexer_list(t_list **alst, char *str) else if (ft_strncmp(str, "then", 4) == 0 && (ft_is_delim_list(*(str + 4)) || *(str + 4) == ' ')) return (ft_tokenize(alst, str, THEN)); - else if (ft_strncmp(str, "fi", 2) == 0 && (ft_is_delim_list(*(str + 2)) - || *(str + 2) == ' ')) + else if (ft_strncmp(str, "fi", 2) == 0 && ft_isalpha(*(str + 2)) == 0) return (ft_tokenize(alst, str, FI)); } token_append(token, *str++); diff --git a/42sh/src/lexer/lexer_sep.c b/42sh/src/lexer/lexer_sep.c index 3e3c6ef3..7c686546 100644 --- a/42sh/src/lexer/lexer_sep.c +++ b/42sh/src/lexer/lexer_sep.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ -/* Updated: 2017/01/26 00:48:08 by ariard ### ########.fr */ +/* Updated: 2017/02/02 16:30:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index 3221534b..6dca613a 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/01/30 23:17:43 by ariard ### ########.fr */ +/* Updated: 2017/02/02 17:50:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,8 +25,6 @@ int lexer_word(t_list **alst, char *str) return (ft_tokenize(&(*alst)->next, str, GREAT)); else if (*str == '<') return (ft_tokenize(&(*alst)->next, str, LESS)); - else if ((state = get_reserved_words(str))) - return (ft_tokenize(alst, str, state)); token_append(token, *str); return (ft_tokenize(alst, str + 1, WORD)); } diff --git a/42sh/src/lexer/reduce_bquotes.c b/42sh/src/lexer/reduce_bquotes.c index 4247ceb0..fbe1022b 100644 --- a/42sh/src/lexer/reduce_bquotes.c +++ b/42sh/src/lexer/reduce_bquotes.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:46:27 by jhalford #+# #+# */ -/* Updated: 2017/01/22 23:33:08 by ariard ### ########.fr */ +/* Updated: 2017/02/02 17:40:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c index 43b19555..87b5fff4 100644 --- a/42sh/src/main/shell_script.c +++ b/42sh/src/main/shell_script.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/22 23:06:34 by ariard #+# #+# */ -/* Updated: 2017/01/31 23:56:53 by ariard ### ########.fr */ +/* Updated: 2017/02/02 17:50:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,7 +31,6 @@ int shell_script() return (1); DG("after post_tokenize"); token_print(token); - return (0); if (ft_parse(&list_ast, &ast, &token)) return (1); tmp2 = list_ast; @@ -47,6 +46,8 @@ int shell_script() return (1); list_ast = list_ast->next; } -*/ loop_exec(list_ast); + +*/ + loop_exec(list_ast); return (0); } diff --git a/42sh/src/parser/parse_done.c b/42sh/src/parser/parse_done.c index 83a5f6f1..3e4ef836 100644 --- a/42sh/src/parser/parse_done.c +++ b/42sh/src/parser/parse_done.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 16:36:28 by ariard #+# #+# */ -/* Updated: 2017/01/31 19:36:49 by ariard ### ########.fr */ +/* Updated: 2017/02/02 16:44:47 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_while.c b/42sh/src/parser/parse_while.c index da3e5f6b..f8b01c55 100644 --- a/42sh/src/parser/parse_while.c +++ b/42sh/src/parser/parse_while.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 16:03:28 by ariard #+# #+# */ -/* Updated: 2017/01/30 19:52:17 by ariard ### ########.fr */ +/* Updated: 2017/02/02 16:30:35 by ariard ### ########.fr */ /* */ /* ************************************************************************** */