2008-01-12 19:10:00 -05:00
|
|
|
#
|
|
|
|
# OnigEncodingDefine(foo, Foo) = {
|
|
|
|
# ..
|
|
|
|
# "Shift_JIS", /* Canonical Name */
|
|
|
|
# ..
|
|
|
|
# };
|
|
|
|
# ENC_ALIAS("SJIS", "Shift_JIS")
|
|
|
|
# ENC_REPLICATE("Windows-31J", "Shift_JIS")
|
|
|
|
# ENC_ALIAS("CP932", "Windows-31J")
|
|
|
|
#
|
|
|
|
|
|
|
|
encodings = []
|
|
|
|
replicas = {}
|
|
|
|
aliases = {}
|
|
|
|
encdir = ARGV[0]
|
2008-01-13 09:29:12 -05:00
|
|
|
Dir.open(encdir) {|d| d.grep(/.+\.c\z/)}.sort.each do |fn|
|
2008-01-12 19:10:00 -05:00
|
|
|
open(File.join(encdir,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
|
2008-01-13 09:29:12 -05:00
|
|
|
encodings << $1
|
2008-01-12 19:10:00 -05:00
|
|
|
replicas[$1] = $2
|
|
|
|
elsif /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line
|
2008-01-13 09:29:12 -05:00
|
|
|
encodings << $1
|
2008-01-12 19:10:00 -05:00
|
|
|
aliases[$1] = $2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-01-13 09:29:12 -05:00
|
|
|
|
2008-01-12 19:10:00 -05:00
|
|
|
open('encdb.h', 'wb') do |f|
|
2008-01-13 04:41:50 -05:00
|
|
|
f.puts 'static const char *const enc_name_list[] = {'
|
2008-01-12 19:10:00 -05:00
|
|
|
encodings.each {|name| f.puts' "%s",' % name}
|
2008-01-13 04:41:50 -05:00
|
|
|
f.puts('};', '', 'static void', 'enc_init_db(void)', '{')
|
2008-01-12 19:10:00 -05:00
|
|
|
replicas.each_pair {|name, orig|
|
2008-01-13 04:41:50 -05:00
|
|
|
f.puts ' ENC_REPLICATE("%s", "%s");' % [name, orig]
|
|
|
|
}
|
2008-01-12 19:10:00 -05:00
|
|
|
aliases.each_pair {|name, orig|
|
2008-01-13 04:41:50 -05:00
|
|
|
f.puts ' ENC_ALIAS("%s", "%s");' % [name, orig]
|
|
|
|
}
|
2008-01-12 19:10:00 -05:00
|
|
|
f.puts '}'
|
|
|
|
end
|