aboutsummaryrefslogtreecommitdiffstats
path: root/enc/make_encdb.rb
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-12 16:03:51 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-12 16:03:51 +0000
commit5b9739a832c884f450e04d90edb026a09da5e6de (patch)
tree2c56a6561c2101cab1b62b81887d15a4fb944d86 /enc/make_encdb.rb
parent2cfd4473d6970dc9b82dd9326a22550dd46855c7 (diff)
downloadruby-5b9739a832c884f450e04d90edb026a09da5e6de.tar.gz
* enc/make_encdb.rb: added. search enc/*.c and make encoding database.
* regenc.h (ENC_REPLICATE, ENC_ALIAS): added for defining replica encoding and encoding alias. * encoding.c (rb_enc_init): move alias definitions to enc/*.c. (rb_enc_find_index): search original of replica and alias when no encoding library. (rb_enc_name_list, rb_enc_aliases_enc_i, rb_enc_aliases_str_i, rb_enc_aliases, Encoding.name_list, Encoding.aliases): added. (Init_Encoding): init encdb. * enc/ascii.c, enc/us_ascii.c, enc/euc_jp.c, enc/sjis.c: add replica encoding and encoding alias difinition. * common.mk (dist-clean-local): add rule for remvoe encdb.h. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enc/make_encdb.rb')
-rwxr-xr-xenc/make_encdb.rb65
1 files changed, 65 insertions, 0 deletions
diff --git a/enc/make_encdb.rb b/enc/make_encdb.rb
new file mode 100755
index 0000000000..2cd7699944
--- /dev/null
+++ b/enc/make_encdb.rb
@@ -0,0 +1,65 @@
+#! ./miniruby
+
+#
+# OnigEncodingDefine(foo, Foo) = {
+# ..
+# "Shift_JIS", /* Canonical Name */
+# ..
+# };
+# ENC_ALIAS("SJIS", "Shift_JIS")
+# ENC_REPLICATE("Windows-31J", "Shift_JIS")
+# ENC_ALIAS("CP932", "Windows-31J")
+#
+
+require 'mkmf'
+
+encodings = []
+replicas = {}
+aliases = {}
+Dir.open($srcdir) {|d| d.grep(/.+\.c\z/)}.each do |fn|
+ open(File.join($srcdir,fn)) do |f|
+ orig = nil
+ name = nil
+ f.each_line do |line|
+ break if /^OnigEncodingDefine/o =~ line
+ end
+ f.each_line do |line|
+ break if /"(.*?)"/ =~ line
+ end
+ encodings << $1 if $1
+ f.each_line do |line|
+ if /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line
+ replicas[$1] = $2
+ elsif /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line
+ aliases[$1] = $2
+ end
+ end
+ end
+end
+open('encdb.h', 'wb') do |f|
+ f.puts 'static const char *enc_name_list[] = {'
+ encodings.each {|name| f.puts' "%s",' % name}
+ replicas.each_key {|name| f.puts' "%s",' % name}
+ f.puts(<<"_TEXT_")
+ NULL
+};
+static const int enc_name_list_size = #{encodings.length + replicas.length};
+static const int enc_aliases_size = #{aliases.length};
+static st_table *enc_table_replica_name;
+static st_table *enc_table_alias_name;
+
+static void enc_init_db(void)
+{
+ if (!enc_table_replica_name) {
+ enc_table_replica_name = st_init_strcasetable();
+ }
+ if (!enc_table_alias_name) {
+ enc_table_alias_name = st_init_strcasetable();
+ }
+_TEXT_
+ replicas.each_pair {|name, orig|
+ f.puts' st_insert(enc_table_replica_name, (st_data_t)"%s", (st_data_t)"%s");' % [name, orig]}
+ aliases.each_pair {|name, orig|
+ f.puts' st_insert(enc_table_alias_name, (st_data_t)"%s", (st_data_t)"%s");' % [name, orig]}
+ f.puts '}'
+end