<commit_before>#!/usr/bin/perl

# display the kernel module dependencies

# author: <NAME> <<EMAIL>>

use gv;

$G = gv::digraph("G");
$N = gv::protonode($G);
$E = gv::protoedge($G);

gv::setv($G, "rankdir", "LR");
gv::setv($G, "nodesep", "0.05");
gv::setv($N, "shape", "box");
gv::setv($N, "width", "0");
gv::setv($N, "height", "0");
gv::setv($N, "margin", ".03");
gv::setv($N, "fontsize", "8");
gv::setv($N, "fontname", "helvetica");
gv::setv($E, "arrowsize", ".4");

#FIXME - complete translation to perl

#f = File.open('/proc/modules', mode="r")
#while ! f.eof do
#	rec = f.gets()
#
#    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

gv::layout($G, "dot");
gv::render($G, "xlib");<commit_msg>some incremental improvements from Max Baker <<EMAIL>> but this doesn't show the edges to dependents properly<commit_after>#!/usr/bin/perl -w
# #!/usr/local/bin/perl -w
# Change ^^ to the version of Perl you installed the SWIG modules / Graphviz with
#
# Change this to point to your installed graphviz lib dir
#   Normally either /usr/local/lib/graphviz/perl or /usr/lib/graphviz/perl
#use lib '/home/maxb/lib/graphviz/perl';
use gv;

use Getopt::Long;
GetOptions(\%Args, 'h|help','d|debug');
$Debug   = $Args{d} || 0;
$Modules = shift @ARGV || '/proc/modules';

die &usage if $Args{h};
die "Cannot read $Modules. $!\n" unless (-r $Modules);

$G = gv::digraph("G");
$N = gv::protonode($G);
$E = gv::protoedge($G);

gv::setv($G, "rankdir", "LR");
gv::setv($G, "nodesep", "0.05");
gv::setv($N, "shape", "box");
gv::setv($N, "width", "0");
gv::setv($N, "height", "0");
gv::setv($N, "margin", ".03");
gv::setv($N, "fontsize", "8");
gv::setv($N, "fontname", "helvetica");
gv::setv($E, "arrowsize", ".4");

open (M,"<$Modules") or die "Can't open $Modules. $!\n";
while (<M>) {
    chomp;
    # parport                36832   1 (autoclean) [parport_pc lp]
    my @f = split(/\s+/);
    # Should be at least three columns
    next unless scalar @f >= 3;

    my $module  = shift @f;
    my $size    = shift @f;
    my $used_by = shift @f;
    my $deps    = join (' ',@f);

    Debug("$module");
    my $n = gv::node($G,$module);

    # look for and get rid of brackets.  ignore parens, etc.
    if ($deps =~ s/\[(.*)\]/$1/) {
        foreach my $dep (split(/\s+/,$deps)) {
            Debug(" $dep -> $module");
            gv::edge($n, gv::node($G, $dep) );
        }
    }
}

gv::layout($G, "dot");
gv::render($G, "xlib");

sub Debug {
    return unless $Debug;
    warn join(" ",@_), "\n";
}

sub usage {
    return << "end_usage";
modgraph.pl

Displays Linux kernel module dependencies from $Modules

Author:    <NAME> <<EMAIL>>
Perl Port: Max Baker <<EMAIL>>

Usage: $0 [--debug] [/proc/modules]

end_usage
}
{'fraction_non_alphanumeric': 0.23823924731182797, 'fraction_numerical': 0.009408602150537635, 'mean_word_length': 3.436661698956781, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1177255', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1220, 'n_words': 312}