diff --git a/po/diff_po.pl b/po/diff_po.pl index a7967bc714..3cc6154bf8 100755 --- a/po/diff_po.pl +++ b/po/diff_po.pl @@ -34,77 +34,116 @@ my %Fuzzy = (); # inside new po-file my $result = 0; # exit value my $printlines = 0; my @names = (); +my $tmpfile = "/tmp/blax"; -# -while(defined($ARGV[0])) { - last if ($ARGV[0] !~ /^\-/); - my $param = shift(@ARGV); - if ($param eq "-L") { - my $name = shift(@ARGV); - push(@names, $name); +# Check first, if called as standalone program for git +if ($ARGV[0] =~ /^-r(.*)/) { + my $rev = $1; + shift(@ARGV); + if ($rev eq "") { + $rev = shift(@ARGV); + } + for my $argf (@ARGV) { + my $baseargf; + ($baseargf = $argf) =~ s/^.*\///; + my @args = (); + push(@args, "-L", $argf . " (" . $rev . ")"); + push(@args, "-L", $argf . " (local copy)"); + open(FI, "git show $rev:po/$baseargf|"); + open(FO, '>', $tmpfile); + while(my $l = ) { + print FO $l; + } + close(FI); + close(FO); + push(@args, $tmpfile, $argf); + &diff_po(@args); } } -if (! defined($names[0])) { - push(@names, "original"); +else { + &diff_po(@ARGV); } -if (! defined($names[1])) { - push(@names, "new"); -} - -if (@ARGV != 2) { - die('"', join('" "', @names, @ARGV) . "\" Expected exactly 2 parameters"); -} - -&check($names[0], $ARGV[0]); -&check($names[1], $ARGV[1]); - -&parse_po_file($ARGV[0], \%Messages); -&parse_po_file($ARGV[1], \%newMessages); - -my @MsgKeys = &getLineSortedKeys(\%newMessages); - -print RED "<<< \"$names[0]\"\n", RESET; -print GREEN ">>> \"$names[1]\"\n", RESET; -for my $k (@MsgKeys) { - if ($newMessages{$k}->{msgstr} eq "") { - # this is still untranslated string - $Untranslated{$newMessages{$k}->{line}} = $k; - } - elsif ($newMessages{$k}->{fuzzy}) { - #fuzzy string - $Fuzzy{$newMessages{$k}->{line}} = $k; - } - if (exists($Messages{$k})) { - &printIfDiff($k, $Messages{$k}, $newMessages{$k}); - delete($Messages{$k}); - delete($newMessages{$k}); - } -} - -@MsgKeys = &getLineSortedKeys(\%Messages); -for my $k (@MsgKeys) { - $result |= 8; - print "deleted message\n"; - print "< line = " . $Messages{$k}->{line} . "\n" if ($printlines); - print RED "< fuzzy = " . $Messages{$k}->{fuzzy} . "\n", RESET; - print RED "< msgid = \"$k\"\n", RESET; - print RED "< msgstr = \"" . $Messages{$k}->{msgstr} . "\"\n", RESET; -} - -@MsgKeys = &getLineSortedKeys(\%newMessages); -for my $k (@MsgKeys) { - $result |= 16; - print "new message\n"; - print "> line = " . $newMessages{$k}->{line} . "\n" if ($printlines); - print GREEN "> fuzzy = " . $newMessages{$k}->{fuzzy} . "\n", RESET; - print GREEN "> msgid = \"$k\"\n", RESET; - print GREEN "> msgstr = \"" . $newMessages{$k}->{msgstr} . "\"\n", RESET; -} - -&printExtraMessages("fuzzy", \%Fuzzy); -&printExtraMessages("untranslated", \%Untranslated); exit($result); +######################################################### + +sub diff_po($$) +{ + my @args = @_; + %Messages = (); + %newMessages = (); + %Untranslated = (); + %Fuzzy = (); + @names = (); + print "========================================================\n"; + while(defined($args[0])) { + last if ($args[0] !~ /^\-/); + my $param = shift(@args); + if ($param eq "-L") { + my $name = shift(@args); + push(@names, $name); + } + } + if (! defined($names[0])) { + push(@names, "original"); + } + if (! defined($names[1])) { + push(@names, "new"); + } + + if (@args != 2) { + die("names = \"", join('" "', @names) . "\"... args = \"" . join('" "', @args) . "\" Expected exactly 2 parameters"); + } + + &check($names[0], $args[0]); + &check($names[1], $args[1]); + + &parse_po_file($args[0], \%Messages); + &parse_po_file($args[1], \%newMessages); + + my @MsgKeys = &getLineSortedKeys(\%newMessages); + + print RED "<<< \"$names[0]\"\n", RESET; + print GREEN ">>> \"$names[1]\"\n", RESET; + for my $k (@MsgKeys) { + if ($newMessages{$k}->{msgstr} eq "") { + # this is still untranslated string + $Untranslated{$newMessages{$k}->{line}} = $k; + } + elsif ($newMessages{$k}->{fuzzy}) { + #fuzzy string + $Fuzzy{$newMessages{$k}->{line}} = $k; + } + if (exists($Messages{$k})) { + &printIfDiff($k, $Messages{$k}, $newMessages{$k}); + delete($Messages{$k}); + delete($newMessages{$k}); + } + } + + @MsgKeys = &getLineSortedKeys(\%Messages); + for my $k (@MsgKeys) { + $result |= 8; + print "deleted message\n"; + print "< line = " . $Messages{$k}->{line} . "\n" if ($printlines); + print RED "< fuzzy = " . $Messages{$k}->{fuzzy} . "\n", RESET; + print RED "< msgid = \"$k\"\n", RESET; + print RED "< msgstr = \"" . $Messages{$k}->{msgstr} . "\"\n", RESET; + } + + @MsgKeys = &getLineSortedKeys(\%newMessages); + for my $k (@MsgKeys) { + $result |= 16; + print "new message\n"; + print "> line = " . $newMessages{$k}->{line} . "\n" if ($printlines); + print GREEN "> fuzzy = " . $newMessages{$k}->{fuzzy} . "\n", RESET; + print GREEN "> msgid = \"$k\"\n", RESET; + print GREEN "> msgstr = \"" . $newMessages{$k}->{msgstr} . "\"\n", RESET; + } + + &printExtraMessages("fuzzy", \%Fuzzy); + &printExtraMessages("untranslated", \%Untranslated); +} sub check($$) {