X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=i18n-diff-auditor;h=341733b41e43cd9b908db75da2a215ace49e67c6;hp=5630d7e8dc192b7082ba6a66fcdf6d71c2845daf;hb=2b844820d3d171b554c43bcc69b907932201f769;hpb=59ca351b460f4d512134e56540addc7e84b6bc2b diff --git a/i18n-diff-auditor b/i18n-diff-auditor index 5630d7e8..341733b4 100755 --- a/i18n-diff-auditor +++ b/i18n-diff-auditor @@ -1,4 +1,53 @@ #!/usr/bin/perl -w +# +# i18n-diff-auditor +# Copyright (C)2018 Ian Jackson +# GPLv3+, NO WARRANTY, see below. +# +# +# Usage: +# something like this +# git-log -n1 -p | ./i18n-diff-auditor -D 2>&1 |less -j10 +/'^!.*' +# +# -D is for debug. Currently only one level. +# +# Output is the relevant diff hunks, with each line prepended with +# space for ok lines and ! for questionable ones, and with relevant +# diff lines prepended with lines starting !! (and lines starting # +# for debug output), so ovrall: +# +# !! reasoning for subsequent questionable diff line(s) +# !+ diff line found to be questionable +# !- diff line found to be questionable +# @@@ etc. diff furniture +# + diff line checked and ok +# - diff line checked and ok +# # debug output (normally precedes relevant output) +# +# Changes are generally marked as ok if they correspond to a known +# intended code change pattern. (That includes changing error calls +# to different error calls.) If they don't correspond to any known +# pattern, they are "questionable" and the first thing that doesn't +# match the most common pattern is reported. +# +# Might be useful for projects other than dgit, provided it uses +# the same gettext aliases (__ f_ i_) and similar error calls +# (die, confess, fail). +# +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + use strict; use Carp; use Data::Dumper; @@ -122,6 +171,7 @@ sub qp ($) { sub semiparse ($) { ($_) = @_; my @o; + #my $in = $_; # entries contain # T type # E exact input text (does not contain here doc contents) @@ -137,12 +187,18 @@ sub semiparse ($) { $q ||= '"'; push @o, { T => 'heredoc', Q => $q, Delim => $d, E => $&, P => "<<$q$d$q" }; - s{^ - ( .* \n ) - ( (?: (?! $d) .* \n )* ) - $d \n - }{ $1 }xe or die "missing end of here doc $d\n"; - $o[$#o]{V} = $2; + if (s{^ + ( .* \n ) + ( (?: (?! $d \n ) .* \n )*? ) + $d \n + }{ $1 }xe) { + $o[$#o]{V} = $2; + } else { + m{^.*\n} or confess; + $_ = $&; + $o[$#o]{V} = $'; + $o[$#o]{Invented} = 1; + } } elsif (s{^ (["'])( (?: [^\\'"] | \\ [^"'] | (?! \1 ) [^"] @@ -176,6 +232,7 @@ sub semiparse ($) { next if grep { !is_string($_) } @inputs; my $q = $inputs[0]{Q}; next if grep { $_->{Q} ne $q } @inputs; + next if grep { $_->{Invented} } @inputs; my $new = { T => 'joinedstrings', E => (join '.', map { $_->{E} } @inputs), P => (join '.', map { $_->{P} } @inputs), @@ -222,6 +279,7 @@ sub analyse_chunk_core () { next if $x->{E} eq $y->{E}; next if $x->{E} eq 'sprintf' and $y->{E} eq 'f_'; next if $x->{E} eq 'die' and $y->{E} eq 'confess'; + next if $x->{E} eq 'die' and $y->{E} eq 'fail'; if ($y->{E} eq '+' and @ys >= 3 and $ys[0]{E} eq '(' @@ -266,7 +324,7 @@ sub analyse_chunk_core () { } if ($ye eq 'f_') { my $fmt = $y->{V}; - die "no percent in _f string\n" unless $fmt =~ m{\%}; + die "no percent in f_ string\n" unless $fmt =~ m{\%}; next unless $string_changed; die "f_ old string '-quoted\n" if $x->{Q} ne '"'; my $xs = $x->{V}; @@ -282,10 +340,12 @@ sub analyse_chunk_core () { $xs = substr($xs, length($lit)); }; for (;;) { + #print STDERR Dumper($fmt, $xs, \@xs, @ys); if ($fmt !~ m{\%[^\%]}) { $exactly->($fmt, '(tail)'); $fmt = ''; - die "text deleted from end of string\n" if length $xs; + die "text deleted from end of string: ".qp($xs)."\n" + if length $xs; last; } $exactly->($`, '(literal)'); @@ -354,6 +414,8 @@ sub analyse_chunk () { return unless length $@; if ($@ =~ m{^missing end of here doc (\S+)\n}) { # fudge this + # (this never happens now, but in the future we might + # want this code again eg to try adding to the chunk) $before .= "\n$1\n"; $after .= "\n$1\n"; next;