affichage reduit sauf en mode debug
authorJeremy Laine <jeremy.laine@m4x.org>
Sat, 23 Nov 2002 17:16:32 +0000 (17:16 +0000)
committerJeremy Laine <jeremy.laine@m4x.org>
Sat, 23 Nov 2002 17:16:32 +0000 (17:16 +0000)
accepte les includes d'un .php moyennant un warning

deptrack/deptrack.pl

index c4a7aa8..e9640ae 100755 (executable)
@@ -16,12 +16,18 @@ my $mask_img = "\\.(png|gif|jpg)\$";
 
 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);
+}
 
 ###############################################################################
 #                                                                             #
@@ -125,7 +131,7 @@ sub putdep {
 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'");
@@ -140,7 +146,7 @@ sub putfile {
   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/);
@@ -274,7 +280,7 @@ sub parsefile {
   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");
@@ -295,35 +301,32 @@ sub parsefile {
   @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);
   }
 }