* ruby.c (proc_options, process_options, load_file): shouldn't effect

--encoding to script encoding. [ruby-dev:33169]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2008-01-25 04:18:14 +00:00
parent b45fa58f6d
commit 2fc0fe5332
2 changed files with 44 additions and 17 deletions

View File

@ -1,3 +1,8 @@
Fri Jan 25 13:15:23 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* ruby.c (proc_options, process_options, load_file): shouldn't effect
--encoding to script encoding. [ruby-dev:33169]
Fri Jan 25 10:31:58 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Jan 25 10:31:58 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* */*.bat: set svn:mime-type to text/batch. * */*.bat: set svn:mime-type to text/batch.

54
ruby.c
View File

@ -80,8 +80,12 @@ struct cmdline_options {
int yydebug; int yydebug;
char *script; char *script;
VALUE e_script; VALUE e_script;
VALUE enc_name; struct {
int enc_index; struct {
VALUE name;
int index;
} enc;
} src, ext;
}; };
static NODE *load_file(VALUE, const char *, int, struct cmdline_options *); static NODE *load_file(VALUE, const char *, int, struct cmdline_options *);
@ -723,7 +727,8 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
break; break;
} }
if (enc_name) { if (enc_name) {
opt->enc_name = rb_str_new2(enc_name); opt->src.enc.name = rb_str_new2(enc_name);
opt->ext.enc.name = opt->src.enc.name;
} }
s++; s++;
} }
@ -794,7 +799,7 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
rb_raise(rb_eRuntimeError, "missing argument for --encoding"); rb_raise(rb_eRuntimeError, "missing argument for --encoding");
} }
encoding: encoding:
opt->enc_name = rb_str_new2(s); opt->ext.enc.name = rb_str_new2(s);
} }
else if (strncmp("encoding=", s, 9) == 0) { else if (strncmp("encoding=", s, 9) == 0) {
if (!*(s += 9)) goto noencoding; if (!*(s += 9)) goto noencoding;
@ -888,7 +893,8 @@ process_options(VALUE arg)
argv += i; argv += i;
if (rb_safe_level() == 0 && (s = getenv("RUBYOPT"))) { if (rb_safe_level() == 0 && (s = getenv("RUBYOPT"))) {
VALUE enc_name = opt->enc_name; VALUE src_enc_name = opt->src.enc.name;
VALUE ext_enc_name = opt->ext.enc.name;
while (ISSPACE(*s)) while (ISSPACE(*s))
s++; s++;
@ -924,7 +930,10 @@ process_options(VALUE arg)
s = moreswitches(s, opt); s = moreswitches(s, opt);
} }
} }
if (enc_name) opt->enc_name = enc_name; if (src_enc_name)
opt->src.enc.name = src_enc_name;
if (ext_enc_name)
opt->ext.enc.name = ext_enc_name;
} }
if (opt->version) { if (opt->version) {
@ -981,11 +990,14 @@ process_options(VALUE arg)
ruby_init_gems(opt); ruby_init_gems(opt);
parser = rb_parser_new(); parser = rb_parser_new();
if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue); if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue);
if (opt->enc_name != 0) { if (opt->ext.enc.name != 0) {
opt->enc_index = opt_enc_index(opt->enc_name); opt->ext.enc.index = opt_enc_index(opt->ext.enc.name);
} }
if (opt->enc_index >= 0) { if (opt->src.enc.name != 0) {
enc = rb_enc_from_index(opt->enc_index); opt->src.enc.index = opt_enc_index(opt->src.enc.name);
}
if (opt->ext.enc.index >= 0) {
enc = rb_enc_from_index(opt->ext.enc.index);
} }
else { else {
enc = rb_locale_encoding(); enc = rb_locale_encoding();
@ -1065,7 +1077,8 @@ load_file(VALUE parser, const char *fname, int script, struct cmdline_options *o
VALUE c = 1; /* something not nil */ VALUE c = 1; /* something not nil */
VALUE line; VALUE line;
char *p; char *p;
int no_enc = !opt->enc_name; int no_src_enc = !opt->src.enc.name;
int no_ext_enc = !opt->ext.enc.name;
if (opt->xflag) { if (opt->xflag) {
forbid_setid("-x"); forbid_setid("-x");
@ -1142,8 +1155,11 @@ load_file(VALUE parser, const char *fname, int script, struct cmdline_options *o
rb_io_ungetc(f, c); rb_io_ungetc(f, c);
} }
rb_io_ungetc(f, INT2FIX('#')); rb_io_ungetc(f, INT2FIX('#'));
if (no_enc && opt->enc_name) { if (no_src_enc && opt->src.enc.name) {
opt->enc_index = opt_enc_index(opt->enc_name); opt->src.enc.index = opt_enc_index(opt->src.enc.name);
}
if (no_ext_enc && opt->ext.enc.name) {
opt->ext.enc.index = opt_enc_index(opt->ext.enc.name);
} }
} }
else if (!NIL_P(c)) { else if (!NIL_P(c)) {
@ -1151,12 +1167,17 @@ load_file(VALUE parser, const char *fname, int script, struct cmdline_options *o
} }
require_libraries(); /* Why here? unnatural */ require_libraries(); /* Why here? unnatural */
} }
if (opt->enc_index >= 0) { if (opt->src.enc.index >= 0) {
enc = rb_enc_from_index(opt->enc_index); enc = rb_enc_from_index(opt->src.enc.index);
} }
else if (f == rb_stdin) { else if (f == rb_stdin) {
if (opt->ext.enc.index >= 0) {
enc = rb_enc_from_index(opt->ext.enc.index);
}
else {
enc = rb_locale_encoding(); enc = rb_locale_encoding();
} }
}
else { else {
enc = 0; enc = 0;
} }
@ -1408,7 +1429,8 @@ ruby_process_options(int argc, char **argv)
rb_argv0 = rb_progname; rb_argv0 = rb_progname;
opt.argc = argc; opt.argc = argc;
opt.argv = argv; opt.argv = argv;
opt.enc_index = -1; opt.src.enc.index = -1;
opt.ext.enc.index = -1;
tree = (NODE *)rb_vm_call_cfunc(rb_vm_top_self(), tree = (NODE *)rb_vm_call_cfunc(rb_vm_top_self(),
process_options, (VALUE)&opt, process_options, (VALUE)&opt,
0, rb_progname); 0, rb_progname);