#!/usr/bin/ruby -w

node_hash = Hash.new

edges_hash = Hash.new

ARGV.each do |filename|

  open( filename ) do |f|

    filename = filename.gsub( /.dot/, '' )

    f.each do |line|
      line.strip!
      if line =~ /^\s*\"(.*?)\" -- \"(.*?)\"/
        nodes = [ $1, $2 ]
        nodes.sort!
        k = "\"#{nodes[0]}\" -- \"#{nodes[1]}\""
        unless edges_hash.has_key? k
          edges_hash[k] = []
        end
        unless edges_hash[k].include? filename
          edges_hash[k].push filename
        end
      elsif line =~ /^\s*(.*fillcolo.*)/
        node_hash[$1] = true
      end
    end


  end
end

print <<EOFHEADER
graph G {
	graph [overlap=scale,splines=true];
	node [fontname="DejaVuSans",style=filled];
EOFHEADER

node_hash.each_key do |k|
  puts "\t#{k}"
end

edges_hash.each_pair do |k,a|
  # label = "#{a.length}\\n#{a.join('\n')}"
  label = a.join('\n')
  puts "\t#{k} [label=\"#{label}\" fontsize=4];"
end

print <<EOFOOTER
}
EOFOOTER
