#!/usr/bin/perl
#
# Copyright © 1999 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see
# <http://www.gnu.org/licenses/>.
#
#######################################################################

use File::Basename;
$progname = basename($0);

use DB_File;
use GDBM_File;

die "Filename missing\n" if !@ARGV;
die "$ARGV[0]: $!\n" if !-f $ARGV[0];

if ($progname =~ /catdb/) {
    tie %db, 'DB_File', $ARGV[0], O_RDONLY, 0664, $DB_HASH;
}
elsif ($progname =~ /catgdbm/) {
    tie %db, 'GDBM_File', $ARGV[0], GDBM_READER, 0644;
}
else {
    die "Called for unknown db type\n";
}
shift;

if (@ARGV > 0) {
    foreach $key (@ARGV) {
	print "-"x78, "\n";
	if (exists $db{$key}) {
	    print "$key:\n$db{$key}\n";
	}
	else {
	    print "*UNDEFINED*\n";
	}
    }
}
else {
    while( ($key,$val) = each %db ) {
	print "-"x78, "\n";
	print "$key:\n$val\n";
    }
}

untie %db;
exit 0;
