From: Jeremy Laine Date: Sat, 23 Nov 2002 15:23:23 +0000 (+0000) Subject: parcoure le include path X-Git-Tag: start~34 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=a6c2c2fb14ef82399e32164dd36ed4939fac2ada;p=old-projects.git parcoure le include path --- diff --git a/deptrack/deptrack.pl b/deptrack/deptrack.pl index 024cd81..22a51a7 100755 --- a/deptrack/deptrack.pl +++ b/deptrack/deptrack.pl @@ -8,7 +8,7 @@ use DBI(); 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 = "(?do("delete from $table"); } +# add a dependency into DB sub putdep { my($pageid,$depid,$did,$type) = @_; my($sth); @@ -119,6 +121,7 @@ sub putdep { } } +# put a directory into DB sub putdir { my($dir) = @_; @@ -131,10 +134,12 @@ sub putdir { 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/); @@ -154,6 +159,7 @@ sub putfile { return $fid; } +# return the ID corresponding to a directory name sub getdirid { my($dir) = @_; my($sth); @@ -167,6 +173,7 @@ sub getdirid { } } +# return the ID corresponding to a file name sub getfileid { my($file) = @_; my($sth); @@ -187,12 +194,15 @@ sub getfileid { # # ############################################################################### +# 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); @@ -236,7 +246,6 @@ sub parsedir { my @list = grep /^[^\.]/, readdir(DIRHANDLE); closedir(DIRHANDLE); - print "$vdir\n"; my @incfiles=grep /$mask_inc/,@list; map (&putfile("${vdir}$_", 1), @incfiles); @@ -263,9 +272,11 @@ sub parsedir { # 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()); @@ -290,7 +301,24 @@ sub parsefile { 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"); } }