From: Eric Hodel Date: 2005-11-05T10:26:46+09:00 Subject: Re: Turning `make --debug=b` into a graph On Nov 4, 2005, at 1:27 PM, Bil.Kleb@gmail.com wrote: > Hello, > > My lack of computer science training > is showing: It seems like turning the > sample output shown after my signature > into a Graphviz dot graph should be easy, > but I can't find an elegant way of doing it. > > Can someone lend an algorithm? > > Foundation: > > sudo gem install rgl > > require 'rgl/adjacency' > require 'rgl/dot' > > dg = RGL::DirectedAdjacencyGraph.new > dg.add_edge( from, to ) > dg.write_to_graphic_file RGL looks like too much typing, so I used lib/graph.rb from ZenHacks: $ ruby make_graph.rb data.txt > kleb.dot $ open kleb.dot [ http://flickr.com/photo_zoom.gne?id=59864477&size=m you can download the full-size 5498x735 px version there as well. ] $ cat make_graph.rb require 'graph' data = ARGF.readlines graph = Graph.new last_indent = 1 parents = [data.shift.strip] last_node = nil data.each do |line| line =~ /^(\s+)(.*)/ node = $2 indent = $1.length.to_i / 2 - 1 parents[indent] = last_node if last_indent < indent graph[parents[indent]] << node last_indent = indent last_node = node end puts graph.to_s -- Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04