qqs simplifications de syntaxe, rien de phénoménal
authorPierre Habouzit <madcoder@debian.org>
Sat, 23 Nov 2002 01:46:49 +0000 (01:46 +0000)
committerPierre Habouzit <madcoder@debian.org>
Sat, 23 Nov 2002 01:46:49 +0000 (01:46 +0000)
deptrack/deptrack.pl

index b31ed06..10afc3e 100755 (executable)
@@ -11,8 +11,8 @@ my $dbh = DBI->connect($dsn,"deptrack","phptrax");
 
 # return program syntax 
 sub syntax {
-  print "Syntax:\n\tdeptrack directory\n";
-  die;
+  print "Syntax:\n\tdeptrack directory\n\n";
+  exit 0;
 }
 
 # worker function called by tagextract and tagstrip
@@ -33,7 +33,7 @@ sub tagcrunch {
       }
       $add =~ s/^\s*//;
       $add =~ s/\s*$//;
-      if (length($add)>0) { push @out, "$add\n"; }
+      push @out, "$add\n" if (length($add)>0);
     }
   
     if (!$intag) {
@@ -50,7 +50,7 @@ sub tagcrunch {
        }
         $add =~ s/^\s*//;
        $add =~ s/\s*$//;
-        if (length($add)>0) { push @out, "$add\n"; }
+        push @out, "$add\n" if (length($add)>0);
       }
     } 
   }
@@ -60,13 +60,13 @@ sub tagcrunch {
 # return only blocks of @lines between tag1 and tag2
 sub tagextract {
   my($tag1,$tag2,@lines) = @_;
-  return tagcrunch($tag1,$tag2,0,@lines);
+  return &tagcrunch($tag1,$tag2,0,@lines);
 }
 
 # return @lines minus blocks between tag1 and tag2
 sub tagstrip {
   my($tag1,$tag2,@lines) = @_;
-  return tagcrunch($tag2,$tag1,1,@lines);
+  return &tagcrunch($tag2,$tag1,1,@lines);
 }
 
 # for each line, remove whatever is after the comment marker
@@ -77,7 +77,7 @@ sub commentstrip {
   foreach my $line (@lines) {
     $line =~ s/$tag.*//;
     $line =~ s/\s*$//;
-    if (length($line)>0) { push @out, "$line\n"; }
+    push @out, "$line\n" if (length($line)>0);
   }
   return @out;
 }
@@ -87,24 +87,18 @@ sub parsedir {
   my($dir,$vdir) = @_;
 
   # build virtual path
-  if (length($vdir)>0) {
-    $vdir="$vdir/"
-  }
+  $vdir="$vdir/" if (length($vdir)>0);
 
   opendir(DIRHANDLE, $dir);
   my @list = grep /^[^\.]/, readdir(DIRHANDLE);
   closedir(DIRHANDLE);
   
   my @phpfiles=grep /\.(php|inc)$/,@list;
-  foreach my $file (@phpfiles) {
-    parsefile("$dir/$file","$vdir$file");
-  }
+  map (&parsefile("$dir/$_", "${vdir}$_"), @phpfiles);
 
   foreach my $entry (@list) {
-    if (-d $entry) {
-      if ($entry !~ /^CVS$/) {
-        &parsedir("$dir/$entry", "$vdir$entry", "$vdir");
-      }
+    if ((-d $entry) && ($entry !~ /^CVS$/)) {
+      &parsedir("$dir/$entry", "${vdir}${entry}", "$vdir");
     }
   }
 }
@@ -119,13 +113,13 @@ sub parsefile {
   close(FHANDLE);
 
   # strip out commented code
-  @lines = tagstrip("<!--","-->",@lines);
+  @lines = &tagstrip("<!--","-->",@lines);
 
   # deal with PHP lines
-  @phplines = tagextract("<?php","?>",@lines);
-  @phplines = tagstrip("/*","*/",@phplines);
-  @phplines = commentstrip("\/\/",@phplines);
-  @phplines = commentstrip("#",@phplines);
+  @phplines = &tagextract("<?php","?>",@lines);
+  @phplines = &tagstrip("/*","*/",@phplines);
+  @phplines = &commentstrip("\/\/",@phplines);
+  @phplines = &commentstrip("#",@phplines);
   @includes = grep /(require|include)\s*\(/, @phplines;
   foreach my $include (@includes) {
     if ($include =~ /\.inc(\.php)?$/) {
@@ -142,9 +136,7 @@ sub listdir {
   my($sth);
   
   # build virtual path
-  if (length($vdir)>0) {
-    $vdir="$vdir/";
-  }
+  $vdir="$vdir/" if (length($vdir)>0);
 
   opendir(DIRHANDLE, $dir);
   my @list = grep /^[^\.]/, readdir(DIRHANDLE);
@@ -153,28 +145,25 @@ sub listdir {
   my @phpfiles=grep /\.(php|inc)/,@list;
   foreach my $file (@phpfiles) {
     if ($file =~ /\.inc(\.php)?$/) {
-      $sth = $dbh->prepare("insert into file set path='$vdir$file',type='include'");
+      $sth = $dbh->do("insert into file set path='$vdir$file',type='include'");
     } else {
-      $sth = $dbh->prepare("insert into file set path='$vdir$file',type='page'");
+      $sth = $dbh->do("insert into file set path='$vdir$file',type='page'");
     }
-    $sth->execute;
   }
   
   foreach my $entry (@list) {
-    if (-d $entry) {
-      if ($entry !~ /^CVS$/) {
-        &listdir("$dir/$entry", "$vdir$entry");
-      }
+    if ((-d $entry) && ($entry !~ /^CVS$/)) {
+      &listdir("$dir/$entry", "$vdir$entry");
     }
   }
 }
 
 ## do the work
 my $nargs = @ARGV;
-$nargs || syntax();
+$nargs || &syntax();
 
 my $topdir = $ARGV[0];
 $topdir =~ s/\/$//;
 
-listdir($topdir,"");
-parsedir($topdir,"");
+&listdir($topdir,"");
+&parsedir($topdir,"");