#!/usr/local/bin/perl
#
# htdbdump.pl v1.0  (C) 1999 heddy Boubaker
#
# ChangeLog
#  25-Feb-1999: Birthday
#
# Read Htdig dbs and print out contents.
#
# Usage: htdbdump.pl [options]
#        -h       help
#        -c conf  config name
#        -d db    db name
#        -v       verbose

use strict;

use HtDig;
require 'getopts.pl';
use vars qw($opt_v $opt_h $opt_c $opt_d);

my %dbs = (
           'doc_db'    => \&HtDig::doc_db, 
           'word_db'   => \&HtDig::word_db, 
           'doc_index' => \&HtDig::doc_index, 
           );

### main ###

&Getopts ('d:c:h:v');
if ($opt_h ne "") {
    print <<EndOfHelp

List HtDig Documents

Usage: $0 [options]
  -h         help
  -c config  configname
  -d db      dbname
  -v         verbose

EndOfHelp
;
    print "Known dbs are:\n";
    foreach ( keys %dbs ) {
        print "\t$_\n";
    }
    exit 0;
}

if ( !exists $dbs{$opt_d} ) {
    print "$opt_d: Don't know what this db is ...\n" .
        "Known dbs are:\n";
    foreach ( keys %dbs ) {
        print "\t$_\n";
    }
    exit 1;
}

my $htdig  = new HtDig ( 'Config'=>$opt_c, 'Verbose'=>$opt_v ) || die "new HtDig($opt_c, $opt_v) Failure - $! -";

my $f = $dbs{$opt_d};
my $db = $htdig->${f}( ) || die "Could not get db $opt_d - $! - ";

$db->process( \&print_record );

exit 0;

#############################################################################
# Subroutines
#

sub print_record {
    my $record = shift;
    $record->print( $opt_v );
} # end parse();

### htdbdump.pl.pl ens here ###
