diff options
Diffstat (limited to 'src/repl.c')
| -rw-r--r-- | src/repl.c | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -6,18 +6,25 @@ /* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */ -/* Updated: 2025/01/20 17:58:43 by dkaiser ### ########.fr */ +/* Updated: 2025/01/25 15:39:36 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ #include "../include/minishell.h" #include "token.h" -void repl(const char *prompt, t_env **env, int *promptflag) +static void free_repl(char *input, t_node *ast) +{ + free(input); + if (ast) + free_node(ast); +} + +void repl(const char *prompt, t_env **env) { char *input; t_token *token_list; - t_list *lines; + t_node *ast; (*promptflag)++; while (1) @@ -25,19 +32,20 @@ void repl(const char *prompt, t_env **env, int *promptflag) input = readline(prompt); if (input == NULL) { - if (*promptflag > 1) - (*promptflag)--; printf("exit\n"); break ; } if (input[0] == '\0') + { + free(input); continue ; + } add_history(input); token_list = NULL; tokenizer(input, &token_list, '\0'); - lines = parse(token_list, env); - if (lines) - set_return_code(eval(lines->content, env), env); - free(input); + ast = parse(token_list, env); + if (ast) + set_return_code(eval(ast, env), env); + free_repl(input, ast); } } |
