#!/usr/bin/perl

use strict;
use warnings;
use CDB_File;

# make_headers_cdb.pl
# $URL: svn+ssh://fw/repos/code/perl/qmail/make_headers_cdb.pl $
# $Id: make_headers_cdb.pl 130 2008-04-20 21:40:11Z ed $
# Copyright (C) 2006, ed neville
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.


if( !defined( $ARGV[0] ) ) {
	die( "usage: make_headers_cdb.pl <location of headers.cdb" );
}

my $cdb = new CDB_File( $ARGV[0], "${ARGV[0]}.tmp" ) 
	or die( "cannot open ${ARGV[0]} for writing:$!" );

while( my $inp = <STDIN> ) {
	chomp $inp;

	next if( $inp =~ /^#/ );
	
	$inp =~ s/\\\x2a/\0/g;

	my @kv = split( /\x2a/, $inp, 2 );

	$kv[0] =~ s/\0/\*/g;
	$kv[1] =~ s/\0/\*/g;

	$cdb->insert( $kv[0], $kv[1] );
}
$cdb->finish();


