summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ast.h1
-rw-r--r--main.c20
2 files changed, 21 insertions, 0 deletions
diff --git a/ast.h b/ast.h
index 480f537..52e22e8 100644
--- a/ast.h
+++ b/ast.h
@@ -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 {
diff --git a/main.c b/main.c
index f80f80b..a23a39d 100644
--- a/main.c
+++ b/main.c
@@ -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");