1 | #! /usr/bin/perl -w
|
---|
2 | ###
|
---|
3 | ### diff_lang.pl - Show differences of a JOSM language file.
|
---|
4 | ###
|
---|
5 | ### Syntax examples:
|
---|
6 | ### diff_lang.pl -u -L "data/en.lang (revision 12345)"
|
---|
7 | ### -L "data/en.lang (working copy)"
|
---|
8 | ### .svn/pristine/42/423b7dfb6a014d6c0d3ec3ce96a10e2df665266a.svn-base
|
---|
9 | ### data/en.lang
|
---|
10 | ### diff_lang.pl --tkdiff -L "data/en.lang (revision 12345)"
|
---|
11 | ### -L "data/en.lang (working copy)"
|
---|
12 | ### .svn/pristine/42/423b7dfb6a014d6c0d3ec3ce96a10e2df665266a.svn-base
|
---|
13 | ### data/en.lang
|
---|
14 |
|
---|
15 | use strict;
|
---|
16 | use utf8;
|
---|
17 | use File::Basename;
|
---|
18 | use File::Temp qw/ tempfile /;
|
---|
19 | push(@INC, dirname($0));
|
---|
20 | require i18nlib;
|
---|
21 |
|
---|
22 | my @diffArgs;
|
---|
23 | my @files;
|
---|
24 | my $tkdiff = 0;
|
---|
25 | #print "Arguments: ", join(" ", @ARGV), "\n";
|
---|
26 | for (my $idx = 0; $idx <= $#ARGV; $idx++) {
|
---|
27 | my $arg = $ARGV[$idx];
|
---|
28 | if ($arg eq "-u") {
|
---|
29 | push(@diffArgs, $arg);
|
---|
30 | }
|
---|
31 | elsif ($arg eq "-L") {
|
---|
32 | push(@diffArgs, $arg, $ARGV[++$idx]);
|
---|
33 | }
|
---|
34 | elsif ($arg eq "--tkdiff") {
|
---|
35 | $tkdiff = 1;
|
---|
36 | }
|
---|
37 | elsif ($arg =~ m/^-/) {
|
---|
38 | #die "Unknown option '$arg'.\n";
|
---|
39 | ### Assume that diff knows this option and that it has no argument.
|
---|
40 | push(@diffArgs, $arg);
|
---|
41 | }
|
---|
42 | else {
|
---|
43 | push(@files, $arg);
|
---|
44 | }
|
---|
45 | #print "$idx: $ARGV[$idx]\n";
|
---|
46 | }
|
---|
47 |
|
---|
48 | if ($#files != 1) {
|
---|
49 | print "Files:\n", join("\n", @files), "\n";
|
---|
50 | die sprintf("Expected two file arguments, got %d arguments.\n", $#files + 1);
|
---|
51 | }
|
---|
52 |
|
---|
53 | my $separator = "\n\n";
|
---|
54 | my @strings = loadLangFile($files[0]);
|
---|
55 | my ($fh1, $tmpfile1) = tempfile();
|
---|
56 | #binmode($fh1, ":utf8");
|
---|
57 | print $fh1 join($separator, @strings), "\n";
|
---|
58 | close($fh1);
|
---|
59 | @strings = loadLangFile($files[1]);
|
---|
60 | my ($fh2, $tmpfile2) = tempfile();
|
---|
61 | #binmode($fh2, ":utf8");
|
---|
62 | print $fh2 join($separator, @strings), "\n";
|
---|
63 | close($fh2);
|
---|
64 |
|
---|
65 | push(@diffArgs, $tmpfile1, $tmpfile2);
|
---|
66 | my @diffCmd;
|
---|
67 | if ($tkdiff) {
|
---|
68 | push(@diffCmd, "tkdiff");
|
---|
69 | }
|
---|
70 | else {
|
---|
71 | push(@diffCmd, "diff");
|
---|
72 | }
|
---|
73 | push(@diffCmd, @diffArgs);
|
---|
74 | #print "Command: ", join(" ", @diffCmd), "\n";
|
---|
75 | system(@diffCmd);
|
---|