#! /usr/bin/perl

my ($properties_orig, $properties_trans) = @ARGV;

sub read_file($)
{
    my ($filename) = @_;
    my %result;

    open FILE, "$filename" or die;
    while (defined($_ = <FILE>)) {
        /^\s*$/ and next;
        /^[#!]/ and next;

        my ($key, $value) = split(/[=: ]/, $_, 2);
        $result{$key} = $value;
    }
    close FILE;

    return %result;
}


sub escape_value($)
{
    my ($value) = @_;
    $value =~ s/\n/\\n/g;
    $value =~ s/"/\\"/g;
    return $value;
}


my %pot;
my %po;

%pot = read_file($properties_orig);
%po = read_file($properties_trans) if $properties_trans;

print "# Do not use this file for translation work.\n";
print "# If you want to translate the JDBC driver messages, look at\n";
print "# src/interfaces/jdbc/org/postgresql/errors_*.properties\n";
print "\n";

foreach my $key (keys %pot) {
    print "# key: $key\n";

    my $value = $pot{$key};
    my $trans = $po{$key} || "";

    print "msgid \"".escape_value($value)."\"\n";
    print "msgstr \"".escape_value($trans)."\"\n";
    print "\n";
}
