@rem = '--*-Perl-*--
@echo off
if "%OS%" == "Windows_NT" goto WinNT
perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
:WinNT
perl -x -S %0 %*
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofperl
@rem ';
#!perl -w
#line 15


#!/usr/bin/perl -w 

use strict;
use XBase::Index;
use Getopt::Long;

my %opts = ();
my $type;
my $startvalue;
my $showtotal;
GetOptions('debug:i' => sub { my $key = shift; my $val = shift;
				$val = 1 if $val eq '0';
				$XBase::Index::DEBUG = $val },
	'type=s' => sub { my $key = shift;
				my $val = shift;
				if ($val eq 'num') { $type = 'N'; }
				elsif ($val eq 'date') { $type = 'D'; }
				elsif ($val eq 'char') { $type = 'C'; }
				elsif ($val eq 'string') { $type = 'C'; }
				else { die "Unknown index type `$val'\n"; }
		},
	'start=s' => \$startvalue,
	'tag=s' => sub { $opts{'tag'} = $_[1]; },
	'n' => sub { $showtotal = 1; },
	);
$opts{'type'} = $type if defined $type;

# AUDIO 4608
# FACILITY 3072
# FILM 9216
# MAIN 7680
# ROOMNAME 1536

my $file = shift;
if (@ARGV and not defined $opts{'tag'}) { $opts{'tag'} = shift; }
my $index = new XBase::Index $file, %opts or die XBase::Index->errstr;

if (defined $startvalue) {
	$index->prepare_select_eq($startvalue) or die $index->errstr;
	}
else {
	$index->prepare_select or die $index->errstr;
	}

my $i = 0;
while (my @data = $index->fetch())
	{
	print "@data\n";
	$i++;
	}

if ($index->errstr) { die $index->errstr; }

print "Total records: $i\n" if $showtotal;

=head1 NAME

indexdump - Show the content of the index file

=head1 FORMAT

        indexdump [options] file [ tag ]

where options are

        --debug		output record separator (default newline)
        --type		specifies the num/date/char type of the index
        --start		defines the value to start dump from
        --n		prints also the total number of records
			in the file

=head1 SYNOPSIS

        indexdump rooms.cdx FACILITY
        indexdump --debug=14 --start=Dub rooms.cdx ROOMNAME

=head1 DESCRIPTION

Indexdump prints to standard output the content of the index file.
The type of the index is one of those supported by the XBase::Index
Perl module (cdx, idx, ntx, ndx, mdx).

The output contains the index key and the value, which is the record
number in the correcponding dbf file.

For mulitag index files (like cdx), you need to specify the tag name
to get the actual data.

=head1 AUTHOR

(c) 1999--2000 Jan Pazdziora, adelton@fi.muni.cz,
http://www.fi.muni.cz/~adelton/
at Faculty of Informatics, Masaryk University in Brno, Czech Republic

=head1 SEE ALSO

perl(1); XBase::Index(3)

=cut

__END__



__END__
:endofperl
