#!/usr/bin/perl -w

use strict;
use XBase::Index;

if (@ARGV and $ARGV[0] eq '-d') {
	$XBase::Index::DEBUG = 1;
	shift;
	}

unless (@ARGV) {
	die <<EOF;
test_index for XBase::Index: usage is:
	./test_index [-d] index_file.ext [tag_name]
		-d	adds debugging info
		index type is guessed from the file extension
		tag_name only makes sense with formats that support tags
EOF
	}


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

### use Data::Dumper; print Dumper $index;

$index->prepare_select or die $index->errstr;

while (my @data = $index->fetch()) {
	$data[0] =~ s/\s+$//;
	print "@data\n";
	}

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

