1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ruby.c (process_options): give priority command line encoding option

to RUBYOPT, and enable -E option in RUBYOPT.

* ruby.c (load_file): deal with encoding option in shebang line if
  nothing in command line and RUBYOPT.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-01-09 06:54:26 +00:00
parent ff1cd79d08
commit d036633dcb
2 changed files with 33 additions and 8 deletions

View file

@ -1,3 +1,11 @@
Wed Jan 9 15:54:24 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (process_options): give priority command line encoding option
to RUBYOPT, and enable -E option in RUBYOPT.
* ruby.c (load_file): deal with encoding option in shebang line if
nothing in command line and RUBYOPT.
Wed Jan 9 14:55:36 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* parse.y (yycompile0): remove setting parser->enc because it is set

33
ruby.c
View file

@ -857,6 +857,21 @@ ruby_init_gems(struct cmdline_options *opt)
Init_prelude();
}
static int
opt_enc_index(VALUE enc_name)
{
const char *s = RSTRING_PTR(enc_name);
int i = rb_enc_find_index(s);
if (i < 0) {
rb_raise(rb_eRuntimeError, "unknown encoding name - %s", s);
}
else if (rb_enc_dummy_p(rb_enc_from_index(i))) {
rb_raise(rb_eRuntimeError, "dummy encoding is not acceptable - %s ", s);
}
return i;
}
static VALUE
process_options(VALUE arg)
{
@ -873,6 +888,8 @@ process_options(VALUE arg)
argv += i;
if (rb_safe_level() == 0 && (s = getenv("RUBYOPT"))) {
VALUE enc_name = opt->enc_name;
while (ISSPACE(*s))
s++;
if (*s == 'T' || (*s == '-' && *(s + 1) == 'T')) {
@ -901,12 +918,13 @@ process_options(VALUE arg)
}
if (!*s)
break;
if (!strchr("IdvwWrK", *s))
if (!strchr("EIdvwWrK", *s))
rb_raise(rb_eRuntimeError,
"invalid switch in RUBYOPT: -%c", *s);
s = moreswitches(s, opt);
}
}
if (enc_name) opt->enc_name = enc_name;
}
if (opt->version) {
@ -964,13 +982,7 @@ process_options(VALUE arg)
parser = rb_parser_new();
if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue);
if (opt->enc_name != 0) {
s = RSTRING_PTR(opt->enc_name);
if ((opt->enc_index = rb_enc_find_index(s)) < 0) {
rb_raise(rb_eRuntimeError, "unknown encoding name - %s", s);
}
else if (rb_enc_dummy_p(rb_enc_from_index(opt->enc_index))) {
rb_raise(rb_eRuntimeError, "dummy encoding is not acceptable - %s ", s);
}
opt->enc_index = opt_enc_index(opt->enc_name);
}
if (opt->e_script) {
if (opt->enc_index >= 0)
@ -1072,6 +1084,8 @@ load_file(VALUE parser, const char *fname, int script, struct cmdline_options *o
c = rb_io_getbyte(f);
if (c == INT2FIX('#')) {
int no_enc = !opt->enc_name;
c = rb_io_getbyte(f);
if (c == INT2FIX('!')) {
line = rb_io_gets(f);
@ -1129,6 +1143,9 @@ load_file(VALUE parser, const char *fname, int script, struct cmdline_options *o
rb_io_ungetc(f, c);
}
rb_io_ungetc(f, INT2FIX('#'));
if (no_enc && opt->enc_name) {
opt->enc_index = opt_enc_index(opt->enc_name);
}
}
else if (!NIL_P(c)) {
rb_io_ungetc(f, c);