ruby-changes:3472
From: ko1@a...
Date: 9 Jan 2008 15:54:42 +0900
Subject: [ruby-changes:3472] nobu - Ruby:r14965 (trunk): * ruby.c (process_options): give priority command line encoding option
nobu 2008-01-09 15:54:26 +0900 (Wed, 09 Jan 2008) New Revision: 14965 Modified files: trunk/ChangeLog trunk/ruby.c Log: * 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. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ruby.c?r1=14965&r2=14964&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14965&r2=14964&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 14964) +++ ChangeLog (revision 14965) @@ -1,3 +1,11 @@ +Wed Jan 9 15:54:24 2008 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * parse.y (yycompile0): remove setting parser->enc because it is set Index: ruby.c =================================================================== --- ruby.c (revision 14964) +++ ruby.c (revision 14965) @@ -857,6 +857,21 @@ 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 @@ 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 @@ } 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 @@ 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 @@ 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 @@ 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml