diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index ed52dfeb..fda62039 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/01/24 20:01:46 by ariard ### ########.fr */ +/* Updated: 2017/01/30 18:57:16 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,8 @@ # define IS_PIPESTART(a) (a & PROCESS_PIPESTART) # define IS_PIPEEND(a) (a & PROCESS_PIPEEND) +# define SCRIPT_LOOP (1 << 0) + # include "libft.h" # include "types.h" # include "job_control.h" @@ -48,6 +50,7 @@ struct s_process int fdout; int status; t_flag attributes; + t_flag script; }; struct s_exec @@ -81,6 +84,8 @@ int exec_great(t_btree **ast); int exec_dgreat(t_btree **ast); int exec_command(t_btree **ast); +int exec_while(t_btree **ast); + int launch_process(t_process *p); int process_setexec(t_type type, t_process *p); int process_setgroup(t_process *p); diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 1e172f76..f1928bfa 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/01/30 16:32:37 by ariard ### ########.fr */ +/* Updated: 2017/01/30 18:05:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 33b25941..3dc119e6 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/01/26 20:57:21 by ariard ### ########.fr */ +/* Updated: 2017/01/30 19:23:44 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,11 +81,13 @@ int shell_single_command(char *command); int read_script(char *file); int shell_script(void); +t_list *shell_get_ast(char *command); void ft_expand_dollar(char **av, char **env); char *ft_findexec(char *path, char *file); char *ft_putast(void *node); void ft_putast2(void *node); +void ft_print_all_ast(t_list *lst_ast); #endif diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 9a9a7012..d9271c02 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/01/30 17:14:02 by ariard ### ########.fr */ +/* Updated: 2017/01/30 18:52:54 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/types.h b/42sh/includes/types.h index eaf9b3d9..7f87c28a 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/01/24 16:01:58 by ariard ### ########.fr */ +/* Updated: 2017/01/30 18:11:14 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/sample/while.sh b/42sh/sample/while.sh index 0a69155f..8a88a4d1 100644 --- a/42sh/sample/while.sh +++ b/42sh/sample/while.sh @@ -1,3 +1,3 @@ -ls ; while [ 1 ]; do - echo hello -done > file1 ; pwd +while echo bonjour toi > file1 ; do + echo hello world > file2 +done diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index 17da9096..344bded5 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/22 22:16:06 by ariard ### ########.fr */ +/* Updated: 2017/01/30 18:29:22 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_pipe.c b/42sh/src/exec/exec_pipe.c index 6d9899f6..ffb3e2fd 100644 --- a/42sh/src/exec/exec_pipe.c +++ b/42sh/src/exec/exec_pipe.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */ -/* Updated: 2017/01/20 00:17:05 by ariard ### ########.fr */ +/* Updated: 2017/01/30 17:32:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_semi.c b/42sh/src/exec/exec_semi.c index 335ac2ac..dfc164f9 100644 --- a/42sh/src/exec/exec_semi.c +++ b/42sh/src/exec/exec_semi.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */ -/* Updated: 2016/12/12 18:00:21 by jhalford ### ########.fr */ +/* Updated: 2017/01/30 17:34:07 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_while.c b/42sh/src/exec/exec_while.c new file mode 100644 index 00000000..2bfb44b6 --- /dev/null +++ b/42sh/src/exec/exec_while.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* exec_while.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */ +/* Updated: 2017/01/30 19:30:16 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "exec.h" + +int exec_while(t_btree **ast) +{ + t_list *test_commands; + t_list *consequent_commands; + t_astnode *node; + t_process *p; + + 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; + +// while (ft_test(test_commands)) +// ft_exec(consequent_commands) +// del tree (test_commands); +// del tree (test_commands); + btree_delone(ast, &ast_free); + return (0); +} diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 27a8fdff..ba452953 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/01/24 20:03:01 by ariard ### ########.fr */ +/* Updated: 2017/01/30 17:33:34 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,7 @@ t_execmap g_execmap[] = {TK_LESS, &exec_less}, {TK_GREAT, &exec_great}, {TK_DGREAT, &exec_dgreat}, + {TK_WHILE, &exec_while}, {TK_COMMAND | TK_SUBSHELL, &exec_command}, {0, 0}, }; diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index ca0b0bbe..172a37ab 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/01/22 22:11:35 by ariard ### ########.fr */ +/* Updated: 2017/01/30 18:30:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_setexec.c b/42sh/src/exec/process_setexec.c index db7afc51..6093aec2 100644 --- a/42sh/src/exec/process_setexec.c +++ b/42sh/src/exec/process_setexec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ -/* Updated: 2017/01/22 22:16:52 by ariard ### ########.fr */ +/* Updated: 2017/01/30 18:29:23 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/ft_print_all_ast.c b/42sh/src/main/ft_print_all_ast.c new file mode 100644 index 00000000..b07ea34f --- /dev/null +++ b/42sh/src/main/ft_print_all_ast.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_all_ast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/30 19:23:49 by ariard #+# #+# */ +/* Updated: 2017/01/30 19:26:42 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void ft_print_all_ast(t_list *lst_ast) +{ + t_list *tmp; + t_btree **ast; + + tmp = lst_ast; + while (tmp) + { + ast = tmp->content; + btree_print(STDBUG, *ast, &ft_putast); + tmp = tmp->next; + } +} diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 47590803..445aaece 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/01/26 21:08:49 by ariard ### ########.fr */ +/* Updated: 2017/01/30 18:59:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_get_ast.c b/42sh/src/main/shell_get_ast.c new file mode 100644 index 00000000..40784a5f --- /dev/null +++ b/42sh/src/main/shell_get_ast.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* shell_set_ast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/30 18:19:13 by ariard #+# #+# */ +/* Updated: 2017/01/30 19:28:19 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +t_list *shell_get_ast(char *command) +{ + t_list *token; + t_btree *ast; + t_list *list_ast; + + token = NULL; + ast = NULL; + list_ast = NULL; + if (ft_tokenize(&token, command, DEFAULT)) + return (NULL); + if (!token) + return (NULL); + if (ft_post_tokenize(&token, command)) + return (NULL); + DG("after post_tokenize"); + token_print(token); + if (ft_parse(&list_ast, &ast, &token)) + return (NULL); +// ft_print_all_ast(list_ast); + return (list_ast); +} diff --git a/42sh/src/main/shell_get_opts.c b/42sh/src/main/shell_get_opts.c index b953af05..d1e370ba 100644 --- a/42sh/src/main/shell_get_opts.c +++ b/42sh/src/main/shell_get_opts.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */ -/* Updated: 2017/01/23 23:36:11 by ariard ### ########.fr */ +/* Updated: 2017/01/30 18:11:18 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c index c13c1b66..8b3631eb 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/30 17:15:37 by ariard ### ########.fr */ +/* Updated: 2017/01/30 19:00:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,7 +40,6 @@ int shell_script() btree_print(STDBUG, *ast2, &ft_putast); tmp2 = tmp2->next; } - return (0); while (list_ast) { if (ft_exec((t_btree **)list_ast->content)) diff --git a/42sh/src/parser/.ft_parse.c.swn b/42sh/src/parser/.ft_parse.c.swn deleted file mode 100644 index 4839274b..00000000 Binary files a/42sh/src/parser/.ft_parse.c.swn and /dev/null differ diff --git a/42sh/src/parser/parse_list.c b/42sh/src/parser/parse_list.c index 6b216e5a..d9f861bb 100644 --- a/42sh/src/parser/parse_list.c +++ b/42sh/src/parser/parse_list.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 16:34:21 by ariard #+# #+# */ -/* Updated: 2017/01/30 17:22:54 by ariard ### ########.fr */ +/* Updated: 2017/01/30 18:48:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ int parse_list(t_list **list_ast, t_btree **ast, token = (*lst)->content; node = (*ast)->item; node->type = TK_LIST; - node->data.sstr = ft_sstradd(node->data.sstr, token->data); + node->data.str = ft_strdup(token->data); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); return (0); } diff --git a/42sh/src/parser/parse_word.c b/42sh/src/parser/parse_word.c index 2de64573..f8f537d7 100644 --- a/42sh/src/parser/parse_word.c +++ b/42sh/src/parser/parse_word.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2017/01/30 16:45:53 by ariard ### ########.fr */ +/* Updated: 2017/01/30 18:37:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */