ruby生成C++头文件引用关系图
生活随笔
收集整理的這篇文章主要介紹了
ruby生成C++头文件引用关系图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先生成graphviz的dot格式文件
require 'find'
class RefNodeattr_accessor :name,:reference
end
include Find
if __FILE__ == $0name = "name"dot = []h = Hash.newputs ["digraph #{name}{","overlap = false","spline = true","ranksep=1.5"].join("\n")Find.find('XX/dir1','XX/dir2') do |path|path = path.downcaseif (path.end_with?(".h") && !path.end_with?("stdafx.h"))headers = []File.readlines(path).each do |line|line = linebeginm = /^\s*#include\s+"(.*?)"\s*/.match(line)rescuebeginm = /^\s*#include\s+"(.*?)"\s*/u.match(line)rescueendendif (m)headers<<File.basename(m[1]).downcaseendendheaders.each do |header|if h.key?(header)h[header]<<File.basename(path);elseh[header] = []endendendendh.keys.each do |key|if (h[key].size > 3)src = key#sprintf("%d %s",h[key].size,key)color = sprintf("%.4f,%.4f,%.4f",1 - h[key].size/150.0,1 - h[key].size/150.0,1 - h[key].size/150.0)dot << sprintf("\nnode[color=\"%s\"]\nedge[color=\"%s\"]\n\"%s\"",color,color,src)h[key].each do |header|dot << sprintf("\t\"%s\"->\"%s\"",header,src)endendendputs dot.join("\n") puts "}\n"end
生成格式大概是這樣的
node[color="0.9733,0.9733,0.9733"]
edge[color="0.9733,0.9733,0.9733"]
"tagnode.h"
"tagdocument.h"->"tagnode.h"
"tagelement.h"->"tagnode.h"
"tagnodecollection.h"->"tagnode.h"
然后調用graphviz 的命令行 fdp -Tpng XX.dot -o XX.png這樣調用關系就生成了
轉載于:https://www.cnblogs.com/marryZhan/archive/2011/10/17/2215148.html
總結
以上是生活随笔為你收集整理的ruby生成C++头文件引用关系图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《学习vi编辑器》的学习笔记1
- 下一篇: 最老程序员创业札记:全文检索、数据挖掘、