From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- 42sh/src/helper.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 42sh/src/helper.c (limited to '42sh/src/helper.c') diff --git a/42sh/src/helper.c b/42sh/src/helper.c new file mode 100644 index 0000000..7f936fc --- /dev/null +++ b/42sh/src/helper.c @@ -0,0 +1,43 @@ +#include "helper.h" + +int _process_input(struct string *input) +{ + struct lexer *lexer = lexer_new(input); + if (!lexer) + { + errx(BAD_GRAMMAR, "main: unable to create lexer."); + } + + enum parser_state status = OK; + + struct ast *ast = NULL; + int r = SHELL_TRUE; + do + { + ast_free(ast); + ast = parse(lexer, &status); + + if (status == ERROR) + { + errx(BAD_GRAMMAR, "main: parse failed."); + } + + if (env_get("PRETTY_PRINT") != NULL) + { + pretty_print(ast); + } + if (ast) + { + r = eval_ast(ast); + } + } while (ast != NULL && status != ERROR); + if (status == ERROR) + { + ast_free(ast); + } + + string_free(lexer->input); + lexer_free(lexer); + + return r; +} -- cgit v1.2.3