dropping debugging again
[feisty_meow.git] / scripts / files / filename_helper.pl
index 2205cf96224a47e349442f054d3b8b9bcf25fd63..3be75c780d307c2a4f2fb9aa01cf6a941a10a354 100644 (file)
@@ -75,7 +75,7 @@ sub glob_list {
       $match =~ s/\*/.*/g;  # replace asterisks with dot star.
       $match =~ s/\+/\\+/g;  # escape plusses.
       $match =~ s/\?/\\?/g;  # escape question marks.
-      $match =~ s/\|/\\?/g;  # escape pipe char.
+      $match =~ s/\|/\\|/g;  # escape pipe char.
       $match =~ s/\$/\\\$/g;  # escape dollar sign.
       $match =~ s/\[/\\[/g;  # escape open bracket.
       $match =~ s/\]/\\]/g;  # escape close bracket.
@@ -89,6 +89,7 @@ sub glob_list {
       if ($possible_name =~ /$match/) {
         # this one matches so add it.
         push @to_return, $chopped_filename[0] . $possible_name;
+#print "a match on: $chopped_filename\n";
       }
     }
   }
@@ -408,7 +409,8 @@ return;
     }
 
     local *DIR;
-    opendir DIR, $dir or die "opendir $dir: $!";
+    # if we can't open the dir, just skip to the next one.
+    opendir DIR, $dir or next;
     while ($_ = readdir DIR) {
       next if /^\.{1,2}$/;
       my $path = "$dir/$_";
@@ -427,16 +429,15 @@ sub find_directories {
   my @dirs_found = ();
   my $dir;
   foreach $dir (@_) {
-printf "FD outer dir: $dir\n";
     local *DIR;
-    opendir DIR, $dir or die "opendir $dir: $!";
+    # if we can't open the dir, just skip to the next one.
+    opendir DIR, $dir or next;
     while ($_ = readdir DIR) {
       # skip if it's current or parent dir.
       next if /^\.{1,2}$/;
       my $path = "$dir/$_";
       # skip if this entry is not itself a directory.
       next if ! -d $path;
-printf "FD adding $path to our list.\n";
       push @dirs_found, $path;
     }
     closedir DIR;
@@ -446,21 +447,25 @@ printf "FD adding $path to our list.\n";
 
 ############################################################################
 
-# given a directory, this returns an array of all the filenames found therein.
+# given a list of paths, this returns an array of all the filenames found therein.
 sub find_files {
   my @files_found = ();
   my $dir;
   foreach $dir (@_) {
-#printf "LFN outer dir: $dir\n";
+    if (-f $dir) {
+      # that's actually just a file, so add it.
+      push @files_found, $dir;
+      next;
+    }
     local *DIR;
-    opendir DIR, $dir or die "opendir $dir: $!";
+    # if we can't open the dir, just skip to the next one.
+    opendir DIR, $dir or next;
     while ($_ = readdir DIR) {
       # skip if it's current or parent dir.
       next if /^\.{1,2}$/;
       my $path = "$dir/$_";
       # skip if this entry is not a file.
       next if ! -f $path;
-#printf "LFN adding $path to our list.\n";
       push @files_found, $path;
     }
     closedir DIR;
@@ -473,45 +478,19 @@ sub find_files {
 # finds all directories starting at a particular directory and returns them
 # in an array.  does not include the starting directory.
 sub recursive_find_directories {
+  # first find all the directories within the parameters.
+  my @toplevel = find_directories(@_);
 
-#fix this
-
-#flush not working!
-$|++;
-  my @dir_list = @_;
-printf "got into find dirs, args are: @dir_list\n";
-  my @to_return = ();
-  my $dir;
-  foreach $dir (@dir_list) {
-printf "outer dir: $dir\n";
-    local *DIR;
-    opendir DIR, $dir or die "opendir $dir: $!";
-    while ($_ = readdir DIR) {
-      # skip if it's current or parent dir.
-      next if /^\.{1,2}$/;
-      my $path = "$dir/$_";
-      # skip if this entry is not itself a directory.
-      next if ! -d $path;
-      # add to our list if it's a directory.
-printf "adding $path to our list.\n";
-      push @to_return, $path;
-#this isn't needed, right????
-      next;
-    }
-    closedir DIR;
-  }
-
-printf "list before recursion: @to_return\n";
+  my @to_return;
+  push(@to_return, @toplevel);
 
   # return the composition of the list we found here plus any directories under those.
-#hmmm: this is hideous!  it will just grow greater.  can't we do this efficiently?
-
-#hmmm: this causes things to totally fail.  what is going on???
-  my @subs_found ;
-@subs_found = recursive_find_directories(@to_return);
-
-  push(@to_return, @subs_found);
-
+  # we only recurse if there's something to chew on in our directory list.
+  # otherwise, we've hit the bottom of that tree.
+  if (scalar @toplevel > 0) {
+    my @subs_found = recursive_find_directories(@toplevel);
+    push(@to_return, @subs_found);
+  }
   return @to_return;
 }