2 # OnigEncodingDefine(foo, Foo) = {
4 # "Shift_JIS", /* Canonical Name */
7 # ENC_ALIAS("SJIS", "Shift_JIS")
8 # ENC_REPLICATE("Windows-31J", "Shift_JIS")
9 # ENC_ALIAS("CP932", "Windows-31J")
12 def check_duplication(defs, name, fn, line)
14 raise ArgumentError, "%s:%d: encoding %s is already registered(%s:%d)" %
15 [fn, line, name, *defs[name]]
17 defs[name.upcase] = [fn,line]
26 outhdr = encdirs.shift || 'encdb.h'
27 encdirs << 'enc' if encdirs.empty?
29 encdirs.each do |encdir|
30 next unless File.directory?(encdir)
31 Dir.open(encdir) {|d| d.grep(/.+\.[ch]\z/)}.sort_by {|e|
32 e.scan(/(\d+)|(\D+)/).map {|n,a| a||[n.size,n.to_i]}.flatten
36 open(File.join(encdir,fn)) do |f|
40 if (/^OnigEncodingDefine/ =~ line)..(/"(.*?)"/ =~ line)
42 check_duplication(defs, $1, fn, $.)
48 when /^\s*rb_enc_register\(\s*"([^"]+)"/
51 when /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/
53 '%s:%d: ENC_REPLICATE: %s is not defined yet. (replica %s)' %
54 [fn, $., $2, $1] unless defs[$2.upcase]
56 when /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/
58 '%s:%d: ENC_ALIAS: %s is not defined yet. (alias %s)' %
59 [fn, $., $2, $1] unless defs[$2.upcase]
60 when /^ENC_DUMMY\(\s*"([^"]+)"/
65 check_duplication(defs, $1, fn, $.)
66 lines << line.sub(/;.*/m, "").chomp + ";\n" if line
73 result = encodings.map {|e| %[ENC_DEFINE("#{e}");\n]}.join + lines.join +
74 "\n#define ENCODING_COUNT #{count}\n"
75 open(outhdr, 'wb') do |f|