diff --git a/42sh/Makefile b/42sh/Makefile index 00263478..147fe340 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -55,6 +55,7 @@ exec/exec_while.c\ exec/exec_if.c\ exec/exec_else.c\ exec/exec_elif.c\ +exec/exec_until.c\ exec/ft_exec.c\ exec/ft_findexec.c\ exec/launch_process.c\ diff --git a/42sh/file1 b/42sh/file1 index ce013625..e69de29b 100644 --- a/42sh/file1 +++ b/42sh/file1 @@ -1 +0,0 @@ -hello diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 4e4279a3..6f6158d4 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/02/06 18:59:24 by ariard ### ########.fr */ +/* Updated: 2017/02/06 20:41:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -92,6 +92,7 @@ int exec_while(t_btree **ast); int exec_if(t_btree **ast); int exec_elif(t_btree **ast); int exec_else(t_btree **ast); +int exec_until(t_btree **ast); int exec_default(t_btree **ast); diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 96e9a93c..98fd2c83 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/02/06 15:13:20 by ariard ### ########.fr */ +/* Updated: 2017/02/06 20:35:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,6 +52,7 @@ typedef long long t_type; # define TK_FI (1 << 25) # define TK_ELIF (1 << 26) # define TK_ELSE (1 << 27) +# define TK_UNTIL (1 << 28) # define TK_WORD (TK_N_WORD | TK_Q_WORD | TK_DQ_WORD) # define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20) diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 71d07a8d..538825a3 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/02/06 19:02:48 by ariard ### ########.fr */ +/* Updated: 2017/02/06 20:35:28 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,9 @@ # include "minishell.h" +#define INSTRUCTION (TK_WHILE | TK_IF | TK_ELIF | TK_NEWLINE | TK_SEMI\ + | TK_ELSE | TK_UNTIL) + typedef struct s_parser t_parser; typedef struct s_ld t_ld; typedef struct s_astnode t_astnode; diff --git a/42sh/sample/4lines.sh b/42sh/sample/4lines.sh index 2ef2d5ba..d6610634 100644 --- a/42sh/sample/4lines.sh +++ b/42sh/sample/4lines.sh @@ -1,2 +1,2 @@ ls | cat - +pwd | cat > file1 diff --git a/42sh/sample/until.sh b/42sh/sample/until.sh new file mode 100644 index 00000000..c9394c45 --- /dev/null +++ b/42sh/sample/until.sh @@ -0,0 +1,8 @@ +until [ 1 ] +do + echo LOOP1 + until [ 1 ] + do + echo hello + done +done > file1 diff --git a/42sh/sample/until2.sh b/42sh/sample/until2.sh new file mode 100644 index 00000000..28aeabc8 --- /dev/null +++ b/42sh/sample/until2.sh @@ -0,0 +1,16 @@ +ONE=0 +while [ $ONE -le 10 ] +do + TWO=0 + while [ $TWO -le 10 ] + do + THREE=0 + while [ $THREE -le 10 ] + do + echo world + ((THREE++)) + done + ((TWO++)) + done + ((ONE++)) +done > file1 diff --git a/42sh/sample/while2.sh b/42sh/sample/while2.sh index d3d0f5e4..6549f933 100644 --- a/42sh/sample/while2.sh +++ b/42sh/sample/while2.sh @@ -13,4 +13,4 @@ do ((TWO--)) done ((ONE--)) -done +done > file1 diff --git a/42sh/src/exec/exec_if.c b/42sh/src/exec/exec_if.c index 82c18ec9..43c7aa87 100644 --- a/42sh/src/exec/exec_if.c +++ b/42sh/src/exec/exec_if.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */ -/* Updated: 2017/02/06 18:55:00 by ariard ### ########.fr */ +/* Updated: 2017/02/06 20:39:25 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_until.c b/42sh/src/exec/exec_until.c new file mode 100644 index 00000000..62b2a567 --- /dev/null +++ b/42sh/src/exec/exec_until.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* exec_until.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/02/06 20:42:20 by ariard #+# #+# */ +/* Updated: 2017/02/06 20:42:21 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "exec.h" + +int exec_until(t_btree **ast) +{ + int test; + + test = 0; + while (test++ != 10) + ft_exec(&(*ast)->right); + +// btree_delone(ast, &ast_free); + return (0); +} diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index a7070ea0..a97029b3 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2017/02/06 18:58:09 by ariard ### ########.fr */ +/* Updated: 2017/02/06 20:38:07 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,7 @@ t_execmap g_execmap[] = {TK_IF, &exec_if}, {TK_ELIF, &exec_elif}, {TK_ELSE, &exec_else}, + {TK_UNTIL, &exec_until}, {TK_COMMAND | TK_SUBSHELL, &exec_command}, {0, 0}, }; diff --git a/42sh/src/lexer/ft_lexer.c b/42sh/src/lexer/ft_lexer.c index 237127f8..6682e759 100644 --- a/42sh/src/lexer/ft_lexer.c +++ b/42sh/src/lexer/ft_lexer.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/02 15:30:59 by jhalford #+# #+# */ -/* Updated: 2017/02/04 15:12:32 by ariard ### ########.fr */ +/* Updated: 2017/02/06 20:27:07 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/get_reserved_words.c b/42sh/src/lexer/get_reserved_words.c index 14ed745b..00fd33ca 100644 --- a/42sh/src/lexer/get_reserved_words.c +++ b/42sh/src/lexer/get_reserved_words.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ -/* Updated: 2017/02/06 15:10:59 by ariard ### ########.fr */ +/* Updated: 2017/02/06 20:37:28 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,6 +43,8 @@ int get_reserved_words(t_list **alst) token->type = TK_ELIF; else if (ft_strncmp(token->data, "else", 4) == 0) token->type = TK_ELSE; + else if (ft_strncmp(token->data, "until", 5) == 0) + token->type = TK_UNTIL; } } previous_token = token; diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index 8ca640d5..acc9cfb8 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/06 19:16:59 by ariard ### ########.fr */ +/* Updated: 2017/02/06 20:37:16 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,6 +40,8 @@ char *ft_putast(void *nodein) return ("ELIF"); else if (node->type == TK_ELSE) return ("ELSE"); + else if (node->type == TK_UNTIL) + return ("UNTIL"); else if (node->type == TK_NEWLINE) return ("NEW"); else if (node->type == TK_GREAT) diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c index eb2b3d9c..a04baf04 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/02/06 19:26:06 by ariard ### ########.fr */ +/* Updated: 2017/02/06 20:58:54 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ int shell_script() { if (parse(&ast, &token)) return (1); -// btree_print(STDBUG, ast, &ft_putast); + btree_print(STDBUG, ast, &ft_putast); if (ft_exec(&ast)) return (1); ast = NULL; diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index de27102c..5631a0a8 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */ -/* Updated: 2017/02/06 19:26:04 by ariard ### ########.fr */ +/* Updated: 2017/02/06 20:37:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ t_parser g_parser[] = { - {TK_WHILE | TK_IF | TK_ELIF | TK_NEWLINE | TK_SEMI | TK_ELSE, &get_sub_instruction}, + {INSTRUCTION, &get_sub_instruction}, {TK_AND_IF | TK_OR_IF, &parse_separator}, {TK_AMP, &parse_separator}, {TK_PIPE, &parse_separator}, diff --git a/42sh/src/parser/get_instruction.c b/42sh/src/parser/get_instruction.c index 00e7e110..09910fd3 100644 --- a/42sh/src/parser/get_instruction.c +++ b/42sh/src/parser/get_instruction.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 16:56:55 by ariard #+# #+# */ -/* Updated: 2017/02/06 19:18:17 by ariard ### ########.fr */ +/* Updated: 2017/02/06 20:30:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -101,7 +101,7 @@ int get_instruction(t_list **lst) token = (*lst)->content; if (token->type & TK_NEWLINE) return (get_simple_instruction(&start, lst)); - else if (token->type & TK_WHILE) + else if (token->type & (TK_WHILE | TK_UNTIL)) return (get_loop_instruction(&start, lst)); else if (token->type & TK_IF) return (get_condition_instruction(&start, lst)); diff --git a/42sh/src/parser/get_sub_instruction.c b/42sh/src/parser/get_sub_instruction.c index 59519558..c5935ce3 100644 --- a/42sh/src/parser/get_sub_instruction.c +++ b/42sh/src/parser/get_sub_instruction.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/05 22:05:26 by ariard #+# #+# */ -/* Updated: 2017/02/06 19:08:17 by ariard ### ########.fr */ +/* Updated: 2017/02/06 20:37:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,17 +17,17 @@ int get_sub_instruction(t_btree **ast, t_list **start, t_list **lst) t_token *token; token = (*lst)->content; - if (token->type == TK_NEWLINE) + if (token->type & TK_NEWLINE) return (parse_separator(ast, start, lst)); - else if (token->type == TK_WHILE) + else if (token->type & (TK_WHILE | TK_UNTIL)) return (parse_while(ast, start, lst)); - else if (token->type == TK_IF) + else if (token->type & TK_IF) return (parse_if(ast, start, lst)); - else if (token->type == TK_ELIF) + else if (token->type & TK_ELIF) return (parse_elif(ast, start, lst)); - else if (token->type == TK_ELSE) + else if (token->type & TK_ELSE) return (parse_else(ast, start, lst)); - else if (token->type == TK_SEMI) + else if (token->type & TK_SEMI) return (parse_separator(ast, start, lst)); return (0); }