[qt_honey][124] introduce -unify option: specify -unify option if considering "unifying" nodes.

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2013年 8月 20日 (火) 17:01:26 JST


Revision: 124
          http://sourceforge.jp/projects/cres/scm/svn/commits/124
Author:   masao
Date:     2013-08-20 17:01:25 +0900 (Tue, 20 Aug 2013)
Log Message:
-----------
introduce -unify option: specify -unify option if considering "unifying" nodes.

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

Modified: cmap/diff.rb
===================================================================
--- cmap/diff.rb	2013-07-06 08:16:12 UTC (rev 123)
+++ cmap/diff.rb	2013-08-20 08:01:25 UTC (rev 124)
@@ -6,7 +6,7 @@
 require "graph.rb"
 
 module CMapUtils
-   def statistics_merged_cmaps( io_pre, io_post )
+   def statistics_merged_cmaps( io_pre, io_post, options = { :unified => true } )
       result = {}
       pre  = DirectedGraph.load_dot2( io_pre, true )
       post = DirectedGraph.load_dot2( io_post, true )
@@ -16,16 +16,16 @@
 
       nodes = {}
 
-      pre_cnodes  = pre.canonical_node_labels
-      post_cnodes = post.canonical_node_labels
+      pre_cnodes  = pre.canonical_node_labels( options[ :unified ] )
+      post_cnodes = post.canonical_node_labels( options[ :unified ] )
       nodes[ :common ] =  pre_cnodes & post_cnodes
       #nodes[ :common ]  = pre.nodes & post.nodes
       nodes[ :lost ] = pre_cnodes - post_cnodes
       nodes[ :new ]   = post_cnodes - pre_cnodes
       result[ :nodes ] = nodes
 
-      pre_e  = pre.canonical_links_set
-      post_e = post.canonical_links_set
+      pre_e  = pre.canonical_links_set( options[ :unified ] )
+      post_e = post.canonical_links_set( options[ :unified ] )
       links = {}
       links[ :common ] = pre_e & post_e
       links[ :lost ] = pre_e - post_e
@@ -100,11 +100,18 @@
 end
 
 if $0 == __FILE__
+   unified = nil
+   if ARGV[0] =~ /\A-+unify/
+      unified = true
+      ARGV.shift
+      p ARGV
+   end
    if ARGV[0].nil? or ARGV[1].nil?
       puts "  Usage:  #{ $0 } pre.dot post.dot"
       exit
    end
    include CMapUtils
-   data = statistics_merged_cmaps( open( ARGV[0] ), open( ARGV[1] ) )
+   data = statistics_merged_cmaps( open( ARGV[0] ), open( ARGV[1] ),
+                                   { :unified => unified } )
    print_statistics( data )
 end

Modified: cmap/graph.rb
===================================================================
--- cmap/graph.rb	2013-07-06 08:16:12 UTC (rev 123)
+++ cmap/graph.rb	2013-08-20 08:01:25 UTC (rev 124)
@@ -1,5 +1,5 @@
 #!/usr/bin/env ruby
-# -*- coding: utf-8 -*-
+# -*- coding: ascii-8bit -*-
 
 require "open3"
 require "set"
@@ -54,12 +54,16 @@
       label = n
       if @node_labels[ n ]
          label = @node_labels[ n ]
-         if unified and label =~ /\A(\w+):(.*)\Z/
-            label = $1
-            if @canonical_label_mapping[ $1 ] and @canonical_label_mapping[ $1 ] != $2
-               @canonical_label_mapping[ $1 ] << "\t"+ $2
+         if label =~ /\A(\w+):(.*)\Z/
+            if unified
+               label = $1
+               if @canonical_label_mapping[ $1 ] and @canonical_label_mapping[ $1 ] != $2
+                  @canonical_label_mapping[ $1 ] << "\t"+ $2
+               else
+                  @canonical_label_mapping[ $1 ] = $2
+               end
             else
-               @canonical_label_mapping[ $1 ] = $2
+               label = $2
             end
          end
       end
@@ -381,7 +385,9 @@
       #STDERR.puts f
       root_node = false
       pin, pout, perr, = *Open3.popen3( "dot", "-Tplain" )
+      io.set_encoding( "ASCII-8BIT" )
       cont = io.read
+      #STDERR.puts cont[ 0, 3 ].inspect
       if cont[ 0, 3 ] == "\xEF\xBB\xBF"
          STDERR.puts "BOM detected."
          cont = cont[ 3..-1 ]




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