From 318b4f3d55bf89044577d20f86be7350ef679fa6 Mon Sep 17 00:00:00 2001 From: ellson Date: Fri, 12 Sep 2008 11:58:36 +0000 Subject: [PATCH] fix to complete the ruby demo from: Patricio Ros --- tclpkg/gv/demo/modgraph.rb | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tclpkg/gv/demo/modgraph.rb b/tclpkg/gv/demo/modgraph.rb index ac4615415..6c24a5df2 100755 --- a/tclpkg/gv/demo/modgraph.rb +++ b/tclpkg/gv/demo/modgraph.rb @@ -2,7 +2,8 @@ # display the kernel module dependencies -# author: John Ellson +#author: Patricio Ros +# based on: modgraph.tcl by John Ellson require 'gv' @@ -20,23 +21,14 @@ Gv.setv(N, 'fontsize', '8') Gv.setv(N, 'fontname', 'helvetica') Gv.setv(E, 'arrowsize', '.4') -f = File.open('/proc/modules', mode="r") -while ! f.eof do - rec = f.gets() - -#FIXME - complete translation to ruby - -# for mod, usedbylist in string.gfind(rec, "([_%w]+) %w+ %w+ ([-,_%w]+)") do -# n = gv.node(G, mod) -# for usedby in string.gfind(usedbylist, "([-_%w]+)") do -# if (usedby ~= '-') and (usedby ~= '') then -# gv.edge(n, gv.node(G, usedby)) -# end -# end -# end - -end -f.close +File.readlines("/proc/modules").each do |rec| + fields = rec.split(' ') + n = Gv.node(G, fields[0]) + fields[3].split(',').find_all {|i| not ['-',' '].include? i}.each do |usedby| + Gv.edge(n, Gv.node(G, usedby)) + end +end Gv.layout(G, 'dot') Gv.render(G, 'xlib') + -- 2.40.0