aboutsummaryrefslogtreecommitdiffstats
path: root/template
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-13 09:05:29 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-13 09:05:29 +0000
commite668e36b49b38d6d422c6e9d4b3eddd374bcbb15 (patch)
treea50eeca907825118f10b1948c534ce30b1535faa /template
parent4cb8d3316afc452993d8e6d26e2818f412b400a2 (diff)
downloadruby-e668e36b49b38d6d422c6e9d4b3eddd374bcbb15.tar.gz
* template/{encdb,transdb}.h.tmpl: moved enc/make_encdb.rb and
enc/trans/make_transdb.rb using tool/generic_erb.rb. * common.mk (encdb.h, transdb.h): generates from avobe template. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'template')
-rw-r--r--template/encdb.h.tmpl79
-rw-r--r--template/transdb.h.tmpl59
2 files changed, 138 insertions, 0 deletions
diff --git a/template/encdb.h.tmpl b/template/encdb.h.tmpl
new file mode 100644
index 0000000000..e65b651050
--- /dev/null
+++ b/template/encdb.h.tmpl
@@ -0,0 +1,79 @@
+<%
+#
+# OnigEncodingDefine(foo, Foo) = {
+# ..
+# "Shift_JIS", /* Canonical Name */
+# ..
+# };
+# ENC_ALIAS("SJIS", "Shift_JIS")
+# ENC_REPLICATE("Windows-31J", "Shift_JIS")
+# ENC_ALIAS("CP932", "Windows-31J")
+#
+
+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]
+ end
+end
+
+count = 0
+lines = []
+encodings = []
+defs = {}
+encdirs = ARGV.dup
+encdirs << 'enc' if encdirs.empty?
+files = {}
+encdirs.each do |encdir|
+ next unless File.directory?(encdir)
+ 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|
+ orig = nil
+ name = nil
+ f.each_line do |line|
+ if (/^OnigEncodingDefine/ =~ line)..(/"(.*?)"/ =~ line)
+ if $1
+ check_duplication(defs, $1, fn, $.)
+ encodings << $1
+ count += 1
+ end
+ else
+ 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]
+ when /^ENC_DUMMY\(\s*"([^"]+)"/
+ count += 1
+ else
+ next
+ end
+ check_duplication(defs, $1, fn, $.)
+ lines << line.sub(/;.*/m, "").chomp + ";" if line
+ end
+ end
+ end
+ end
+end
+encodings.each do |e|
+%>ENC_DEFINE("<%=e%>");
+% end
+% lines.each do |line|
+<%=line%>
+% end
+
+#define ENCODING_COUNT <%=count%>
diff --git a/template/transdb.h.tmpl b/template/transdb.h.tmpl
new file mode 100644
index 0000000000..d0cf101344
--- /dev/null
+++ b/template/transdb.h.tmpl
@@ -0,0 +1,59 @@
+<%
+#
+# static const rb_transcoder
+# rb_from_US_ASCII = {
+# "US-ASCII", "UTF-8", &from_US_ASCII, 1, 0,
+# NULL, NULL,
+# };
+#
+
+count = 0
+converters = {}
+transdirs = ARGV.dup
+transdirs << 'enc/trans' if transdirs.empty?
+
+transdirs = transdirs.sort_by {|td|
+ -td.length
+}.inject([]) {|tds, td|
+ next tds unless File.directory?(td)
+ tds << td if tds.all? {|td2| !File.identical?(td2, td) }
+ tds
+}
+
+files = {}
+names_t = []
+converter_list = []
+transdirs.each do |transdir|
+ names = Dir.entries(transdir)
+ names_t += names.map {|n| /(?!\A)\.trans\z/ =~ n ? $` : nil }.compact
+ names_c = names.map {|n| /(?!\A)\.c\z/ =~ n ? $` : nil }.compact
+ (names_t & names_c).map {|n|
+ "#{n}.c"
+ }.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
+ path = File.join(transdir,fn)
+ open(path) 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 at %s:%d' %
+ [path, $., from_to, *converters[from_to].values_at(3, 4)]
+ else
+ converters[from_to] = [$1, $2, fn[0..-3], path, $.]
+ converter_list << from_to
+ end
+ end
+ end
+ end
+ end
+ end
+end
+converter_list.each do |from_to|
+ from, to, fn = *converters[from_to]
+%>rb_declare_transcoder("<%=from%>", "<%=to%>", "<%=fn%>");
+% end