зеркало из https://github.com/github/ruby.git
* enc/make_encdb.rb: set properties.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15011 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
e699dda504
Коммит
9bded8aae9
|
@ -1,64 +1,64 @@
|
||||||
#
|
#
|
||||||
# OnigEncodingDefine(foo, Foo) = {
|
# OnigEncodingDefine(foo, Foo) = {
|
||||||
# ..
|
# ..
|
||||||
# "Shift_JIS", /* Canonical Name */
|
# "Shift_JIS", /* Canonical Name */
|
||||||
# ..
|
# ..
|
||||||
# };
|
# };
|
||||||
# ENC_ALIAS("SJIS", "Shift_JIS")
|
# ENC_ALIAS("SJIS", "Shift_JIS")
|
||||||
# ENC_REPLICATE("Windows-31J", "Shift_JIS")
|
# ENC_REPLICATE("Windows-31J", "Shift_JIS")
|
||||||
# ENC_ALIAS("CP932", "Windows-31J")
|
# ENC_ALIAS("CP932", "Windows-31J")
|
||||||
#
|
#
|
||||||
|
|
||||||
encodings = []
|
encodings = []
|
||||||
replicas = {}
|
replicas = {}
|
||||||
aliases = {}
|
aliases = {}
|
||||||
encdir = ARGV[0]
|
encdir = ARGV[0]
|
||||||
Dir.open(encdir) {|d| d.grep(/.+\.c\z/)}.each do |fn|
|
Dir.open(encdir) {|d| d.grep(/.+\.c\z/)}.each do |fn|
|
||||||
open(File.join(encdir,fn)) do |f|
|
open(File.join(encdir,fn)) do |f|
|
||||||
orig = nil
|
orig = nil
|
||||||
name = nil
|
name = nil
|
||||||
f.each_line do |line|
|
f.each_line do |line|
|
||||||
break if /^OnigEncodingDefine/o =~ line
|
break if /^OnigEncodingDefine/o =~ line
|
||||||
end
|
end
|
||||||
f.each_line do |line|
|
f.each_line do |line|
|
||||||
break if /"(.*?)"/ =~ line
|
break if /"(.*?)"/ =~ line
|
||||||
end
|
end
|
||||||
encodings << $1 if $1
|
encodings << $1 if $1
|
||||||
f.each_line do |line|
|
f.each_line do |line|
|
||||||
if /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line
|
if /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line
|
||||||
replicas[$1] = $2
|
replicas[$1] = $2
|
||||||
elsif /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line
|
elsif /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line
|
||||||
aliases[$1] = $2
|
aliases[$1] = $2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
p aliases
|
p aliases
|
||||||
open('encdb.h', 'wb') do |f|
|
open('encdb.h', 'wb') do |f|
|
||||||
f.puts 'static const char *enc_name_list[] = {'
|
f.puts 'static const char *enc_name_list[] = {'
|
||||||
encodings.each {|name| f.puts' "%s",' % name}
|
encodings.each {|name| f.puts' "%s",' % name}
|
||||||
replicas.each_key {|name| f.puts' "%s",' % name}
|
replicas.each_key {|name| f.puts' "%s",' % name}
|
||||||
aliases.each_key {|name| f.puts' "%s",' % name}
|
aliases.each_key {|name| f.puts' "%s",' % name}
|
||||||
f.puts(<<"_TEXT_")
|
f.puts(<<"_TEXT_")
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
static const int enc_name_list_size = #{encodings.length + replicas.length + aliases.length};
|
static const int enc_name_list_size = #{encodings.length + replicas.length + aliases.length};
|
||||||
static const int enc_aliases_size = #{aliases.length};
|
static const int enc_aliases_size = #{aliases.length};
|
||||||
static st_table *enc_table_replica_name;
|
static st_table *enc_table_replica_name;
|
||||||
static st_table *enc_table_alias_name;
|
static st_table *enc_table_alias_name;
|
||||||
|
|
||||||
static void enc_init_db(void)
|
static void enc_init_db(void)
|
||||||
{
|
{
|
||||||
if (!enc_table_replica_name) {
|
if (!enc_table_replica_name) {
|
||||||
enc_table_replica_name = st_init_strcasetable();
|
enc_table_replica_name = st_init_strcasetable();
|
||||||
}
|
}
|
||||||
if (!enc_table_alias_name) {
|
if (!enc_table_alias_name) {
|
||||||
enc_table_alias_name = st_init_strcasetable();
|
enc_table_alias_name = st_init_strcasetable();
|
||||||
}
|
}
|
||||||
_TEXT_
|
_TEXT_
|
||||||
replicas.each_pair {|name, orig|
|
replicas.each_pair {|name, orig|
|
||||||
f.puts' st_insert(enc_table_replica_name, (st_data_t)"%s", (st_data_t)"%s");' % [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|
|
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' st_insert(enc_table_alias_name, (st_data_t)"%s", (st_data_t)"%s");' % [name, orig]}
|
||||||
f.puts '}'
|
f.puts '}'
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче