[前][次][番号順一覧][スレッド一覧]

ruby-changes:9949

From: nobu <ko1@a...>
Date: Tue, 13 Jan 2009 18:05:43 +0900 (JST)
Subject: [ruby-changes:9949] Ruby:r21490 (trunk): * template/{encdb,transdb}.h.tmpl: moved enc/make_encdb.rb and

nobu	2009-01-13 18:05:29 +0900 (Tue, 13 Jan 2009)

  New Revision: 21490

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21490

  Log:
    * 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.

  Added files:
    trunk/template/encdb.h.tmpl
    trunk/template/transdb.h.tmpl
  Removed files:
    trunk/enc/make_encdb.rb
    trunk/enc/trans/make_transdb.rb
  Modified directories:
    trunk/enc/trans/
  Modified files:
    trunk/common.mk

Index: enc/make_encdb.rb
===================================================================
--- enc/make_encdb.rb	(revision 21489)
+++ enc/make_encdb.rb	(revision 21490)
@@ -1,77 +0,0 @@
-#
-# 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
-outhdr = encdirs.shift || 'encdb.h'
-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 + ";\n" if line
-        end
-      end
-    end
-  end
-end
-
-result = encodings.map {|e| %[ENC_DEFINE("#{e}");\n]}.join + lines.join + 
-  "\n#define ENCODING_COUNT #{count}\n"
-open(outhdr, 'wb') do |f|
-  f.print result
-end
Index: enc/trans/make_transdb.rb
===================================================================
--- enc/trans/make_transdb.rb	(revision 21489)
+++ enc/trans/make_transdb.rb	(revision 21490)
@@ -1,61 +0,0 @@
-#
-# 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
-outhdr = transdirs.shift || 'transdb.h'
-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
-result = converter_list.map do |from_to|
-  %[rb_declare_transcoder("%s", "%s", "%s");\n] % converters[from_to]
-end.join("")
-open(outhdr, 'wb') do |f|
-  f.print result
-end

Property changes on: enc/trans
___________________________________________________________________
Name: svn:ignore
   - single_byte.c
korean.c
utf_16_32.c
japanese.c
japanese_euc.c
japanese_sjis.c
iso2022.c
newline.c
escape.c
gbk.c
chinese.c
big5.c

   + *.c


Index: common.mk
===================================================================
--- common.mk	(revision 21489)
+++ common.mk	(revision 21490)
@@ -647,13 +647,11 @@
 
 node_name.inc: {$(VPATH)}node.h
 
-encdb.h: $(PREP)
-	$(MINIRUBY) $(srcdir)/enc/make_encdb.rb $@.new $(srcdir)/enc enc
-	$(IFCHANGE) "$@" "$@.new"
+encdb.h: $(PREP) $(srcdir)/tool/generic_erb.rb $(srcdir)/template/encdb.h.tmpl
+	$(MINIRUBY) $(srcdir)/tool/generic_erb.rb -c -o $@ $(srcdir)/template/encdb.h.tmpl $(srcdir)/enc enc
 
-transdb.h: $(PREP) srcs-enc
-	$(MINIRUBY) $(srcdir)/enc/trans/make_transdb.rb $@.new $(srcdir)/enc/trans enc/trans
-	$(IFCHANGE) "$@" "$@.new"
+transdb.h: $(PREP) srcs-enc $(srcdir)/tool/generic_erb.rb $(srcdir)/template/transdb.h.tmpl
+	$(MINIRUBY) $(srcdir)/tool/generic_erb.rb -c -o $@ $(srcdir)/template/transdb.h.tmpl $(srcdir)/enc/trans enc/trans
 
 # {$(VPATH)}id.h: {$(VPATH)}parse.h $(srcdir)/tool/generic_erb.rb $(srcdir)/template/id.h.tmpl
 # 	$(BASERUBY) $(srcdir)/tool/generic_erb.rb --if-change --output=$@ \
Index: template/encdb.h.tmpl
===================================================================
--- template/encdb.h.tmpl	(revision 0)
+++ template/encdb.h.tmpl	(revision 21490)
@@ -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%>

Property changes on: template/encdb.h.tmpl
___________________________________________________________________
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + LF
Name: svn:keywords
   + Author Date Id Revision

Index: template/transdb.h.tmpl
===================================================================
--- template/transdb.h.tmpl	(revision 0)
+++ template/transdb.h.tmpl	(revision 21490)
@@ -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

Property changes on: template/transdb.h.tmpl
___________________________________________________________________
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + LF
Name: svn:keywords
   + Authors Id Revision


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]