From 434e8a379656337f97cff9108c5a4b5b7c220fed Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 14 May 2005 02:48:07 +0000 Subject: * intern.h (ruby_pragma): prototype. [ruby-core:04881] * parse.y (parser_pragma): parse Emacsen hack. * parse.y (parser_prepare): deal with specific syntax at the top. * ruby.c (load_file): read the first line iff it started with shebang. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'ruby.c') diff --git a/ruby.c b/ruby.c index dd2a3612a2..736f585f27 100644 --- a/ruby.c +++ b/ruby.c @@ -917,11 +917,11 @@ load_file(fname, script) c = rb_io_getc(f); if (c == INT2FIX('#')) { - line = rb_io_gets(f); - if (NIL_P(line)) return; - line_start++; + c = rb_io_getc(f); + if (c == INT2FIX('!')) { + line = rb_io_gets(f); + if (NIL_P(line)) return; - if (RSTRING(line)->len > 2 && RSTRING(line)->ptr[0] == '!') { if ((p = strstr(RSTRING(line)->ptr, "ruby")) == 0) { /* not ruby script, kick the program */ char **argv; @@ -965,7 +965,15 @@ load_file(fname, script) p = moreswitches(p+1); } } + + /* push back shebang for pragma may exist in next line */ + rb_io_ungetc(f, INT2FIX('\n')); + rb_io_ungetc(f, INT2FIX('!')); + } + else if (!NIL_P(c)) { + rb_io_ungetc(f, c); } + rb_io_ungetc(f, INT2FIX('#')); } else if (!NIL_P(c)) { rb_io_ungetc(f, c); -- cgit v1.2.3