diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index ec98c235..75cfab31 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/22 00:37:19 by ariard ### ########.fr */ +/* Updated: 2017/01/22 23:30:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index e0a4a1f4..0e5c6b2b 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/22 22:50:22 by ariard ### ########.fr */ +/* Updated: 2017/01/22 23:21:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -73,6 +73,8 @@ void data_exit(void); int shell_single_command(char *command); +int shell_script(void); + void ft_expand_dollar(char **av, char **env); char *ft_findexec(char *path, char *file); diff --git a/42sh/includes/readscript.h b/42sh/includes/readscript.h index d12f2cc3..29c91132 100644 --- a/42sh/includes/readscript.h +++ b/42sh/includes/readscript.h @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/21 22:50:22 by ariard #+# #+# */ -/* Updated: 2017/01/22 22:19:32 by ariard ### ########.fr */ +/* Updated: 2017/01/22 23:02:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/script.sh b/42sh/script.sh index 4065c7cb..35caedf2 100755 --- a/42sh/script.sh +++ b/42sh/script.sh @@ -1,4 +1,5 @@ -#!/bin/yolosh +#!/bin/minishell + while [ 1 ]; do sleep 1 echo "a" diff --git a/42sh/src/read-script/.rs_shebang.c.swp b/42sh/src/lexer/.ft_post_tokenize.c.swo similarity index 71% rename from 42sh/src/read-script/.rs_shebang.c.swp rename to 42sh/src/lexer/.ft_post_tokenize.c.swo index 7e751dc1..f9f7efee 100644 Binary files a/42sh/src/read-script/.rs_shebang.c.swp and b/42sh/src/lexer/.ft_post_tokenize.c.swo differ diff --git a/42sh/src/read-script/.ft_read_script.c.swp b/42sh/src/lexer/.ft_tokenize.c.swo similarity index 81% rename from 42sh/src/read-script/.ft_read_script.c.swp rename to 42sh/src/lexer/.ft_tokenize.c.swo index 48f63c7a..c523a788 100644 Binary files a/42sh/src/read-script/.ft_read_script.c.swp and b/42sh/src/lexer/.ft_tokenize.c.swo differ diff --git a/42sh/includes/.readscript.h.swp b/42sh/src/lexer/.reduce_bquotes.c.swo similarity index 86% rename from 42sh/includes/.readscript.h.swp rename to 42sh/src/lexer/.reduce_bquotes.c.swo index 747c167a..20161d54 100644 Binary files a/42sh/includes/.readscript.h.swp and b/42sh/src/lexer/.reduce_bquotes.c.swo differ diff --git a/42sh/src/lexer/ft_post_tokenize.c b/42sh/src/lexer/ft_post_tokenize.c index 23367fcf..a69df251 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/20 16:37:25 by ariard ### ########.fr */ +/* Updated: 2017/01/22 23:27:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/ft_tokenize.c b/42sh/src/lexer/ft_tokenize.c index a75170dc..1e5af252 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/21 20:49:42 by ariard ### ########.fr */ +/* Updated: 2017/01/22 23:18:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/reduce_bquotes.c b/42sh/src/lexer/reduce_bquotes.c index 6057e8c0..cb70ee1c 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/20 01:14:32 by ariard ### ########.fr */ +/* Updated: 2017/01/22 23:26:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_readline.c b/42sh/src/line-editing/ft_readline.c index 90f36e9e..2570d0f3 100644 --- a/42sh/src/line-editing/ft_readline.c +++ b/42sh/src/line-editing/ft_readline.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 18:03:48 by sbenning #+# #+# */ -/* Updated: 2017/01/22 21:43:48 by ariard ### ########.fr */ +/* Updated: 2017/01/22 23:15:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/.main.c.swo b/42sh/src/main/.main.c.swo index 2ec104e9..5c8f87b2 100644 Binary files a/42sh/src/main/.main.c.swo and b/42sh/src/main/.main.c.swo differ diff --git a/42sh/src/main/.shell_script.c.swp b/42sh/src/main/.shell_script.c.swp new file mode 100644 index 00000000..f9ac3d8f Binary files /dev/null and b/42sh/src/main/.shell_script.c.swp differ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index e64ce801..6aceeb75 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/22 22:52:41 by ariard ### ########.fr */ +/* Updated: 2017/01/22 23:09:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,6 +37,7 @@ int shell_single_command(char *command) /* /1* btree_apply_infix(ast, &ft_putast2); *1/ */ if (ft_exec(&ast)) return (1); + return (0); } @@ -51,7 +52,10 @@ int main(int ac, char **av) } if (ft_read_script(av[1])) { - shell_single_command(data_singleton()->line.input); + if (data_singleton()->opts & SHELL_MODE_SCRIPT) + shell_script(); + else + shell_single_command(data_singleton()->line.input); return (0); } while (1) diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c new file mode 100644 index 00000000..6b680e90 --- /dev/null +++ b/42sh/src/main/shell_script.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* shell_script.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */ +/* Updated: 2017/01/22 23:32:27 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int shell_script() +{ + t_list *token; + t_btree *ast; + t_list *tmp; + + token = NULL; + ast = NULL; + tmp = data_singleton()->script.queue; + while (tmp) + { + if (ft_tokenize(&token, tmp->content , DEFAULT)) + return (1); + tmp = tmp->next; + } + if (!token) + return (0); +// if (ft_post_tokenize(&token, command)) +// return (1); + DG("after post_tokenize"); + token_print(token); + if (ft_parse(&ast, &token)) + return (1); + btree_print(STDBUG, ast, &ft_putast); + if (ft_exec(&ast)) + return (1); + return (0); +} diff --git a/42sh/src/read-script/ft_read_script.c b/42sh/src/read-script/ft_read_script.c index 92a11f9d..6e1a9e8f 100644 --- a/42sh/src/read-script/ft_read_script.c +++ b/42sh/src/read-script/ft_read_script.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/21 22:49:31 by ariard #+# #+# */ -/* Updated: 2017/01/22 22:19:42 by ariard ### ########.fr */ +/* Updated: 2017/01/22 23:11:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/read-script/rs_shebang.c b/42sh/src/read-script/rs_shebang.c index 090cb834..bc1550f8 100644 --- a/42sh/src/read-script/rs_shebang.c +++ b/42sh/src/read-script/rs_shebang.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/22 21:42:27 by ariard #+# #+# */ -/* Updated: 2017/01/22 22:53:34 by ariard ### ########.fr */ +/* Updated: 2017/01/22 23:11:57 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,7 +72,7 @@ int rs_shebang_check(char *file, t_script *script) else if (ft_strncmp(interpreter, "minishell", ft_strlen("minishell")) == 0) { data_singleton()->opts &= ~SHELL_MODE_MASK; - data_singleton()->opts |= SHELL_MODE_EXEC; + data_singleton()->opts |= SHELL_MODE_SCRIPT; } return (0); }