#!/usr/local/bin/perl -I../pm
 
#-----------------------------------------------------------------------

=head1 NAME

B<createReachable> - A program to run through the WWWGraph and create the
reachable graph

=head1 SYNOPSIS

  createIndex
    [-help] |
    [-version] |
    [-verbose]
    [-databaseName databaseName]
    [-databaseMode GDBM | DBM | BSD]

=head1 DESCRIPTION

B<createReachable> is a simple script to read the initial graph and
create the reachable graph.

=head1 EXAMPLE USAGE

Create a reachable graph.

 perl -I../lib createReachable \
    -verbose \
    -exclude excludedWords \
    -databaseName databaseName \
    -databaseMode DBM 

See also L<JumpingSpider>.

=cut

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

use strict;
require 5.002;

use Getopt::Long;
use IO::Pipe;
use English;
use JumpingSpider;

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

=head1 OPTIONS

=over 4

=item -help

Display a short help message with a reminder of supported
command-line options.

=item -version

Display the version of Robot.

=item -verbose

Enable verbose reporting.

=item -databaseName databaseName

The name of the database, overides the default name
in L<JumpingSpider::Constants>.

=item -databaseMode databaseMode

The mode of the database, overides the default mode
in L<JumpingSpider::Constants>.

=back

=cut

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

use vars qw($VERSION);

my $VERSION       = '1.00';
my $SHOW_VERSION  = 0;
my $VERBOSE       = 0;
my $HELP          = 0;
my $COMMAND_NAME  = 'createReachable';

&ParseCommandLine();
print "$COMMAND_NAME: Initializing...\n" if $VERBOSE;
&JumpingSpider::WWWGraph::init(new JumpingSpider::Globals());
print "$COMMAND_NAME: Creating reachable graph.\n" if $VERBOSE;
&JumpingSpider::WWWGraph::createReachable();
&JumpingSpider::WWWGraph::done();
print "$COMMAND_NAME: Cleaned up and exiting.\n" if $VERBOSE;

#------------------------------------------------------------------------
# ParseCommandLine() - handle command line
#------------------------------------------------------------------------
sub ParseCommandLine {
  my @switches = (
    'databaseMode=s', \$JumpingSpider::Constants::databaseMode,
    'databaseName=s', \$JumpingSpider::Constants::databaseName,
    'help',           \$HELP,
    'verbose',        \$VERBOSE,
    'version',        \$SHOW_VERSION,
    );

  &GetOptions(@switches) || die "use -help switch to display brief help\n";

  if ($SHOW_VERSION) {
    print "This is $COMMAND_NAME, version $VERSION\n";
    exit 0;
    }

  if ($HELP) {
    print <<HelpEnd;
    $COMMAND_NAME, v$VERSION - do the reachability calculation on the WWW Graph

    Usage: $COMMAND_NAME
                         [-help] |
                         [-version] |
                         [-verbose]
                         [-databaseName databaseName]
                         [-databaseMode GDBM | DBM | BSD]

        -help            : display this message
        -verbose         : display verbose information as running
        -databaseName name : name of the database
        -databaseMode mode : mode for the database

HelpEnd
    exit 0;
    }
}
