--- ./lib/File/Find.pm~	Tue Nov 25 06:52:28 1997
+++ ./lib/File/Find.pm	Thu Dec 11 22:04:06 1997
@@ -75,28 +75,37 @@ There is no way to make find or finddept
 @EXPORT = qw(find finddepth);
 
 
-sub find {
+sub find_opt {
     my $wanted = shift;
-    my $cwd = Cwd::cwd();
+    my $bydepth = $wanted->{bydepth};
+    my $cwd = $bydepth ? Cwd::fastcwd() : Cwd::cwd();
     # Localize these rather than lexicalizing them for backwards
     # compatibility.
     local($topdir,$topdev,$topino,$topmode,$topnlink);
+
     foreach $topdir (@_) {
 	(($topdev,$topino,$topmode,$topnlink) =
 	  ($Is_VMS ? stat($topdir) : lstat($topdir)))
 	  || (warn("Can't stat $topdir: $!\n"), next);
 	if (-d _) {
 	    if (chdir($topdir)) {
-		($dir,$_) = ($topdir,'.');
-		$name = $topdir;
 		$prune = 0;
-		&$wanted;
+		unless ($bydepth) {
+		  ($dir,$_) = ($topdir,'.');
+		  $name = $topdir;
+		  $wanted->{sub}->();
+		}
 		if (!$prune) {
 		    my $fixtopdir = $topdir;
 	            $fixtopdir =~ s,/$,, ;
 		    $fixtopdir =~ s/\.dir$// if $Is_VMS;
 		    $fixtopdir =~ s/\\dir$// if $Is_NT;
-		    &finddir($wanted,$fixtopdir,$topnlink);
+		    &finddir($wanted,$fixtopdir,$topnlink, $bydepth);
+		    if ($bydepth) {
+		        ($dir,$_) = ($fixtopdir,'.');
+			$name = $fixtopdir;
+			$wanted->{sub}->();
+		    }
 		}
 	    }
 	    else {
@@ -108,21 +117,21 @@ sub find {
 		($dir,$_) = ('.', $topdir);
 	    }
 	    $name = $topdir;
-	    chdir $dir && &$wanted;
+	    chdir $dir && $wanted->{sub}->();
 	}
 	chdir $cwd;
     }
 }
 
 sub finddir {
-    my($wanted, $nlink);
+    my($wanted, $nlink, $bydepth);
     local($dir, $name);
-    ($wanted, $dir, $nlink) = @_;
+    ($wanted, $dir, $nlink, $bydepth) = @_;
 
     my($dev, $ino, $mode, $subcount);
 
     # Get the list of files in the current directory.
-    opendir(DIR,'.') || (warn "Can't open $dir: $!\n", return);
+    opendir(DIR,'.') || (warn("Can't open $dir: $!\n"), $bydepth || return);
     my(@filenames) = readdir(DIR);
     closedir(DIR);
 
@@ -132,7 +141,7 @@ sub finddir {
 	    next if $_ eq '..';
 	    $name = "$dir/$_";
 	    $nlink = 0;
-	    &$wanted;
+	    $wanted->{sub}->();
 	}
     }
     else {                    # This dir has subdirectories.
@@ -140,9 +149,10 @@ sub finddir {
 	for (@filenames) {
 	    next if $_ eq '.';
 	    next if $_ eq '..';
-	    $nlink = $prune = 0;
+	    $nlink = 0;
+	    $prune = 0 unless $bydepth;
 	    $name = "$dir/$_";
-	    &$wanted;
+	    $wanted->{sub}->() unless $bydepth;
 	    if ($subcount > 0 || $dont_use_nlink) {    # Seen all the subdirs?
 
 		# Get link count and check for directoriness.
@@ -157,104 +167,31 @@ sub finddir {
 		    if (!$prune && chdir $_) {
 			$name =~ s/\.dir$// if $Is_VMS;
 			$name =~ s/\\dir$// if $Is_NT;
-			&finddir($wanted,$name,$nlink);
+			&finddir($wanted,$name,$nlink, $bydepth);
 			chdir '..';
 		    }
 		    --$subcount;
 		}
 	    }
+	    $wanted->{sub}->() if $bydepth;
 	}
     }
 }
 
-
-sub finddepth {
-    my $wanted = shift;
-
-    $cwd = Cwd::fastcwd();;
-
-    # Localize these rather than lexicalizing them for backwards
-    # compatibility.
-    local($topdir, $topdev, $topino, $topmode, $topnlink);
-    foreach $topdir (@_) {
-	(($topdev,$topino,$topmode,$topnlink) =
-	  ($Is_VMS ? stat($topdir) : lstat($topdir)))
-	  || (warn("Can't stat $topdir: $!\n"), next);
-	if (-d _) {
-	    if (chdir($topdir)) {
-		my $fixtopdir = $topdir;
-		$fixtopdir =~ s,/$,, ;
-		$fixtopdir =~ s/\.dir$// if $Is_VMS;
-		$fixtopdir =~ s/\\dir$// if $Is_NT;
-		&finddepthdir($wanted,$fixtopdir,$topnlink);
-		($dir,$_) = ($fixtopdir,'.');
-		$name = $fixtopdir;
-		&$wanted;
-	    }
-	    else {
-		warn "Can't cd to $topdir: $!\n";
-	    }
-	}
-	else {
-	    unless (($_,$dir) = File::Basename::fileparse($topdir)) {
-		($dir,$_) = ('.', $topdir);
-	    }
-	    $name = $topdir;
-	    chdir $dir && &$wanted;
-	}
-	chdir $cwd;
-    }
+sub wrap_wanted {
+  my $wanted = shift;
+  defined &$wanted ? {'sub' => $wanted} : $wanted;
 }
 
-sub finddepthdir {
-    my($wanted, $nlink);
-    local($dir, $name);
-    ($wanted,$dir,$nlink) = @_;
-    my($dev, $ino, $mode, $subcount);
-
-    # Get the list of files in the current directory.
-    opendir(DIR,'.') || warn "Can't open $dir: $!\n";
-    my(@filenames) = readdir(DIR);
-    closedir(DIR);
-
-    if ($nlink == 2 && !$dont_use_nlink) {   # This dir has no subdirectories.
-	for (@filenames) {
-	    next if $_ eq '.';
-	    next if $_ eq '..';
-	    $name = "$dir/$_";
-	    $nlink = 0;
-	    &$wanted;
-	}
-    }
-    else {                    # This dir has subdirectories.
-	$subcount = $nlink - 2;
-	for (@filenames) {
-	    next if $_ eq '.';
-	    next if $_ eq '..';
-	    $nlink = 0;
-	    $name = "$dir/$_";
-	    if ($subcount > 0 || $dont_use_nlink) {    # Seen all the subdirs?
-
-		# Get link count and check for directoriness.
-
-		($dev,$ino,$mode,$nlink) = ($Is_VMS ? stat($_) : lstat($_));
-		
-		if (-d _) {
-
-		    # It really is a directory, so do it recursively.
+sub find {
+  my $wanted = shift;
+  find_opt(wrap_wanted($wanted), @_);
+}
 
-		    if (chdir $_) {
-			$name =~ s/\.dir$// if $Is_VMS;
-			$name =~ s/\\dir$// if $Is_NT;
-			&finddepthdir($wanted,$name,$nlink);
-			chdir '..';
-		    }
-		    --$subcount;
-		}
-	    }
-	    &$wanted;
-	}
-    }
+sub find_depth {
+  my $wanted = wrap_wanted(shift);
+  $wanted->{bydepth} = 1;
+  find_opt($wanted, @_);
 }
 
 # Set dont_use_nlink in your hint file if your system's stat doesn't
