#!/usr/bin/env perl

use DB_File;
use Fcntl ':flock';

die("DB file name expected\n") unless (@ARGV);

while ($filename = shift(@ARGV)) {
    my(%database);
    my $db = tie(%database, 'DB_File', $filename, O_RDWR, 0444);
    unless ($db) {
	print(STDERR "couldn't init DB '$filename': $!\n");
    } else {
	$fd = $db->fd();
	unless (open(DATAFILE, "+<&=$fd")) {
	    print(STDERR "couldn't safety open DB '$filename': $!\n");
	} else {
	    unless (flock(DATAFILE, LOCK_SH)) {
		print(STDERR "couldn't lock DB '$filename': $!\n");
	    } else {
		my($key);
		foreach $key (keys(%database)) {
		    print("$key\t$database{$key}\n");
		}
	    }
	    close(DATAFILE);
	}
	undef($db);
	untie(%database);
    }
}
