From 0dc029406f82269d9e90f753c473a15bde676d01 Mon Sep 17 00:00:00 2001 From: "ariard@student.42.fr" Date: Mon, 30 Jan 2017 23:47:05 +0100 Subject: [PATCH] exec while ok nxt: resoudre bug empty tree --- 42sh/file2 | 1 + 42sh/file3 | 0 42sh/includes/exec.h | 5 ++++- 42sh/includes/lexer.h | 2 +- 42sh/includes/minishell.h | 4 ++-- 42sh/sample/while.sh | 8 +++++--- 42sh/src/exec/exec_ampersand.c | 9 +++++++-- 42sh/src/exec/exec_and_if.c | 10 +++++++--- 42sh/src/exec/exec_command.c | 6 ++++-- 42sh/src/exec/exec_dgreat.c | 8 ++++++-- 42sh/src/exec/exec_great.c | 8 ++++++-- 42sh/src/exec/exec_less.c | 8 ++++++-- 42sh/src/exec/exec_list.c | 23 +++++++++++++++++++++++ 42sh/src/exec/exec_or_if.c | 8 ++++++-- 42sh/src/exec/exec_pipe.c | 6 ++++-- 42sh/src/exec/exec_semi.c | 9 +++++++-- 42sh/src/exec/exec_while.c | 24 ++++++++++++++++-------- 42sh/src/exec/ft_exec.c | 5 ++++- 42sh/src/exec/launch_process.c | 2 +- 42sh/src/exec/loop_exec.c | 27 +++++++++++++++++++++++++++ 42sh/src/exec/set_exitstatus.c | 2 +- 42sh/src/lexer/lexer_list.c | 7 +++++-- 42sh/src/lexer/lexer_word.c | 2 +- 42sh/src/main/ft_print_all_ast.c | 2 +- 42sh/src/main/main.c | 2 +- 42sh/src/main/read_script.c | 2 +- 42sh/src/main/shell_get_ast.c | 13 ++++++------- 42sh/src/main/shell_get_opts.c | 2 +- 42sh/src/main/shell_script.c | 5 +++-- 42sh/src/parser/parse_list.c | 4 ++-- 42sh/src/parser/parse_newline.c | 3 +-- 42sh/src/parser/parse_separator.c | 3 +-- 42sh/src/parser/parse_while.c | 2 +- 33 files changed, 162 insertions(+), 60 deletions(-) create mode 100644 42sh/file2 create mode 100644 42sh/file3 create mode 100644 42sh/src/exec/exec_list.c create mode 100644 42sh/src/exec/loop_exec.c diff --git a/42sh/file2 b/42sh/file2 new file mode 100644 index 00000000..ce09b016 --- /dev/null +++ b/42sh/file2 @@ -0,0 +1 @@ +/Users/ariard/Projects/42sh diff --git a/42sh/file3 b/42sh/file3 new file mode 100644 index 00000000..e69de29b diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index fda62039..3791999c 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/30 18:57:16 by ariard ### ########.fr */ +/* Updated: 2017/01/30 22:32:57 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,6 +85,7 @@ int exec_dgreat(t_btree **ast); int exec_command(t_btree **ast); int exec_while(t_btree **ast); +int exec_list(t_btree **ast); int launch_process(t_process *p); int process_setexec(t_type type, t_process *p); @@ -102,4 +103,6 @@ void set_exitstatus(int status); void ast_free(void *data, size_t content_size); +int loop_exec(t_list *list_ast); + #endif diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index f1928bfa..eb3ba0e9 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 18:05:43 by ariard ### ########.fr */ +/* Updated: 2017/01/30 23:41:17 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 3dc119e6..bd86829c 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/30 19:23:44 by ariard ### ########.fr */ +/* Updated: 2017/01/30 23:10:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,7 +81,7 @@ int shell_single_command(char *command); int read_script(char *file); int shell_script(void); -t_list *shell_get_ast(char *command); +t_list **shell_get_ast(char *command); void ft_expand_dollar(char **av, char **env); char *ft_findexec(char *path, char *file); diff --git a/42sh/sample/while.sh b/42sh/sample/while.sh index 8a88a4d1..84f20c5e 100644 --- a/42sh/sample/while.sh +++ b/42sh/sample/while.sh @@ -1,3 +1,5 @@ -while echo bonjour toi > file1 ; do - echo hello world > file2 -done +echo "begin script" +while [ 1 ] +do sleep 1 ; echo "hello 42sh" +done +echo "end script" diff --git a/42sh/src/exec/exec_ampersand.c b/42sh/src/exec/exec_ampersand.c index a3ab0fa9..0a0c7a0b 100644 --- a/42sh/src/exec/exec_ampersand.c +++ b/42sh/src/exec/exec_ampersand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */ -/* Updated: 2017/01/22 22:08:34 by ariard ### ########.fr */ +/* Updated: 2017/01/30 21:11:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,17 @@ int exec_ampersand(t_btree **ast) { + t_process *p; + if (SHELL_HAS_JOBC(data_singleton()->opts)) data_singleton()->exec.job.attributes |= JOB_BG; ft_exec(&(*ast)->left); if (SHELL_HAS_JOBC(data_singleton()->opts)) data_singleton()->exec.job.attributes &= ~JOB_BG; ft_exec(&(*ast)->right); - btree_delone(ast, &ast_free); + + p = &data_singleton()->exec.process; + if (!(p->script & SCRIPT_LOOP)) + btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_and_if.c b/42sh/src/exec/exec_and_if.c index 0728310d..4b26c5d4 100644 --- a/42sh/src/exec/exec_and_if.c +++ b/42sh/src/exec/exec_and_if.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */ -/* Updated: 2016/12/12 18:01:06 by jhalford ### ########.fr */ +/* Updated: 2017/01/30 20:53:56 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,8 @@ int exec_and_if(t_btree **ast) { - t_data *data; + t_data *data; + t_process *p; data = data_singleton(); if (data->exec.aol_status == NULL @@ -32,6 +33,9 @@ int exec_and_if(t_btree **ast) ft_exec(&(*ast)->right); data->exec.aol_status = NULL; data->exec.aol_search = 0; - btree_delone(ast, &ast_free); + + p = &data_singleton()->exec.process; + if (!(p->script & SCRIPT_LOOP)) + btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index 344bded5..5a47ff90 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 18:29:22 by ariard ### ########.fr */ +/* Updated: 2017/01/30 23:25:44 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,6 +37,8 @@ int exec_command(t_btree **ast) p->av = NULL; p->pid = 0; p->attributes = PROCESS_PIPESTART | PROCESS_PIPEEND; - btree_delone(ast, &ast_free); + + if (!(p->script & SCRIPT_LOOP)) + btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_dgreat.c b/42sh/src/exec/exec_dgreat.c index 9897f54d..ad73e6b6 100644 --- a/42sh/src/exec/exec_dgreat.c +++ b/42sh/src/exec/exec_dgreat.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:15:13 by jhalford #+# #+# */ -/* Updated: 2016/12/13 17:13:58 by jhalford ### ########.fr */ +/* Updated: 2017/01/30 20:55:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ int exec_dgreat(t_btree **ast) { t_astnode *node; + t_process *p; int fd; node = (*ast)->item; @@ -22,6 +23,9 @@ int exec_dgreat(t_btree **ast) data_singleton()->exec.process.fdout = fd; ft_exec(&(*ast)->left); data_singleton()->exec.process.fdout = STDOUT; - btree_delone(ast, &ast_free); + + p = &data_singleton()->exec.process; + if (!(p->script & SCRIPT_LOOP)) + btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_great.c b/42sh/src/exec/exec_great.c index 6b410e7b..f4399234 100644 --- a/42sh/src/exec/exec_great.c +++ b/42sh/src/exec/exec_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:27:51 by jhalford #+# #+# */ -/* Updated: 2016/12/13 17:14:19 by jhalford ### ########.fr */ +/* Updated: 2017/01/30 21:09:36 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ int exec_great(t_btree **ast) { t_astnode *node; + t_process *p; int fd; node = (*ast)->item; @@ -22,6 +23,9 @@ int exec_great(t_btree **ast) data_singleton()->exec.process.fdout = fd; ft_exec(&(*ast)->left); data_singleton()->exec.process.fdout = STDOUT; - btree_delone(ast, &ast_free); + + p = &data_singleton()->exec.process; + if (!(p->script & SCRIPT_LOOP)) + btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_less.c b/42sh/src/exec/exec_less.c index f27be538..4c0d226d 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: 2016/12/13 17:14:46 by jhalford ### ########.fr */ +/* Updated: 2017/01/30 20:56:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ int exec_less(t_btree **ast) { t_astnode *node; + t_process *p; int fd; node = (*ast)->item; @@ -25,6 +26,9 @@ int exec_less(t_btree **ast) ft_exec(&(*ast)->left); data_singleton()->exec.process.fdin = STDIN; /* data->exec.process.command = NULL; */ - btree_delone(ast, &ast_free); + + p = &data_singleton()->exec.process; + if (!(p->script & SCRIPT_LOOP)) + btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_list.c b/42sh/src/exec/exec_list.c new file mode 100644 index 00000000..aab8b1ce --- /dev/null +++ b/42sh/src/exec/exec_list.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* exec_list.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/30 20:19:29 by ariard #+# #+# */ +/* Updated: 2017/01/30 20:57:51 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "exec.h" + +int exec_list(t_btree **ast) +{ + t_process *p; + + p = &data_singleton()->exec.process; + if (!(p->script & SCRIPT_LOOP)) + btree_delone(ast, &ast_free); + return (0); +} diff --git a/42sh/src/exec/exec_or_if.c b/42sh/src/exec/exec_or_if.c index 6b18060c..c7abb167 100644 --- a/42sh/src/exec/exec_or_if.c +++ b/42sh/src/exec/exec_or_if.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */ -/* Updated: 2017/01/02 18:10:21 by jhalford ### ########.fr */ +/* Updated: 2017/01/30 21:09:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ int exec_or_if(t_btree **ast) { t_data *data; + t_process *p; data = data_singleton(); if (data->exec.aol_status == NULL @@ -32,6 +33,9 @@ int exec_or_if(t_btree **ast) ft_exec(&(*ast)->right); data->exec.aol_status = NULL; data->exec.aol_search = 0; - btree_delone(ast, &ast_free); + + p = &data_singleton()->exec.process; + if (!(p->script & SCRIPT_LOOP)) + btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_pipe.c b/42sh/src/exec/exec_pipe.c index ffb3e2fd..d11fc8f1 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/30 17:32:39 by ariard ### ########.fr */ +/* Updated: 2017/01/30 21:01:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,6 +41,8 @@ int exec_pipe(t_btree **ast) close(fds[PIPE_READ]); p->fdin = STDIN; - btree_delone(ast, &ast_free); + + if (!(p->script & SCRIPT_LOOP)) + btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_semi.c b/42sh/src/exec/exec_semi.c index dfc164f9..2ab2b3d2 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: 2017/01/30 17:34:07 by ariard ### ########.fr */ +/* Updated: 2017/01/30 23:25:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,13 @@ int exec_semi(t_btree **ast) { + t_process *p; + ft_exec(&(*ast)->left); ft_exec(&(*ast)->right); - btree_delone(ast, &ast_free); + + p = &data_singleton()->exec.process; + if (!(p->script & SCRIPT_LOOP)) + btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_while.c b/42sh/src/exec/exec_while.c index 2bfb44b6..d6aa3e24 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/30 19:30:16 by ariard ### ########.fr */ +/* Updated: 2017/01/30 23:41:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,25 +14,33 @@ int exec_while(t_btree **ast) { - t_list *test_commands; - t_list *consequent_commands; + 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); +// ft_print_all_ast(*test_commands); 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; + p->script |= SCRIPT_LOOP; -// while (ft_test(test_commands)) -// ft_exec(consequent_commands) +// ft_print_all_ast(consequent_commands); + + test = 10; + while (test--) + loop_exec(*consequent_commands); // del tree (test_commands); // del tree (test_commands); - btree_delone(ast, &ast_free); + p->script &= 0; + + btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index ba452953..16bd6e16 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/30 17:33:34 by ariard ### ########.fr */ +/* Updated: 2017/01/30 23:15:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ t_execmap g_execmap[] = {TK_GREAT, &exec_great}, {TK_DGREAT, &exec_dgreat}, {TK_WHILE, &exec_while}, + {TK_LIST, &exec_list}, {TK_COMMAND | TK_SUBSHELL, &exec_command}, {0, 0}, }; @@ -39,8 +40,10 @@ int ft_exec(t_btree **ast) while (g_execmap[i].type) { if (item->type & g_execmap[i].type) + { /* return ((*g_execmap[i].f)(ast)); */ (*g_execmap[i].f)(ast); + } i++; } return (0); diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 172a37ab..5fd4472d 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/30 18:30:31 by ariard ### ########.fr */ +/* Updated: 2017/01/30 19:36:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/loop_exec.c b/42sh/src/exec/loop_exec.c new file mode 100644 index 00000000..c33f48be --- /dev/null +++ b/42sh/src/exec/loop_exec.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* loop_exec.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/30 21:02:10 by ariard #+# #+# */ +/* Updated: 2017/01/30 23:17:24 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "exec.h" + +int loop_exec(t_list *list_ast) +{ + +// DG("begin exec loop"); +// ft_print_all_ast(*list_ast); + while (list_ast) + { + if (ft_exec((t_btree **)list_ast->content)) + return (1); + list_ast = list_ast->next; + } + return (0); +} diff --git a/42sh/src/exec/set_exitstatus.c b/42sh/src/exec/set_exitstatus.c index 584abdcc..0a82731d 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/01/08 15:58:20 by jhalford ### ########.fr */ +/* Updated: 2017/01/30 21:05:42 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_list.c b/42sh/src/lexer/lexer_list.c index 33754baa..3fe84e51 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/26 19:24:50 by ariard ### ########.fr */ +/* Updated: 2017/01/30 23:14:45 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ int lexer_list(t_list **alst, char *str) { t_token *token; + char lim; token = (*alst)->content; token->type = TK_LIST; @@ -22,12 +23,14 @@ int lexer_list(t_list **alst, char *str) { if (ft_is_delim_list(*str)) { - str++; + lim = *str++; while (ft_is_delim(*str) || *str == '\n') str++; if (ft_strncmp(str, "done", 4) == 0 || ft_strncmp(str, "do", 2) == 0) return (ft_tokenize(alst, str, DO_GROUP)); + else + token_append(token, lim); } token_append(token, *str++); } diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index 9f2fab64..3221534b 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/27 12:51:00 by ariard ### ########.fr */ +/* Updated: 2017/01/30 23:17:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/ft_print_all_ast.c b/42sh/src/main/ft_print_all_ast.c index b07ea34f..84d2ada8 100644 --- a/42sh/src/main/ft_print_all_ast.c +++ b/42sh/src/main/ft_print_all_ast.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 19:23:49 by ariard #+# #+# */ -/* Updated: 2017/01/30 19:26:42 by ariard ### ########.fr */ +/* Updated: 2017/01/30 22:11:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 445aaece..7cbf39ee 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/30 18:59:13 by ariard ### ########.fr */ +/* Updated: 2017/01/30 20:45:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/read_script.c b/42sh/src/main/read_script.c index 8b8c8230..04f03a1a 100644 --- a/42sh/src/main/read_script.c +++ b/42sh/src/main/read_script.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/21 22:49:31 by ariard #+# #+# */ -/* Updated: 2017/01/26 17:52:25 by ariard ### ########.fr */ +/* Updated: 2017/01/30 20:32:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_get_ast.c b/42sh/src/main/shell_get_ast.c index 40784a5f..7005119a 100644 --- a/42sh/src/main/shell_get_ast.c +++ b/42sh/src/main/shell_get_ast.c @@ -6,21 +6,21 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 18:19:13 by ariard #+# #+# */ -/* Updated: 2017/01/30 19:28:19 by ariard ### ########.fr */ +/* Updated: 2017/01/30 23:14:32 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -t_list *shell_get_ast(char *command) +t_list **shell_get_ast(char *command) { t_list *token; t_btree *ast; - t_list *list_ast; + t_list **list_ast; token = NULL; ast = NULL; - list_ast = NULL; + list_ast = ft_memalloc(sizeof(*list_ast)); if (ft_tokenize(&token, command, DEFAULT)) return (NULL); if (!token) @@ -29,8 +29,7 @@ t_list *shell_get_ast(char *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); + if (ft_parse(list_ast, &ast, &token)) + return (NULL); return (list_ast); } diff --git a/42sh/src/main/shell_get_opts.c b/42sh/src/main/shell_get_opts.c index d1e370ba..cd56439a 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/30 18:11:18 by ariard ### ########.fr */ +/* Updated: 2017/01/30 20:29:48 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c index 8b3631eb..e525e758 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 19:00:50 by ariard ### ########.fr */ +/* Updated: 2017/01/30 23:13:44 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,11 +40,12 @@ int shell_script() btree_print(STDBUG, *ast2, &ft_putast); tmp2 = tmp2->next; } - while (list_ast) +/* while (list_ast) { if (ft_exec((t_btree **)list_ast->content)) return (1); list_ast = list_ast->next; } +*/ loop_exec(list_ast); return (0); } diff --git a/42sh/src/parser/parse_list.c b/42sh/src/parser/parse_list.c index d9f861bb..f55d8336 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 18:48:24 by ariard ### ########.fr */ +/* Updated: 2017/01/30 23:38:15 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.str = ft_strdup(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_newline.c b/42sh/src/parser/parse_newline.c index 0cf3888d..f4129f9e 100644 --- a/42sh/src/parser/parse_newline.c +++ b/42sh/src/parser/parse_newline.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 19:26:41 by ariard #+# #+# */ -/* Updated: 2017/01/30 17:14:05 by ariard ### ########.fr */ +/* Updated: 2017/01/30 20:02:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,6 @@ int parse_newline(t_list **list_ast, t_btree **ast, { t_list *temp; - DG("parsing newline"); temp = (*lst)->next; (*lst)->next = NULL; ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); diff --git a/42sh/src/parser/parse_separator.c b/42sh/src/parser/parse_separator.c index 4453a4ff..cf7c911b 100644 --- a/42sh/src/parser/parse_separator.c +++ b/42sh/src/parser/parse_separator.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */ -/* Updated: 2017/01/30 17:11:05 by ariard ### ########.fr */ +/* Updated: 2017/01/30 20:25:22 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ int parse_separator(t_list **list_ast, t_btree **ast, t_token *token; t_astnode *node; - DG("parsing separator"); token = (*lst)->content; node = (*ast)->item; node->type = token->type; diff --git a/42sh/src/parser/parse_while.c b/42sh/src/parser/parse_while.c index 58af9101..da3e5f6b 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 17:22:36 by ariard ### ########.fr */ +/* Updated: 2017/01/30 19:52:17 by ariard ### ########.fr */ /* */ /* ************************************************************************** */