diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-23 07:53:49 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-24 09:23:55 +0200 |
commit | fc7ef102aa147680e2c82b6f2be338ad51ce0842 (patch) | |
tree | 3cd221f54a6e93c4a68e7d20007b4abfaaf55d90 | |
parent | 45f1c9f05c66f864853a2a9bc3b592f6f9d42e6f (diff) |
main: support invoking utpl interpreter through shebang
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | ast.h | 1 | ||||
-rw-r--r-- | main.c | 20 |
2 files changed, 21 insertions, 0 deletions
@@ -83,6 +83,7 @@ struct ut_state { uint8_t trim_blocks:1; uint8_t lstrip_blocks:1; uint8_t strict_declarations:1; + uint8_t skip_shebang:1; size_t off; enum ut_block_type blocktype; struct { @@ -148,6 +148,16 @@ parse(struct ut_state *state, const char *source, bool dumponly, enum ut_error_type err; char *msg; + if (state->skip_shebang) { + if (source[0] == '#' && source[1] == '!') { + while (source[0] != '\0' && source[0] != '\n') + source++; + + if (source[0] == '\n') + source++; + } + } + err = ut_parse(state, source); if (!err) { @@ -336,6 +346,16 @@ main(int argc, char **argv) } } + if (!srcstr && !srcfile && argv[optind] != NULL) { + srcfile = read_file(argv[optind]); + state->skip_shebang = 1; + + if (!srcfile) { + rv = UT_ERROR_EXCEPTION; + goto out; + } + } + if ((srcstr && srcfile) || (!srcstr && !srcfile)) { fprintf(stderr, srcstr ? "Options -i and -s are exclusive\n" : "One of -i or -s is required\n"); |