#!/usr/bin/perl
#
# Checks a language file against the reference language (en_us), and
# finds #define string diferences
#
my $srcfile = $ARGV[0];
my $engfile = "en_us.l";
my %is_there= ();
my $pos=0;
my $wc=0;

my @defs;
my @text;

sub error {

    my $msg = shift ;
    print "*** Error: $msg \n";
    exit ;
}

sub not_del {
    $line = shift;
    if ($is_there{$line}) {
        return 1;
    } else {
        return 0;
    }

}

error("Usage $0 [lang.l]") unless ($srcfile);
error("Can't find language file: $srcfile") if (! -f $srcfile);
error("Can't find language file: $engfile") if (! -f $engfile);
open (EFILE, "< $engfile");
open (SFILE, "< $srcfile");

while (<EFILE>) {
    my $line = $_;
    chomp $line;
    if (/^[A-Z]/) {
        $wc = push (@defs, $line);
    }
}

for (@defs) { 
    $is_there{$_} = 1;
}

while (<SFILE>) {
    my $line = $_;
    chomp $line;
    if (/^[A-Z]/) {

        if (not_del($line)) {
            while ($line ne $defs[$pos]) {
                print "ADD: $defs[$pos]\n";
                $pos++;
            }
            $pos++;
        } else {
            print "DEL: $line\n";
        }
    }
}

for($pos ; $pos < $wc; $pos++) {
    print "ADD: $defs[$pos]\n";
}
close(EFILE);
close(SFILE);
