From f6e474d27a1398c6d4f2e88c7f2d3797b85217da Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Wed, 22 Jan 2025 02:40:27 +0100 Subject: kinda fix for pipe error and again.vs for you db just chnage workfolder gn --- src/repl.c | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) (limited to 'src/repl.c') diff --git a/src/repl.c b/src/repl.c index 7ff80a8..2dcd16d 100644 --- a/src/repl.c +++ b/src/repl.c @@ -6,56 +6,44 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */ -/* Updated: 2025/01/11 16:01:44 by chuhlig ### ########.fr */ +/* Updated: 2025/01/21 21:29:16 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ #include "../include/minishell.h" #include "token.h" -t_token *reverse_token_list(t_token *head) +void free_repl(char *input, t_node *ast) { - t_token *prev; - t_token *current; - t_token *next; - - prev = NULL; - current = head; - next = NULL; - while (current != NULL) - { - next = current->previous; - current->next = prev; - current->previous = next; - prev = current; - current = next; - } - return (prev); + free(input); + free_node(ast); } -void repl(const char *prompt, t_env **env) +void repl(const char *prompt, t_env **env, int *promptflag) { char *input; t_token *token_list; - t_list *lines; + t_node *ast; + (*promptflag)++; while (1) { input = readline(prompt); if (input == NULL) - return ; + { + if (*promptflag > 1) + (*promptflag)--; + printf("exit\n"); + break ; + } if (input[0] == '\0') continue ; add_history(input); token_list = NULL; tokenizer(input, &token_list, '\0'); - token_list = reverse_token_list(token_list); - lines = parse(token_list, env); - if (lines) - { - print_ast(lines->content); - eval(lines->content, env); - } - free(input); + ast = parse(token_list, env); + if (ast) + set_return_code(eval(ast, env), env); + free_repl(input, ast); } } -- cgit v1.2.3