#!/usr/bin/perl

use Tie::IxHash;
tie %conf, 'Tie::IxHash';

sub eat{
	my ($fn, $buf, $key, $s) = (shift, '', '', '');
	open F, $fn;
	while(<F>) {
		chomp;
		s@\s+$@@gs;
		next if /^\s+$/;
		if(/^[a-zA-Z\$]+/ || eof(F)) {
			if(eof(F)) {
				if(length $buf) { $buf .= "\n"; }
				$buf .= $_;
			}
			@a = split /[=]{1}/;
			if(length $key){
				$conf{$key} = $buf;
			}
			$key = $a[0];
			$key =~ s@\s+@@gs;
			$buf = '';
		}
		if(length $buf) { $buf .= "\n"; }
		$buf .= $_;
	}
	close F;
}

$global_config = $ARGV[0];
$local_config = $ARGV[1];
die("Usage: $0 <global-config> <local-config>\n") unless length($global_config) && length($local_config);

eat $global_config;
eat $local_config;

for $k(keys %conf) {
	print $conf{$k} . "\n";
	if($conf{$k} =~ /\n/s) { print "\n"; }
}
