2009-01-13 04:05:29 -05:00
|
|
|
<%
|
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
|
2008-08-08 03:09:03 -04:00
|
|
|
transdirs << 'enc/trans' if transdirs.empty?
|
2008-09-02 07:57:49 -04:00
|
|
|
|
|
|
|
transdirs = transdirs.sort_by {|td|
|
2008-09-03 04:57:18 -04:00
|
|
|
-td.length
|
2008-09-02 07:57:49 -04:00
|
|
|
}.inject([]) {|tds, td|
|
|
|
|
next tds unless File.directory?(td)
|
|
|
|
tds << td if tds.all? {|td2| !File.identical?(td2, td) }
|
|
|
|
tds
|
|
|
|
}
|
|
|
|
|
2008-08-08 03:03:35 -04:00
|
|
|
files = {}
|
2008-09-03 04:57:18 -04:00
|
|
|
names_t = []
|
2009-01-13 03:28:14 -05:00
|
|
|
converter_list = []
|
2008-08-07 15:24:47 -04:00
|
|
|
transdirs.each do |transdir|
|
2008-09-02 07:57:49 -04:00
|
|
|
names = Dir.entries(transdir)
|
2008-09-03 04:57:18 -04:00
|
|
|
names_t += names.map {|n| /(?!\A)\.trans\z/ =~ n ? $` : nil }.compact
|
2008-09-02 07:57:49 -04:00
|
|
|
names_c = names.map {|n| /(?!\A)\.c\z/ =~ n ? $` : nil }.compact
|
|
|
|
(names_t & names_c).map {|n|
|
|
|
|
"#{n}.c"
|
|
|
|
}.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-09-02 06:20:11 -04:00
|
|
|
path = File.join(transdir,fn)
|
|
|
|
open(path) do |f|
|
2018-06-15 04:53:17 -04:00
|
|
|
transcoder_def = false
|
2008-08-07 15:24:47 -04:00
|
|
|
f.each_line do |line|
|
2018-06-15 04:53:17 -04:00
|
|
|
transcoder_def = true if /^static const rb_transcoder/ =~ line
|
|
|
|
if transcoder_def && /"(.*?)"\s*,\s*"(.*?)"/ =~ line
|
|
|
|
transcoder_def = false
|
|
|
|
from_to = "%s to %s" % [$1, $2]
|
|
|
|
if converters[from_to]
|
|
|
|
raise ArgumentError, '%s:%d: transcode "%s" is already registered at %s:%d' %
|
2020-01-20 02:53:31 -05:00
|
|
|
[path, f.lineno, from_to, *converters[from_to].values_at(3, 4)]
|
2018-06-15 04:53:17 -04:00
|
|
|
else
|
2020-01-20 02:53:31 -05:00
|
|
|
converters[from_to] = [$1, $2, fn[0..-3], path, f.lineno]
|
2018-06-15 04:53:17 -04:00
|
|
|
converter_list << from_to
|
2008-08-07 15:24:47 -04:00
|
|
|
end
|
2008-01-29 06:18:22 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-01-13 04:05:29 -05:00
|
|
|
converter_list.each do |from_to|
|
|
|
|
from, to, fn = *converters[from_to]
|
|
|
|
%>rb_declare_transcoder("<%=from%>", "<%=to%>", "<%=fn%>");
|
|
|
|
% end
|