2008-01-29 06:18:22 -05:00
|
|
|
#
|
|
|
|
# static const rb_transcoder
|
|
|
|
# rb_from_US_ASCII = {
|
|
|
|
# "US-ASCII", "UTF-8", &from_US_ASCII, 1, 0,
|
|
|
|
# NULL, NULL,
|
|
|
|
# };
|
|
|
|
#
|
|
|
|
|
|
|
|
count = 0
|
|
|
|
converters = {}
|
2008-08-08 03:15:52 -04:00
|
|
|
transdirs = ARGV.dup
|
|
|
|
outhdr = transdirs.shift || 'transdb.h'
|
2008-08-08 03:09:03 -04:00
|
|
|
transdirs << 'enc/trans' if transdirs.empty?
|
2008-08-08 03:03:35 -04:00
|
|
|
files = {}
|
2008-08-07 15:24:47 -04:00
|
|
|
transdirs.each do |transdir|
|
2008-08-08 17:37:43 -04:00
|
|
|
next unless File.directory?(transdir)
|
2008-08-12 05:43:44 -04:00
|
|
|
Dir.open(transdir) {|d| d.grep(/.+\.[ch]\z/) }.sort_by {|e|
|
2008-08-07 15:24:47 -04:00
|
|
|
e.scan(/(\d+)|(\D+)/).map {|n,a| a||[n.size,n.to_i]}.flatten
|
|
|
|
}.each do |fn|
|
2008-08-08 03:03:35 -04:00
|
|
|
next if files[fn]
|
|
|
|
files[fn] = true
|
2008-08-07 15:24:47 -04:00
|
|
|
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
|
2008-01-29 06:18:22 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
result = converters.map {|k, v| %[rb_declare_transcoder("%s", "%s", "%s");\n] % v}.join
|
2008-05-29 23:18:45 -04:00
|
|
|
open(outhdr, 'wb') do |f|
|
|
|
|
f.print result
|
2008-01-29 06:18:22 -05:00
|
|
|
end
|