Skip to content

Instantly share code, notes, and snippets.

@jl2
Created March 12, 2011 00:32
Show Gist options
  • Save jl2/866863 to your computer and use it in GitHub Desktop.
Save jl2/866863 to your computer and use it in GitHub Desktop.
##!/usr/bin/ruby
# Quick and dirty C++ inheritance tree using GraphViz's dot command
# Limitations:
# * Only handles single inheritance
# * Base classes must be specified on a single line:
# Such as "class Foo : public Bar"
require "find"
ofile = ARGV.shift
IO.popen("dot -Tsvg -o" + ofile, mode="w") do | dot |
dot.puts "digraph G {"
dot.puts "rankdir=BT;"
ARGV.each do | dir |
Find.find(dir) do | f |
Find.prune if f == "."
# puts "Processing \"" + f + "\""
if f =~ /\.h$/ then
IO.foreach(f) do | ln |
if ln =~ /class *.* +(\w+)\s+:\s+public\s+(\w+)\s*$/ then
derived = $1
base = $2
dot.puts derived + " -> " + base + ";"
end
end
end
end
end
dot.puts "}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment