summaryrefslogtreecommitdiff
path: root/jni/ruby/template/transdb.h.tmpl
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/template/transdb.h.tmpl
Fresh start
Diffstat (limited to 'jni/ruby/template/transdb.h.tmpl')
-rw-r--r--jni/ruby/template/transdb.h.tmpl59
1 files changed, 59 insertions, 0 deletions
diff --git a/jni/ruby/template/transdb.h.tmpl b/jni/ruby/template/transdb.h.tmpl
new file mode 100644
index 0000000..d0cf101
--- /dev/null
+++ b/jni/ruby/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