summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ruby.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/ruby.c b/ruby.c
index 2e44c47fbd..a47403eb55 100644
--- a/ruby.c
+++ b/ruby.c
@@ -81,6 +81,7 @@ struct cmdline_options {
int yydebug;
char *script;
VALUE e_script;
+ VALUE enc_name;
int enc_index;
};
@@ -723,7 +724,7 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
break;
}
if (enc) {
- opt->enc_index = rb_enc_find_index(rb_enc_name(enc));
+ opt->enc_name = rb_str_new2(rb_enc_name(enc));
}
s++;
}
@@ -789,16 +790,12 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
else if (strcmp("disable-gems", s) == 0)
opt->disable_gems = 1;
else if (strcmp("encoding", s) == 0) {
- int idx;
if (!--argc || !(s = *++argv)) {
noencoding:
rb_raise(rb_eRuntimeError, "missing argument for --encoding");
}
encoding:
- if ((idx = rb_enc_find_index(s)) < 0) {
- rb_raise(rb_eRuntimeError, "unknown encoding name - %s", s);
- }
- opt->enc_index = idx;
+ opt->enc_name = rb_str_new2(s);
}
else if (strncmp("encoding=", s, 9) == 0) {
if (!*(s += 9)) goto noencoding;
@@ -967,6 +964,12 @@ process_options(VALUE arg)
ruby_init_gems(opt);
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);
+ }
+ }
if (opt->e_script) {
if (opt->enc_index >= 0)
rb_enc_associate_index(opt->e_script, opt->enc_index);