From 00bce5ad1d5ac92d20617a9eb2647365bf87cab2 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Fri, 9 Oct 2020 16:13:50 +0200 Subject: Splitting preprocessing, Added parsed error helper --- src/main.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index baa03b5..28b808a 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */ -/* Updated: 2020/10/09 13:57:22 by cacharle ### ########.fr */ +/* Updated: 2020/10/09 15:51:00 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,12 +25,27 @@ int debug_parser(char *input); t_state g_state; +int run_eval(t_env env, t_parsed *parser_out) +{ + int status; + int fds[2]; + + fds[0] = FD_NONE; + fds[1] = FD_NONE; + status = eval(fds, env, parser_out->ast); + ast_destroy(parser_out->ast); + free(parser_out); + if (status == EVAL_FATAL) + exit(1); + g_state.last_status = status; + return (status); +} + int execute(t_env env, char *input) { t_tok_lst *lexer_out; int status; t_parsed *parser_out; - int fds[2]; if (utils_strisblank(input)) return (0); @@ -46,15 +61,7 @@ int execute(t_env env, char *input) free(parser_out); return (2); } - fds[0] = FD_NONE; - fds[1] = FD_NONE; - status = eval(fds, env, parser_out->ast); - ast_destroy(parser_out->ast); - free(parser_out); - if (status == EVAL_FATAL) - exit(1); - g_state.last_status = status; - return (status); + return (run_eval(env, parser_out)); } int repl(t_env env) @@ -65,11 +72,6 @@ int repl(t_env env) print_prompt(); while ((ret = ft_getline(STDIN_FILENO, &line)) == FTGL_OK) { - if (*line == '\0') - { - print_prompt(); - continue ; - } g_state.killed = false; if (execute(env, line) == EVAL_FATAL) return (2); -- cgit