my $dsn = "DBI:mysql:database=deptrack;host=localhost";
my $dbh = DBI->connect($dsn,"deptrack","phptrax");
-my $incpath = "./:../";
+my @incpath = split /:/, "./:../";
my $mask_inc = "\\.inc(\\.php)?\$";
my $mask_php = "(?<!\\.inc)\\.php\$";
# return program syntax
sub syntax {
- print "Syntax:\n\tdeptrack directory\n\n";
+ print "Syntax:\n\tdeptrack root_directory\n\n";
exit 0;
}
# #
###############################################################################
+# clear a database table
sub cleartable {
my($table) = @_;
my $sth = $dbh->do("delete from $table");
}
+# add a dependency into DB
sub putdep {
my($pageid,$depid,$did,$type) = @_;
my($sth);
}
}
+# put a directory into DB
sub putdir {
my($dir) = @_;
return $did;
}
+# put a file into DB
sub putfile {
my($file,$exists) = @_;
my($fid,$type);
-
+
+ $exists=0 if (!$exists);
print "putfile($file,$exists)\n";
if ($exists) {
$type = "page" if ($file =~ /$mask_php/);
return $fid;
}
+# return the ID corresponding to a directory name
sub getdirid {
my($dir) = @_;
my($sth);
}
}
+# return the ID corresponding to a file name
sub getfileid {
my($file) = @_;
my($sth);
# #
###############################################################################
+# from a path in the server tree, return the path in the filesystem
sub realpath {
my($vpath) = @_;
return $rootdir.$vpath;
}
+# given a working directory and a relative path, return full path
+# ( in the server tree )
sub abspath {
my($curdir,$relpath) = @_;
my(@path,@comps,$ret);
my @list = grep /^[^\.]/, readdir(DIRHANDLE);
closedir(DIRHANDLE);
- print "$vdir\n";
my @incfiles=grep /$mask_inc/,@list;
map (&putfile("${vdir}$_", 1), @incfiles);
# parse a file
sub parsefile {
my($fid,$did,$vfile,$vdir) = @_;
- my(@lines,@phplines,@includes,$depid,$sth);
+ my(@lines,@phplines,@includes,$depid,$sth,$ifile);
print "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");
$sth->execute();
return if (my $ref = $sth->fetchrow_hashref());
die;
}
if ($include =~ /$mask_inc/) {
- $depid=&putfile(&abspath($vdir,$include),0);
+ if ($include =~ /^[\.\/]/) {
+ # the directory is specified
+ $ifile = &abspath($vdir,$include);
+ $depid=&putfile($ifile,(-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)) {
+ $depid=&putfile($ifile,1);
+ last;
+ }
+ }
+ # did not find file to be included, add it as if it were
+ # in the current directory
+ $depid=&putfile(&abspath($vdir,$include),0) if (!$depid);
+ }
&putdep($fid,$depid,$did,"include");
}
}