All pastes #462450 Raw Edit

Someone

public ruby v1 · immutable
#462450 ·published 2007-04-28 09:22 UTC
rendered paste body
#!/usr/local/bin/ruby#jasscg.rb - generate a graphviz graph#use:  cat file1.j file2.j | ruby jasscg.rb | dot -T png -o dep.png@calls = {}keywords = { "if", "elseif" }STDIN.readlines.each{|l| l.sub(/\/\/.*/,"")}.join("").gsub(/"[^"\\]*(\\.[^"\\]*)*"/,"").split("\n").each {|l|	f = l.slice(/^\s*function\s+\w+/)	if l =~ /^\s*globals/ then		@func = "globals"		@calls[@func] = {} unless @calls.has_key?(@func)	elsif f == nil then		calls = l.scan(/\w+\s*\(/).each {|f| f = f.scan(/\w+/)[0]; @calls[@func][f] = true unless keywords.has_key?(f)}	else		@func = f.slice(/\w+$/)		@calls[@func] = {}	end}def draw_node(key)	if not @already_drawn.has_key?(key) then		@already_drawn[key] = true		print key + " [label=\""+key+"\",fillcolor=\"#f8c85c\"];\n"	endenddef draw()	@already_drawn = {}	print "digraph G {\n"	print " ranksep=1.0;\n"	print "node [stype=filled,fontname=Helvetica,fontsize=10];\n"	@calls.each {|k,v|		draw_node(k)		v.each_key {|dep|			draw_node(dep)			print k + " -> " + dep + "\n"		}	}	print "}\n"enddraw()