Skip to content

Instantly share code, notes, and snippets.

@sbeyer
Created October 6, 2015 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbeyer/742f24f3b1ef8fc5e8e6 to your computer and use it in GitHub Desktop.
Save sbeyer/742f24f3b1ef8fc5e8e6 to your computer and use it in GitHub Desktop.
Generating a graph (DOT format) from C/C++ includes
#!/usr/bin/env ruby
# Output a DOT file of the include structure of a project
#
# Usage:
# cd <the include path of the project>
# <path of this script>/make-include-graph.rb > includes.dot
require 'find'
def output_edges(path)
File.open(path) do |f|
f.each_line do |line|
match = line.match(/^\s*#\s*include\s*[<"](.*)[">]/)
if match
puts "\t\"#{path}\" -> \"#{match[1]}\";"
end
end
end
end
puts 'digraph includes {'
Find.find('.') do |path|
unless FileTest.directory?(path)
path = path[2..-1]
output_edges(path)
end
end
puts '}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment