1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/enc/trans/make_transdb.rb
nobu 2f37e03736 * enc/trans/make_transdb.rb: fix for the case no transdirs are given.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18434 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-08 07:09:03 +00:00

41 lines
1.2 KiB
Ruby

#
# static const rb_transcoder
# rb_from_US_ASCII = {
# "US-ASCII", "UTF-8", &from_US_ASCII, 1, 0,
# NULL, NULL,
# };
#
count = 0
converters = {}
outhdr = ARGV[0] || 'transdb.h'
transdirs = ARGV[1..-1]
transdirs << 'enc/trans' if transdirs.empty?
files = {}
transdirs.each do |transdir|
Dir.open(transdir) {|d| d.grep(/.+\.[ch]\z/).reject {|n| /\.erb\.c\z/ =~ n }}.sort_by {|e|
e.scan(/(\d+)|(\D+)/).map {|n,a| a||[n.size,n.to_i]}.flatten
}.each do |fn|
next if files[fn]
files[fn] = true
open(File.join(transdir,fn)) do |f|
f.each_line do |line|
if (/^static const rb_transcoder/ =~ line)..(/"(.*?)"\s*,\s*"(.*?)"/ =~ line)
if $1 && $2
from_to = "%s to %s" % [$1, $2]
if converters[from_to]
raise ArgumentError, '%s:%d: transcode "%s" is already registered (%s:%d)' %
[fn, $., from_to, *converters[from_to].values_at(2, 3)]
else
converters[from_to] = [$1, $2, fn[0..-3], $.]
end
end
end
end
end
end
end
result = converters.map {|k, v| %[rb_declare_transcoder("%s", "%s", "%s");\n] % v}.join
open(outhdr, 'wb') do |f|
f.print result
end