#!/usr/bin/perl
#
# create a Berkeley DB from a text file
# similar to Sendmail's makemap utility

use DB_File;

# $FORMAT not currently used
my $FORMAT = shift @ARGV;
my $DB = shift @ARGV;

# connect to data store
my %old_hash;
my %new_hash;
if ($FORMAT eq 'hash') {
	tie (%old_hash, 'DB_File', $DB, O_RDWR|O_CREAT, 0644, $DB_HASH) || die $!; # Open dbm file
} elsif ($FORMAT eq 'btree') {
	tie (%old_hash, 'DB_File', $DB, O_RDWR|O_CREAT, 0644, $DB_BTREE) || die $!; # Open dbm file 
} else {
	print "format $FORMAT not recognized\n";
	exit;
}

while (<STDIN>) {
	my ($key, $value) = split ' ';
	$new_hash{$key} = $value;
}

%old_hash = %new_hash;
untie (%old_hash);
