Created
October 6, 2015 22:34
-
-
Save sbeyer/742f24f3b1ef8fc5e8e6 to your computer and use it in GitHub Desktop.
Generating a graph (DOT format) from C/C++ includes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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