diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /42sh/src/helper.c | |
Diffstat (limited to '42sh/src/helper.c')
| -rw-r--r-- | 42sh/src/helper.c | 43 |
1 files changed, 43 insertions, 0 deletions
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; +} |
