my $rootdir = $ARGV[0];
+my $debug = 0;
+
# return program syntax
sub syntax {
print "Syntax:\n\tdeptrack root_directory\n\n";
exit 0;
}
+sub dprint {
+ my($text) = @_;
+ print($text) if ($debug);
+}
###############################################################################
# #
sub putdir {
my($dir) = @_;
- print "putdir($dir)\n";
+ &dprint("putdir($dir)\n");
my $did=&getdirid($dir);
if (!$did) {
$dbh->do("insert into dir set path='$dir'");
my($fid,$type);
$exists=0 if (!$exists);
- print "putfile($file,$exists)\n";
+ &dprint("putfile($file,$exists)\n");
if ($exists) {
$type = "page" if ($file =~ /$mask_php/);
$type = "include" if ($file =~ /$mask_inc/);
my($fid,$did,$vfile,$vdir) = @_;
my(@lines,@phplines,@includes,$depid,$sth,$ifile,$iexists);
- print "parsefile($fid,$did,$vfile,$vdir)\n";
+ &dprint("parsefile($fid,$did,$vfile,$vdir)\n");
# we return if we already have dependecies in the same scope
$sth = $dbh->prepare("select id from dep where page=$fid and dir=$did");
@phplines = &commentstrip("#",@phplines);
@includes = grep s/.*(require|include)\s*\(\"(.*)\"\).*\n$/$2/, @phplines;
foreach my $include (@includes) {
- print "REQ:$include\n";
+ &dprint("REQ:$include\n");
if ($include =~ /$mask_php/) {
- print "ERROR : a .php file gets included by $vfile!\n";
- die;
+ print "Warning : $include gets included by $vfile!\n";
}
- if ($include =~ /$mask_inc/) {
- $iexists=0;
- if ($include =~ /^[\.\/]/) {
- # the directory is specified
- $ifile = &abspath($vdir,$include);
- $iexists=1 if (-f &realpath($ifile));
- } else {
- # directory not specified, go through the include path
- foreach my $incp (@incpath) {
- $ifile = &abspath(&abspath($vdir,$incp),$include);
- print "trying $ifile\n";
- if (-f &realpath($ifile)) {
- $iexists=1;
- last;
- }
+ $iexists=0;
+ if ($include =~ /^[\.\/]/) {
+ # the directory is specified
+ $ifile = &abspath($vdir,$include);
+ $iexists=1 if (-f &realpath($ifile));
+ } else {
+ # directory not specified, go through the include path
+ foreach my $incp (@incpath) {
+ $ifile = &abspath(&abspath($vdir,$incp),$include);
+ &dprint("trying $ifile\n");
+ if (-f &realpath($ifile)) {
+ $iexists=1;
+ last;
}
- # did not find file to be included, treat it as if it were
- # in the first segment of include path
- $ifile = &abspath(&abspath($vdir,$incpath[0]),$include) if (!$iexists);
}
- $depid=&putfile($ifile,$iexists);
- &putdep($fid,$depid,$did,"include");
- &parsefile($depid,$did,$ifile,$vdir) if ($iexists);
+ # did not find file to be included, treat it as if it were
+ # in the first segment of include path
+ $ifile = &abspath(&abspath($vdir,$incpath[0]),$include) if (!$iexists);
}
+ $depid=&putfile($ifile,$iexists);
+ &putdep($fid,$depid,$did,"include");
+ &parsefile($depid,$did,$ifile,$vdir) if ($iexists);
}
}