From 60f150a4b459583e4fa8d76b20d61d2f56976925 Mon Sep 17 00:00:00 2001 From: wescande Date: Sun, 19 Mar 2017 17:45:29 +0100 Subject: [PATCH] modif env, modif command get ouput, modif hash (just a str is needed) --- 42sh/Makefile | 2 + 42sh/includes/hash.h | 8 ++-- 42sh/includes/lexer.h | 5 ++- 42sh/includes/parser.h | 1 + 42sh/src/builtin/builtin_env.c | 4 +- 42sh/src/exec/process_set.c | 4 +- 42sh/src/exec/process_setgroup.c | 4 +- 42sh/src/exec/pset_cmd.c | 6 +-- 42sh/src/glob/command_getoutput.c | 70 +++++++++++++++++++++-------- 42sh/src/glob/expand_bquote.c | 19 ++++++-- 42sh/src/hash_table/ft_add_hash.c | 15 +++---- 42sh/src/hash_table/hash.c | 13 +++--- 42sh/src/hash_table/is_hash.c | 15 +++---- 42sh/src/lexer/do_lexer_routine.c | 36 +++++++++++++++ 42sh/src/main/data_init.c | 10 ++--- 42sh/src/main/main.c | 48 -------------------- 42sh/src/main/shell_init.c | 5 ++- 42sh/src/parser/do_parser_routine.c | 38 ++++++++++++++++ 18 files changed, 189 insertions(+), 114 deletions(-) create mode 100644 42sh/src/lexer/do_lexer_routine.c create mode 100644 42sh/src/parser/do_parser_routine.c diff --git a/42sh/Makefile b/42sh/Makefile index 8d15f1b5..68378b27 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -209,6 +209,7 @@ job_control/sigint_handler.c\ job_control/sigtstp_handler.c\ job_control/sigttin_handler.c\ job_control/sigttou_handler.c\ +lexer/do_lexer_routine.c\ lexer/get_lexer_stack.c\ lexer/get_reserved_words.c\ lexer/get_state_global.c\ @@ -279,6 +280,7 @@ parser/add_sep.c\ parser/add_subshell.c\ parser/aggregate_sym.c\ parser/build_tree.c\ +parser/do_parser_routine.c\ parser/error_syntax.c\ parser/eval_sym.c\ parser/ft_parse.c\ diff --git a/42sh/includes/hash.h b/42sh/includes/hash.h index bafc47db..e9a27aac 100644 --- a/42sh/includes/hash.h +++ b/42sh/includes/hash.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 11:10:14 by gwojda #+# #+# */ -/* Updated: 2017/03/15 18:54:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/19 16:37:44 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,9 +23,9 @@ typedef struct s_hash char *path; } t_hash; -int ft_add_hash(t_process *p); -int ft_hash(t_process *p); -int ft_is_hash(t_process *p); +char *ft_add_hash(char *cmd); +char *ft_hash(char *cmd); +char *ft_is_hash(char *cmd); int ft_hash_str(char *str); void ft_hash_free(void *ptr, size_t size); diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 3ba66acd..a0bc1ed1 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/03/18 02:58:19 by wescande ### ########.fr */ +/* Updated: 2017/03/19 17:13:05 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -82,7 +82,7 @@ void token_print(t_list *lst); int reduce_parens(t_list **alst, char *str); int bquotes_expand(t_list **alst); -char *command_getoutput(char *command, char *const av_cmd[], char **env); +char *command_getoutput(char *command, char *const av[], char **env, int pipe_mode); int ft_is_delim(char c); int ft_is_delim_list(char c); @@ -94,6 +94,7 @@ int get_lexer_stack(t_lexer lexer); int get_reserved_words(t_list *temp); int insert_newline(t_list **alst); +int do_lexer_routine(t_list **token, char *stream); void lexer_init(t_lexer *lexer); void lexer_destroy(t_lexer *lexer); int lexer_lex(t_list **alst, t_lexer *lexer); diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 7fbb200e..6bd7ac30 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -60,6 +60,7 @@ struct s_errormatch char *error; }; +int do_parser_routine(t_list **token, t_btree **ast); void parser_init(t_parser *parser); void parser_destroy(t_parser *parser); int stack_init(t_parser *parser); diff --git a/42sh/src/builtin/builtin_env.c b/42sh/src/builtin/builtin_env.c index da65d981..b6fc4c3b 100644 --- a/42sh/src/builtin/builtin_env.c +++ b/42sh/src/builtin/builtin_env.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */ -/* Updated: 2017/03/18 04:13:57 by wescande ### ########.fr */ +/* Updated: 2017/03/19 17:43:24 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -106,7 +106,7 @@ int builtin_env(const char *path, char *const argv[], char *const envp[]) ft_putchar('\n'); } else - ft_putstr(command_getoutput(NULL, argv, env)); + command_getoutput(NULL, argv, env, 0); ft_tabdel(&env); return (0); } diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index d1f6980d..fb6c739b 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/16 21:42:38 by jhalford ### ########.fr */ +/* Updated: 2017/03/19 16:00:16 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,6 +67,8 @@ int process_set(t_process *p, t_btree *ast) p->to_close = fds[PIPE_READ]; p->fdout = fds[PIPE_WRITE]; exec->fdin = fds[PIPE_READ]; + if (!ast) + return (0); p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, &redir_copy); return (process_set_spec(p, ast)); } diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index 08b822e9..b5424a8f 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ -/* Updated: 2017/03/18 00:23:57 by wescande ### ########.fr */ +/* Updated: 2017/03/19 14:04:57 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ int process_setgroup(t_process *p, pid_t pid) if (setpgid(pid, j->pgid) == -1) ft_dprintf(2, "{red}%s: internal setpgid() errno=%i{eoc}\n", SHELL_NAME, errno); /* if (JOB_IS_FG(j->attrs)) */ - if (pid ==0 && JOB_IS_FG(j->attrs)) + if (pid == 0 && JOB_IS_FG(j->attrs)) { DG("tcsetpgrp[%i]", j->pgid); tcsetpgrp(STDIN, j->pgid); diff --git a/42sh/src/exec/pset_cmd.c b/42sh/src/exec/pset_cmd.c index 43153bb5..8f09fecb 100644 --- a/42sh/src/exec/pset_cmd.c +++ b/42sh/src/exec/pset_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ -/* Updated: 2017/03/15 18:48:13 by ariard ### ########.fr */ +/* Updated: 2017/03/19 16:42:10 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ int pset_cmd(t_process *p, t_btree *ast) { t_btree *func; - if (!(p->data.cmd.av = token_to_argv(((t_astnode *)ast->item)->data.cmd.token, 1))) + if (ast && !(p->data.cmd.av = token_to_argv(((t_astnode *)ast->item)->data.cmd.token, 1))) { p->type = PROCESS_EMPTY; return (0); @@ -40,7 +40,7 @@ int pset_cmd(t_process *p, t_btree *ast) if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) ft_memdel((void**)&p->data.cmd.stat); } - else if (ft_hash(p)) + else if ((p->data.cmd.path = ft_hash(p->data.cmd.av[0]))) { p->data.cmd.execf = &execve; if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) diff --git a/42sh/src/glob/command_getoutput.c b/42sh/src/glob/command_getoutput.c index d3fcbcdb..7a3f387f 100644 --- a/42sh/src/glob/command_getoutput.c +++ b/42sh/src/glob/command_getoutput.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 19:44:25 by wescande #+# #+# */ -/* Updated: 2017/03/18 04:11:20 by wescande ### ########.fr */ +/* Updated: 2017/03/19 17:42:45 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,35 +38,67 @@ static char *manage_command(char *const av_cmd[]) if (!av_cmd) return (NULL); i = -1; - command = ft_strdup(av_cmd[++i]); + command = NULL; while (av_cmd[++i]) - ft_strjoin(command, av_cmd[i]); + { + if (!command) + command = ft_str3join("\"", av_cmd[i], "\""); + else + command = ft_strjoinf(command, ft_str3join("\"", av_cmd[i], "\""), 3); + } return (command); } -char *command_getoutput(char *command, char *const av_cmd[], char **env) +static void execute_command(char *command, char *const av[], char **env) +{ + t_list *token; + t_btree *ast; + t_data *data; + + token = NULL; + ast = NULL; + data = data_singleton(); + data->env = env; + data->opts &= ~SH_INTERACTIVE; + data->opts &= ~SH_OPTS_JOBC; + command = command ? command : manage_command(av); + DG("command is %s", command); + if (do_lexer_routine(&token, command)) + { + ft_dprintf(2, "{red}%s: syntax error in command substitution{eoc}\n", + SHELL_NAME); + exit(1); + } + if (do_parser_routine(&token, &ast) <= 0) + { + ft_dprintf(2, "{red}%s: parse error in command substitution{eoc}\n", + SHELL_NAME); + exit(1); + } + exit(data_singleton()->parser.state == SUCCESS && ft_exec(&ast) < 0); +} + +char *command_getoutput(char *command, char *const av[], char **env, int pipe_mode) { - char *output; int ret; int pid; int fds[2]; - char **av; - pipe(fds); + if (!command && !av) + return (NULL); + if (pipe_mode) + pipe(fds); if (!(pid = fork())) { - close(fds[PIPE_READ]); - dup2_close(fds[PIPE_WRITE], STDOUT); - av = ft_sstradd(NULL, data_singleton()->argv[0]); - av = ft_sstradd(av, "-c"); - if (!(command = command ? command : manage_command(av_cmd))) - exit(1); - DG("command is %s", command); - av = ft_sstradd(av, command); - execve(data_singleton()->argv[0], av, env); - exit(1); + if (pipe_mode) + { + close(fds[PIPE_READ]); + dup2_close(fds[PIPE_WRITE], STDOUT); + } + execute_command(command, av, env); } waitpid(pid, &ret, WUNTRACED); - output = manage_output(fds); - return (output); + if (pipe_mode) + return (manage_output(fds)); + return (NULL); } diff --git a/42sh/src/glob/expand_bquote.c b/42sh/src/glob/expand_bquote.c index 9b74930d..5a97fcb4 100644 --- a/42sh/src/glob/expand_bquote.c +++ b/42sh/src/glob/expand_bquote.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 17:47:53 by wescande #+# #+# */ -/* Updated: 2017/03/18 02:59:06 by wescande ### ########.fr */ +/* Updated: 2017/03/19 17:33:11 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,7 +72,7 @@ static char *get_output(char *command) char *output; int len; - if (!(output = command_getoutput(command, NULL, data_singleton()->env))) + if (!(output = command_getoutput(command, NULL, data_singleton()->env, 1))) return (NULL); len = ft_strlen(output); while (output[--len] == '\n') @@ -80,6 +80,18 @@ static char *get_output(char *command) return (output); } +static char *treat_str(t_bquote *me, char *sta) +{ + if (sta && *me->str == '\n' + && !is_char_esc(me->esc, CH(*me->wk)[0], me->str)) + *me->str = ';'; + if (sta && *me->str == '\n' + && is_char_esc(me->esc, CH(*me->wk)[0], me->str)) + *me->str = ' '; + return (*me->str == '`' && !sta + && !is_char_esc(me->esc2, CH(*me->wk)[0], me->str) ? me->str : sta); +} + static int search_bquote(t_bquote *me) { char *sta; @@ -88,8 +100,7 @@ static int search_bquote(t_bquote *me) sta = NULL; while (*(++me->str)) { - sta = *me->str == '`' && !sta - && !is_char_esc(me->esc2, CH(*me->wk)[0], me->str) ? me->str : sta; + sta = treat_str(me, sta); if (sta && *me->str == '`' && me->str != sta && !is_char_esc(me->esc2, CH(*me->wk)[0], me->str)) { diff --git a/42sh/src/hash_table/ft_add_hash.c b/42sh/src/hash_table/ft_add_hash.c index b347f82a..4c4781d5 100644 --- a/42sh/src/hash_table/ft_add_hash.c +++ b/42sh/src/hash_table/ft_add_hash.c @@ -6,23 +6,22 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 11:20:11 by gwojda #+# #+# */ -/* Updated: 2017/03/16 10:39:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/19 16:40:25 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int ft_add_hash(t_process *p) +char *ft_add_hash(char *cmd) { int id; t_hash hash; if (!(hash.path = ft_findexec(ft_getenv( - data_singleton()->env, "PATH"), p->data.cmd.av[0]))) - return (0); - hash.key = ft_strdup(p->data.cmd.av[0]); - id = ft_hash_str(p->data.cmd.av[0]); + data_singleton()->env, "PATH"), cmd))) + return (NULL); + hash.key = ft_strdup(cmd); + id = ft_hash_str(cmd); ft_lsteadd(&(g_hash[id]), ft_lstnew(&hash, sizeof(t_hash))); - p->data.cmd.path = ft_strdup(hash.path); - return (1); + return (ft_strdup(hash.path)); } diff --git a/42sh/src/hash_table/hash.c b/42sh/src/hash_table/hash.c index 2276a4e1..1cf1dd79 100644 --- a/42sh/src/hash_table/hash.c +++ b/42sh/src/hash_table/hash.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 11:06:19 by gwojda #+# #+# */ -/* Updated: 2017/03/07 16:02:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/19 16:38:12 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,11 @@ t_list *g_hash[MAX_HASH] = {NULL}; -int ft_hash(t_process *p) +char *ft_hash(char *cmd) { - if (!ft_is_hash(p)) - if (!ft_add_hash(p)) - return (0); - return (1); + char *path; + + if (!(path = ft_is_hash(cmd))) + path = ft_add_hash(cmd); + return (path); } diff --git a/42sh/src/hash_table/is_hash.c b/42sh/src/hash_table/is_hash.c index 385401e3..fc7c687d 100644 --- a/42sh/src/hash_table/is_hash.c +++ b/42sh/src/hash_table/is_hash.c @@ -6,36 +6,35 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 11:08:40 by gwojda #+# #+# */ -/* Updated: 2017/03/07 14:45:20 by wescande ### ########.fr */ +/* Updated: 2017/03/19 16:39:18 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int ft_is_hash(t_process *p) +char *ft_is_hash(char *cmd) { t_list *list; t_list *ref; int id; - id = ft_hash_str(p->data.cmd.av[0]); + id = ft_hash_str(cmd); list = g_hash[id]; ref = list; while (list) { - if (!ft_strcmp(((t_hash *)list->content)->key, p->data.cmd.av[0])) + if (!ft_strcmp(((t_hash *)list->content)->key, cmd)) { if (access(((t_hash *)list->content)->path, X_OK)) { ref->next = list->next; ft_lstdelone(&list, &ft_hash_free); - return (0); + return (NULL); } - p->data.cmd.path = ft_strdup(((t_hash *)list->content)->path); - return (1); + return (ft_strdup(((t_hash *)list->content)->path)); } ref = list; list = list->next; } - return (0); + return (NULL); } diff --git a/42sh/src/lexer/do_lexer_routine.c b/42sh/src/lexer/do_lexer_routine.c new file mode 100644 index 00000000..6c996280 --- /dev/null +++ b/42sh/src/lexer/do_lexer_routine.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* do_lexer_routine.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/19 14:24:38 by wescande #+# #+# */ +/* Updated: 2017/03/19 14:31:39 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int do_lexer_routine(t_list **token, char *stream) +{ + t_list *ltoken; + t_data *data; + + data = data_singleton(); + if (data->lexer.state == HEREDOC || data->parser.state == UNDEFINED) + { + ft_strappend(&data->lexer.str, (char[]){'\n', 0}); + data->lexer.pos++; + } + ft_strappend(&data->lexer.str, stream); + if (get_lexer_stack(data->lexer) == BACKSLASH) + pop(&data->lexer.stack); + ltoken = ft_lstlast(*token); + if (lexer_lex(*token ? <oken : token, &data->lexer) < 0) + exit(1); + if (get_lexer_stack(data->lexer) > 2) + return (1); + data->lexer.state = DEFAULT; + return (0); +} diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 7c901196..7c51b07b 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/17 21:18:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/19 16:49:29 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,11 +29,11 @@ int data_init(int ac, char **av) set_exitstatus(0, 1); shlvl = ft_getenv(data->env, "SHLVL"); if (shlvl) - { shlvl = ft_itoa(ft_atoi(shlvl) + 1); - builtin_setenv(NULL, (char *[]){"setenv", "SHLVL", shlvl, 0}, NULL); - ft_strdel(&shlvl); - } + else + shlvl = ft_strdup("1"); + builtin_setenv(NULL, (char *[]){"setenv", "SHLVL", shlvl, 0}, NULL); + ft_strdel(&shlvl); data->comp = NULL; data->opts = 0; exec_reset(); diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 34394cc0..9a1c7e8b 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -28,54 +28,6 @@ static int do_readline_routine(char **stream) return (ret); } -static int do_lexer_routine(t_list **token, char *stream) -{ - t_list *ltoken; - t_data *data; - - data = data_singleton(); - if (data->lexer.state == HEREDOC || data->parser.state == UNDEFINED) - { - ft_strappend(&data->lexer.str, (char[]){'\n', 0}); - data->lexer.pos++; - } - ft_strappend(&data->lexer.str, stream); - if (get_lexer_stack(data->lexer) == BACKSLASH) - pop(&data->lexer.stack); - ltoken = ft_lstlast(*token); - if (lexer_lex(*token ? <oken : token, &data->lexer) < 0) - exit(1); - if (get_lexer_stack(data->lexer) > 2) - return (1); - data->lexer.state = DEFAULT; - return (0); -} - -static int do_parser_routine(t_list **token, t_btree **ast) -{ - t_data *data; - - data = data_singleton(); - if (get_reserved_words(*token)) - return (1); - if (insert_newline(token)) - return (1); - if (data->parser.state == SUCCESS && stack_init(&data->parser)) - exit(1); - if (ft_parse(ast, token, &data->parser)) - exit(1); - if ((data->lexer.state = data->parser.heredoc_queue ? HEREDOC : DEFAULT)) - return (0); - if (data->parser.state == ERROR) - { - error_syntax(token); - return (1); - } - else if (data->parser.state == SUCCESS) - return (1); - return (0); -} - static int handle_instruction(t_list **token, t_btree **ast) { int ret; diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 0ef8b902..be1f1cf6 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/18 00:04:33 by wescande ### ########.fr */ +/* Updated: 2017/03/19 16:50:42 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,7 +71,8 @@ static int interactive_settings(void) *shell_pgid = getpid(); if (setpgid(*shell_pgid, *shell_pgid)) { - ft_dprintf(2, "Couldnt put the shell in it's own process group"); + ft_dprintf(2, + "{red}Couldnt put the shell in it's own process group{eoc}\n"); exit(1); } tcsetpgrp(STDIN, *shell_pgid); diff --git a/42sh/src/parser/do_parser_routine.c b/42sh/src/parser/do_parser_routine.c new file mode 100644 index 00000000..26dfdd34 --- /dev/null +++ b/42sh/src/parser/do_parser_routine.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* do_parser_routine.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/19 14:24:14 by wescande #+# #+# */ +/* Updated: 2017/03/19 14:24:22 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int do_parser_routine(t_list **token, t_btree **ast) +{ + t_data *data; + + data = data_singleton(); + if (get_reserved_words(*token)) + return (1); + if (insert_newline(token)) + return (1); + if (data->parser.state == SUCCESS && stack_init(&data->parser)) + exit(1); + if (ft_parse(ast, token, &data->parser)) + exit(1); + if ((data->lexer.state = data->parser.heredoc_queue ? HEREDOC : DEFAULT)) + return (0); + if (data->parser.state == ERROR) + { + error_syntax(token); + return (1); + } + else if (data->parser.state == SUCCESS) + return (1); + return (0); +}