#!/usr/bin/env perl
# Script for generating a library dependency graph (requires dot)
# Based on code wriiten by George Hagen (NASA)
use Getopt::Long;
use File::Basename;
@prelude = ("bitvector", "finite_sets");
$usageln = "Usage: dependencygraph [--help] [;
sub usage() {
print <<EOF;
dependencygraph -- generates a library dependency graph for <file>.
This script builds a dot graph of library dependecies. It will then call
Graphviz's dot utility on that file to produce a pdf graph.
$usageln
<option> is
--dot don't generate PDF unless --pdf is specified
--pdf generate a pdf file (default)
--title=<string> use <string> as the title of the graph
--out=<outfile> use <outfile> as name of the output file
--zoom=<dir1>,...,<dirn> zoom into libraries <dir1>,...,<dirn>
--help print this message
--after=<dir> process all libraries after <dir>, exclusive
--before=<dir> process all libraries before <dir>, exclusive
--but=<dir1>,..,<dirn> do not process libraries <dir1>,...,<dirn>
--do=all process all libraries. This is the default,
except when the option --zoom is also specified
--do=<dir1>,..,<dirn> process libraries <dir1>,...,<dirn>
--from=<dir> process all libraries from <dir>, inclusive
--to=<dir> process all libraries to <dir>, inclusive
--top=<topfile> specify name of the top file directory
File <file> is an ordered list of libraries as used by the script provethem.
By default <file> is nasalib.all. If <outfile> is not specified,
<file><postfix> is used. The <postfix> depends on library selection option, i.e.,
--do,--but,--from,--to,--after,--before,--zoom. When the option --zoom is
used in conjunction with one of the other options, the libraries that are selected,
except for those in --zoom, will appear unzoomed in the dependency graph.
except when the option zoom is used.
EOF
exit;
}
sub deslash($)
{
my $string = shift;
$string =~ s|/||g;
return $string;
}
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
sub writeedge {
my ($from, $to) = @_;
if (!(grep {$_ eq $to} @prelude)) {
print "*** Warning: Library $to is out of order. It should appear before $from in $file\n"
if !(grep {$_ eq $to} @nodes) && (grep {$_ eq $to} @libraries);
push(@external,$to)
if !(grep {$_ eq $to} @libraries) &&
!(grep {$_ eq $to} @external);
$graph .= " \"$from\" -> \"$to\";\n";
}
}
sub writesubgraph {
my ($lib, $from, $tos) = @_;
@tolist = split /,/,$tos;
foreach $to (@tolist) {
@libto = split /@/,$to;
if ($libto[1] && !(grep {$_ eq $libto[0]} @prelude)) {
if (grep {$_ eq $libto[0]} @libraries) {
print "*** Warning: Library $libto[0] is out of order. It should appear before $lib in $file\n"
if !(grep {$_ eq $libto[0]} @nodes);
$subgraph{$lib} .= " \"$from\" -> \"$libto[1]\";\n";
} else {
writeedge($from,$to);
}
} elsif (!$libto[1]) {
$subgraph{$lib} .= " \"$from\" -> \"$to\";\n";
}
}
}
die "$file is a directory\n" if -d $file;
open (INFILE,$file) || die "File $file doesn't exist\n";
if (!$out) {
my ($base,$path,$type) = fileparse($file,qr{\..*});
$out = "$path$base";
my $dol = join('_',@dolist);
$out .= "-$dol" if $dol;
my $butl = join('_',@butlist);
$out .= "-but_$butl" if $butl;
$out .= "-from_$from" if $from;
$out .= "-to_$to" if $to;
$out .= "-after_$after" if $after;
$out .= "-below_$below" if $below;
my $zooml = join('_',@zoomlist);
$out .= "-zoom_$zooml" if $zooml;
}
my ($graphname,$path,$type) = fileparse($out);
$graphname =~ s/-/_/g;
open(DOT,">$out.dot") or die "can't open $out.dot\n";
print DOT "digraph $graphname {\n";
if ($title) {
print DOT "labelloc=\"t\"";
print DOT "label=\"$title\"";
}
print DOT " rankdir=LR;\n";
#print DOT " node [shape=box]\n" if !$zoom;
print DOT " concentrate=true;\n";
print DOT " splines=true;\n"; # splines=ortho for a more circuit diagram form, splines=true for default curves
print DOT $graph;
print DOT "}\n";
close(DOT);
print "File $out.dot has been generated\n" if $dot;
if (!$dot || $pdf) {
die "To produce $out.pdf, install Graphviz and add it to PATH\n" if !`which dot`;
`dot -Tpdf $out.dot -o $out.pdf`;
print "File $out.pdf has been generated\n";
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.