diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | encoding.c | 17 | ||||
-rw-r--r-- | ruby.c | 12 |
3 files changed, 32 insertions, 7 deletions
@@ -1,3 +1,13 @@ +Fri Dec 21 13:40:11 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * encoding.c (rb_enc_register): set encoding constant. + + * encoding.c (rb_enc_find_index): replace non-alphanumeric chars with + underscores, so that initialize function can be called. + + * ruby.c (proc_options, process_options): finds encoding after + load_path is initialized. + Fri Dec 21 13:10:57 2007 Yukihiro Matsumoto <matz@ruby-lang.org> * io.c (rb_io_external_encoding): new method. diff --git a/encoding.c b/encoding.c index 6ff8fb6aad..fdcceab5a2 100644 --- a/encoding.c +++ b/encoding.c @@ -158,6 +158,7 @@ enc_register(const char *name, rb_encoding *encoding) } static VALUE enc_based_encoding(VALUE); +static void set_encoding_const(const char *, rb_encoding *); int rb_enc_registered(const char *name); int @@ -170,16 +171,21 @@ rb_enc_register(const char *name, rb_encoding *encoding) if (strcasecmp(name, rb_enc_name(oldenc))) { st_data_t key = (st_data_t)name, alias; st_delete(enc_table_alias, &key, &alias); + index = enc_register(name, encoding); } else if (enc_initialized_p(oldenc) && - !NIL_P(enc_based_encoding(ENC_FROM_ENCODING(encoding)))) { - return enc_register_at(index, name, encoding); + !NIL_P(enc_based_encoding(ENC_FROM_ENCODING(oldenc)))) { + enc_register_at(index, name, encoding); } else { rb_raise(rb_eArgError, "encoding %s is already registered", name); } } - return enc_register(name, encoding); + else { + index = enc_register(name, encoding); + } + set_encoding_const(name, rb_enc_from_index(index)); + return index; } int @@ -293,6 +299,11 @@ rb_enc_find_index(const char *name) int i = rb_enc_registered(name); if (i < 0) { VALUE enclib = rb_sprintf("enc/%s", name); + char *s = RSTRING_PTR(enclib) + 4, *e = RSTRING_END(enclib); + while (s < e) { + if (!ISALNUM(*s)) *s = '_'; + ++s; + } OBJ_FREEZE(enclib); if (RTEST(rb_protect(require_enc, enclib, 0))) i = rb_enc_registered(name); @@ -81,6 +81,7 @@ struct cmdline_options { int yydebug; char *script; VALUE e_script; + const char *enc_name; int enc_index; }; @@ -739,7 +740,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_enc_name(enc); } s++; } @@ -810,9 +811,7 @@ proc_options(int argc, char **argv, struct cmdline_options *opt) rb_raise(rb_eRuntimeError, "missing argument for --encoding"); } encoding: - if ((opt->enc_index = rb_enc_find_index(s)) < 0) { - rb_raise(rb_eRuntimeError, "unknown encoding name - %s", s); - } + opt->enc_name = s; } else if (strncmp("encoding=", s, 9) == 0) { if (!*(s += 9)) goto noencoding; @@ -981,6 +980,11 @@ process_options(VALUE arg) ruby_init_gems(opt); parser = rb_parser_new(); if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue); + if ((s = opt->enc_name) != 0) { + 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); |