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

use Data::MagicTie;
use Data::Dumper;
use Fcntl;

$Data::Dumper::Indent = 1;

die "Usage: $0 <filename>  <see_values> <no_serialise> <Q_factor> <local_or_remote> [ <style> <host> <port>]\n"
	unless($#ARGV>=4);

my $file = shift;
$file =~ s/\.([dbm]+)$//;
my $seevalues = shift;
my $noft = shift;
my $Q = shift;
undef $Q
	unless ($Q =~ /\d+/);
my $lr = shift;
my $style = shift;
my $host = shift;
undef $host
	unless($host ne '');
my $port = shift;
undef $port
	unless($port =~ /\d+/);

tie %tmp, "Data::MagicTie",$file,( lr => $lr, mode => ($style eq 'BerkeleyDB') ?  DB_RDONLY : O_CREAT|O_RDONLY, noft => $noft, Q=> $Q, style => $style, dbms_host => $host, dbms_port => $port )
	or die "Could not open $file: $!";

while(($k,$v)=each %tmp) {

	print $file." "
		if $more_than_one;

	$k =~ s/[\x00-\x1f]/sprintf("%%%2x",\1)/eg;
	$v =~ s/[\x00-\x1f]/sprintf("%%%2x",\1)/eg;

	$v= Dumper( $v ) if ref($v);

	print "'$k'";
	print "=\t$v"
		if $seevalues;
	print "\n";
	};
untie %tmp;
