#!/usr/bin/perl -w

#-------------------------------------------------------------------------

# Make sure we pre-declare everything
# Use the necessary Perl modules

use strict;
use NexTrieve qw(Targz);

# Output warning if it is the wrong version

warn <<EOD if $NexTrieve::VERSION ne '0.37';
$0 is not using the right version of the associated Perl modules.
Operation of this script may be in error because of this.
EOD

# Create a NexTrieve object
# Initialize the list of directories to work with

my $ntv = NexTrieve->new( {PrintError => 1} );
my @dir;

# If parameters are specified
#  Use those
# Else
#  Read the directory names from standard input

if (@ARGV) {
  @dir = @ARGV;
} else {
  chomp( @dir = <STDIN> );
}

# Initialize number of messages handled
# Initialize total number of messages handled
# Initialize number or directories handled

my $messages;
my $total = 0;
my $directories = 0;

# For all of the valid directories specified
#  Increment number of directories
#  Count the messages
#  Show the number of messages handled
#  Add number of messages to total

foreach my $directory (map {(-d "$_/rfc") ? $_ : ()} @dir) {
  $directories++;
  my $messages = $ntv->Targz( $mailinglist )->count_storable;
  print "$directory -> $messages\n";
  $total += $messages;
}

# Show the final statistics if any

printf( "Counted $total articles in $directories directories (average %.2f)\n",
$total/$directories ) if $directories;

#-------------------------------------------------------------------------

__END__

=head1 targz_count

Count messages in directories in Targz format.

=head2 Usage

 targz_count			# count all Targz in current directory

 targz_count apache*		# count all apache* Targz directories

 find perl* | targz_count	# count all Targz directories with perl* in it

=head1 AUTHOR

Elizabeth Mattijsen, <liz@dijkmat.nl>.

Please report bugs to <perlbugs@dijkmat.nl>.

=head1 COPYRIGHT

Copyright (c) 1995-2002 Elizabeth Mattijsen <liz@dijkmat.nl>. All rights
reserved.  This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 SEE ALSO

http://www.nextrieve.com and the NexTrieve::xxx modules.

=cut
