[qt_honey][117] merge-simple.rb implemented.

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2013年 6月 9日 (日) 11:42:44 JST


Revision: 117
          http://sourceforge.jp/projects/cres/scm/svn/commits/117
Author:   masao
Date:     2013-06-09 11:42:44 +0900 (Sun, 09 Jun 2013)
Log Message:
-----------
merge-simple.rb implemented.

Modified Paths:
--------------
    cmap/graph.rb

Added Paths:
-----------
    cmap/merge-simple.rb

Modified: cmap/graph.rb
===================================================================
--- cmap/graph.rb	2011-11-20 18:16:29 UTC (rev 116)
+++ cmap/graph.rb	2013-06-09 02:42:44 UTC (rev 117)
@@ -416,24 +416,25 @@
       g
    end
 
-
    def to_dot( attr = {} )
       done = {}
       str = "digraph {\n"
       each_node do |n|
+         escaped_n = escape( n )
          # node_attr = { :label => @node_labels[ n ] }
          if attr[n]
             attr_s = attr[n].keys.sort.map{|e| %Q|#{e}="#{attr[n][e]}"| }.join(",")
-            str << "#{ n } [ #{attr_s} ]\n"
+            str << "#{ escaped_n } [ #{attr_s} ]\n"
          end
          if edges_to[ n ]
             edges_to[ n ].each do |n2|
+               escaped_n2 = escape( n2 )
                pair = Set[ n, n2 ]
                if attr[ pair ]
                   attr_s = attr[ pair ].keys.sort.map{|e| %Q|#{e}="#{attr[pair][e]}"| }.join(",")
-                  str << "#{ n } -> #{ n2 } [ #{attr_s} ]\n"
+                  str << "#{ escaped_n } -> #{ escaped_n2 } [ #{attr_s} ]\n"
                else
-                  str << "#{ n } -> #{ n2 }\n"
+                  str << "#{ escaped_n } -> #{ escaped_n2 }\n"
                end
             end
          end
@@ -441,6 +442,15 @@
       str << "}"
       str
    end
+
+   private
+   def escape( str )
+      case str
+      when /[\(\)\&\?\-\%\.]/, /\A\d/
+         str = %Q["#{ str }"]
+      end
+      str
+   end
 end
 
 if $0 == __FILE__

Added: cmap/merge-simple.rb
===================================================================
--- cmap/merge-simple.rb	                        (rev 0)
+++ cmap/merge-simple.rb	2013-06-09 02:42:44 UTC (rev 117)
@@ -0,0 +1,62 @@
+#!/usr/bin/env ruby
+# -*- coding: utf-8 -*-
+
+require "stringio"
+
+$:.unshift File.join( File.dirname( __FILE__ ) )
+require "graph.rb"
+
+module CMapUtils
+   DEFAULT_NODE_ATTR = " POINT-SIZE=\"9\" FACE=\"times\""
+   def to_simple_merged_dot( files, style = {} )
+      total = DirectedGraph.new
+      result = "digraph G{\n"
+      files.each do |file|
+	 graph_io = open( file )
+         # check if contents includes BOM snippets.
+         cont = graph_io.read
+         if cont[ 0, 3 ] == "\xEF\xBB\xBF"
+            STDERR.puts "BOM detected."
+            graph_io = StringIO.new( cont[ 3..-1 ] )
+         else
+            graph_io.rewind
+         end
+	 graph = DirectedGraph.load_dot2( graph_io, true, true )
+         #p graph.nodes
+         graph.each_node do |node|
+            #p graph
+            #p node
+            #p [node, graph.node_labels[ node ] ]
+            #puts graph.canonical_node_label( node, true )
+            label = get_label( graph.node_labels[ node ] )
+            #puts label
+            total.add_node( label )
+            if graph.edges_to[ node ]
+               graph.edges_to[ node ].each do |node2|
+                  label2 = get_label( graph.node_labels[ node2 ] )
+                  total.add_node( label2 )
+                  total.add_edge( label, label2 )
+               end
+            end
+         end
+      end
+      #p total.nodes
+      total.to_dot
+   end
+
+   private
+   def get_label( n )
+      label = n
+      label = $1 if label =~ /\A\w+:(.+)\Z/
+      label
+   end
+end
+
+if $0 == __FILE__
+   if ARGV.empty?
+      puts "  Usage:  #{ $0 } foo.dot ..."
+      exit
+   end
+   include CMapUtils
+   puts to_simple_merged_dot( ARGV )
+end


Property changes on: cmap/merge-simple.rb
___________________________________________________________________
Added: svn:executable
   + *




Cres-cvs メーリングリストの案内
Back to archive index