2009-01-13 04:05:29 -05:00
|
|
|
<%
|
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")
|
|
|
|
#
|
|
|
|
|
2008-01-19 15:15:13 -05:00
|
|
|
def check_duplication(defs, name, fn, line)
|
|
|
|
if defs[name]
|
|
|
|
raise ArgumentError, "%s:%d: encoding %s is already registered(%s:%d)" %
|
|
|
|
[fn, line, name, *defs[name]]
|
|
|
|
else
|
|
|
|
defs[name.upcase] = [fn,line]
|
2008-01-13 15:46:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-01-17 09:56:22 -05:00
|
|
|
count = 0
|
|
|
|
lines = []
|
2008-01-12 19:10:00 -05:00
|
|
|
encodings = []
|
2008-01-19 15:15:13 -05:00
|
|
|
defs = {}
|
2008-08-08 03:15:52 -04:00
|
|
|
encdirs = ARGV.dup
|
|
|
|
encdirs << 'enc' if encdirs.empty?
|
|
|
|
files = {}
|
|
|
|
encdirs.each do |encdir|
|
2008-08-08 17:37:43 -04:00
|
|
|
next unless File.directory?(encdir)
|
2008-08-08 03:15:52 -04:00
|
|
|
Dir.open(encdir) {|d| d.grep(/.+\.[ch]\z/)}.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(encdir,fn)) do |f|
|
|
|
|
name = nil
|
|
|
|
f.each_line do |line|
|
|
|
|
if (/^OnigEncodingDefine/ =~ line)..(/"(.*?)"/ =~ line)
|
|
|
|
if $1
|
2009-08-03 20:50:59 -04:00
|
|
|
if name
|
|
|
|
lines << %[ENC_SET_BASE("#$1", "#{name}");]
|
|
|
|
else
|
|
|
|
name = $1
|
|
|
|
end
|
2008-08-08 03:15:52 -04:00
|
|
|
check_duplication(defs, $1, fn, $.)
|
|
|
|
encodings << $1
|
|
|
|
count += 1
|
|
|
|
end
|
2008-01-17 09:56:22 -05:00
|
|
|
else
|
2008-08-08 03:15:52 -04:00
|
|
|
case line
|
|
|
|
when /^\s*rb_enc_register\(\s*"([^"]+)"/
|
|
|
|
count += 1
|
|
|
|
line = nil
|
|
|
|
when /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/
|
|
|
|
raise ArgumentError,
|
|
|
|
'%s:%d: ENC_REPLICATE: %s is not defined yet. (replica %s)' %
|
|
|
|
[fn, $., $2, $1] unless defs[$2.upcase]
|
|
|
|
count += 1
|
|
|
|
when /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/
|
|
|
|
raise ArgumentError,
|
|
|
|
'%s:%d: ENC_ALIAS: %s is not defined yet. (alias %s)' %
|
|
|
|
[fn, $., $2, $1] unless defs[$2.upcase]
|
2012-10-05 20:42:14 -04:00
|
|
|
when /^ENC_DUMMY\w*\(\s*"([^"]+)"/
|
2008-08-08 03:15:52 -04:00
|
|
|
count += 1
|
|
|
|
else
|
|
|
|
next
|
|
|
|
end
|
|
|
|
check_duplication(defs, $1, fn, $.)
|
2009-01-13 04:05:29 -05:00
|
|
|
lines << line.sub(/;.*/m, "").chomp + ";" if line
|
2008-01-17 09:56:22 -05:00
|
|
|
end
|
2008-01-12 19:10:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-01-13 04:05:29 -05:00
|
|
|
encodings.each do |e|
|
|
|
|
%>ENC_DEFINE("<%=e%>");
|
|
|
|
% end
|
|
|
|
% lines.each do |line|
|
|
|
|
<%=line%>
|
|
|
|
% end
|
2008-01-13 09:29:12 -05:00
|
|
|
|
2009-01-13 04:05:29 -05:00
|
|
|
#define ENCODING_COUNT <%=count%>
|