#!/usr/bin/env perl # # phprefs2dot - creates a (sloppily parsed) graph of PHP cross-file references # # $Id$ # # e.g. as used for the Petriweb code: # phprefs2dot verwerkpnml.php approve*.php addnetvalues.php toon*.php | # fgrep -v .inc. | dot -Tps \ # -Gsize='7,10' -Grankdir=LR -Gratio=1 -Gcenter=1 -Ecolor=blue -Efontcolor=blue use strict; use warnings; use Cwd 'realpath'; use File::Spec::Functions qw(abs2rel rel2abs catdir splitpath); my $now = gmtime(); $0 =~ m#[^/]+$#; my $me = $&; print "// generated by $me at $now\n\n"; print "digraph phprefs {\n"; #print " size=\"6,6\"\n"; # not here; supply such details on the dot/neato command line ... sub safe_realpath { -e $_[0] ? realpath( $_[0] ) : "$_[0] (not found)"; } my $cwd = &safe_realpath('.'); while (<>) { if (m#^\s*//#) { #a comment - skip } elsif (m#(location|include|require|action|a\s+href).*[^\w./]([\w./]+\.php)#i) { my ( $src, $tgt, $type ) = ( &safe_realpath($ARGV), $2, lc($1) ); $tgt = rel2abs( $tgt, catdir( ( splitpath($src) )[1] ) ); ( $src, $tgt ) = ( &safe_realpath($src), &safe_realpath($tgt) ); ( $src, $tgt ) = ( abs2rel( $src, $cwd ), abs2rel( $tgt, $cwd ) ); printf ' "%s" -> "%s" [label="%s"];' . "\n", $src, $tgt, $type; } } print "}\n";