| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | # Movable Type (r) Open Source (C) 2005-2009 Six Apart, Ltd. |
|---|
| 4 | # This program is distributed under the terms of the |
|---|
| 5 | # GNU General Public License, version 2. |
|---|
| 6 | # |
|---|
| 7 | # $Id$ |
|---|
| 8 | |
|---|
| 9 | use strict; |
|---|
| 10 | use Getopt::Long; |
|---|
| 11 | |
|---|
| 12 | my ($file1, $file2, $file3); |
|---|
| 13 | my (%conv1, %conv2); |
|---|
| 14 | my (%conv1_lc, %conv2_lc); |
|---|
| 15 | |
|---|
| 16 | GetOptions( 'old:s' => \$file1, |
|---|
| 17 | 'target:s' => \$file2, |
|---|
| 18 | 'new:s' => \$file3, |
|---|
| 19 | ); |
|---|
| 20 | |
|---|
| 21 | # print "## old: $file1 new: $file2 \n"; |
|---|
| 22 | print "\n\t## phrases from previous version.\n"; |
|---|
| 23 | |
|---|
| 24 | open FH, $file1; |
|---|
| 25 | while (<FH>) { |
|---|
| 26 | next if (/^\s*#/); |
|---|
| 27 | if ($_ =~ /^\s*(['"])(.+)\1\s*=>\s*(['"])(.+)\3,/) { |
|---|
| 28 | # print STDERR $2, "\n"; |
|---|
| 29 | $conv1{$2} = $4; |
|---|
| 30 | $conv1_lc{lc $2} = $4; |
|---|
| 31 | } |
|---|
| 32 | } |
|---|
| 33 | close FH; |
|---|
| 34 | |
|---|
| 35 | open my $n, '>', $file3; |
|---|
| 36 | |
|---|
| 37 | open FH, $file2; |
|---|
| 38 | while (<FH>) { |
|---|
| 39 | if (/^\s*#/) { |
|---|
| 40 | print $n "\n$_"; |
|---|
| 41 | next; |
|---|
| 42 | } |
|---|
| 43 | if ($_ =~ /^\s*#?\s*(['"])(.+)\1\s*=>\s*(['"])(.*)\3,/) { |
|---|
| 44 | # print STDERR $2, "\n"; |
|---|
| 45 | unless (exists $conv2{$2}) { |
|---|
| 46 | print $n $_; |
|---|
| 47 | $conv2{$2} = $4 || q(); |
|---|
| 48 | $conv2_lc{lc $2} = $4 || q(); |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | close FH; |
|---|
| 53 | |
|---|
| 54 | close $n; |
|---|
| 55 | |
|---|
| 56 | my %check; |
|---|
| 57 | |
|---|
| 58 | foreach my $p (keys %conv1) { |
|---|
| 59 | if ($conv1{$p} eq $conv2{$p}) { |
|---|
| 60 | $check{$p} = 1; |
|---|
| 61 | } elsif ($conv2{$p} && $conv1{$p} ne $conv2{$p}) { |
|---|
| 62 | # printf "\t'%s' => '%s', # modified from '%s'\n", $p, $conv2{$p}, $conv1{$p}; |
|---|
| 63 | $check{$p} = 1; |
|---|
| 64 | } elsif ($conv2_lc{lc $p}) { |
|---|
| 65 | # printf "\t'%s' => '%s', # changed UPPER/LOWER '%s'\n", $p, $conv2_lc{lc $p}, $conv1_lc{lc $p}; |
|---|
| 66 | $check{$p} = 1; |
|---|
| 67 | $check{lc $p} = 1; |
|---|
| 68 | } elsif (!exists($conv2{$p})) { |
|---|
| 69 | # printf "\t'%s' => '%s', # only old. \n", $p, $conv1{$p}; |
|---|
| 70 | my $q = "'"; |
|---|
| 71 | if ($p =~ /\\[a-z]/) { |
|---|
| 72 | $q = '"'; |
|---|
| 73 | } |
|---|
| 74 | printf "\t$q%s$q => '%s',\n", $p, $conv1{$p}; |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | # print "\n\n# only in new\n\n"; |
|---|
| 79 | # foreach my $p (sort keys %conv2) { |
|---|
| 80 | # unless ($check{$p} || $check{lc $p}) { |
|---|
| 81 | # printf "\t'%s' => '%s',\n", $p, $conv2{$p}; |
|---|
| 82 | # } |
|---|
| 83 | # } |
|---|
| 84 | |
|---|
| 85 | 1; |
|---|