chiark / gitweb /
auditor wip output
[dgit-junk.git] / i18n-diff-auditor
index 8c40f4a848822f6d7c7aa23a443ea99dac51b417..36f3da3005384a73e9a10de3e53da0e83ba531f0 100755 (executable)
@@ -91,7 +91,9 @@ sub prep_perlop () {
 
 prep_perlop();
 
-our ($ifilehead, $ihunkhead, $ichunkstart, $ichunkend);
+our ($ifilehead, $ifirsthunkhead);
+our ($ihunkhead, $ihunkend);
+our ($ichunkstart, $ichunkend);
 our ($before, $after);
 
 sub semiparse ($) {
@@ -159,18 +161,19 @@ sub analyse_chunk_core () {
        $$var = shift @$ary;
     };
     my ($x,$y);
-    my $next_before = sub { $next_something->(\@xs, \$x, 'before'); };
-    my $next_after  = sub { $next_something->(\@ys , \$y, 'after' ); };
+    my $next_x = sub { $next_something->(\@xs, \$x, 'before'); };
+    my $next_y = sub { $next_something->(\@ys, \$y, 'after' ); };
     my $is_string = sub { $_[0]{T} =~ m/heredoc|string/; };
     for (;;) {
        last unless @xs or @ys;
-       $next_before->();
-       $next_after->();
+       $next_x->();
+       $next_y->();
        next if $x->{E} eq $y->{E};
        my $string_changed;
-       if ($y->{E} eq '__' or $y->{E} eq '_f') {
-           $next_after->();
-           die "__ on non-string $y->{P}\n"     unless Sis_string->($y);
+       my $ye = $y->{E};
+       if ($ye eq '__' or $ye eq 'f_') {
+           $next_y->();
+           die "__ on non-string $y->{P}\n"     unless $is_string->($y);
            die "__ on was non-string $y->{P}\n" unless $is_string->($x);
            if ($y->{Q} ne "'") {
                die "var subst in new string\n"
@@ -182,13 +185,13 @@ sub analyse_chunk_core () {
            };
            $string_changed = $@;
        }
-       if ($y->{E} eq '__') {
+       if ($ye eq '__') {
            $_ = $y->{V};
            die "percent $& in __ ' string\n" if m{\%};
            die $string_changed if length $string_changed;
            next;
        }
-       if ($y->{E} eq 'f_') {
+       if ($ye eq 'f_') {
            my $fmt = $y->{V};
            die "no percent in _f string\n" unless $fmt =~ m{\%};
            next unless $string_changed;
@@ -210,10 +213,10 @@ sub analyse_chunk_core () {
                $fmt = $';
                if ($& eq '%%') { $exactly->('%'); next; }
                elsif ($& ne '%s') { die "unhandled %-subst $&\n"; }
-               $next_after->();
+               $next_y->();
                die "expected comma, got $y->{P}\n" unless $y->{E} eq ',';
                if ($xs =~ m{^\@}) {
-                   $next_after->();
+                   $next_y->();
                    die "\@... => not string" unless $is_string->($y);
                    die "\@... => $y->{P}" if $y->{Q} ne '"';
                    $exactly->($y->{V});
@@ -224,7 +227,7 @@ sub analyse_chunk_core () {
                    if (!$bras and !@ys) {
                        last;
                    }
-                   $next_after->();
+                   $next_y->();
                    if (!$bras and
                        (grep { $y->{E} eq $_ } qw( or xor and not ; : )
                         or $y->{T} eq 'ket'
@@ -263,10 +266,53 @@ sub analyse_chunk () {
     }
 }
 
+our @report;
+our $last_filehead = -1;
+
+sub report_on_hunk () {
+    return unless @report;
+    if ($last_filehead != $ifilehead) {
+       foreach (my $i=$ifilehead; $i<$ifirsthunkhead; $i++) {
+           print $d[$i];
+       }
+       $last_filehead = $ifilehead;
+    }
+    my $dummy_r = { S => (scalar @d)+1, E => (scalar @d)+1 };
+    my $r;
+    for (my $i=$ihunkhead; ; $i++) {
+       for (;;) {
+           $r //= shift @report;
+           $r //= $dummy_r;
+           last if $i < $r->{E};
+           confess unless $r->{Done} == 03;
+           $r = undef;
+       }
+
+       last unless $i<$ihunkend;
+
+       if ($i == $r->{S}) {
+           print "!! $r->{M}";
+           $r->{Done} |= 01;
+       }
+       if ($i >= $r->{S}) {
+           print "!";
+           $r->{Done} |= 02;
+       } else {
+           print " ";
+       }
+       print $d[$i];
+    }
+    confess unless $r = $dummy_r;
+}
+
 for ($ifilehead = 0; l_ok $ifilehead; $ifilehead++) {
     m{^diff} or next;
-    while (l_ok $ifilehead and m{^diff|^index|^---|^\Q+++\E}) { $ifilehead++ }
-    $ihunkhead = $ifilehead;
+    $ifirsthunkhead = $ifilehead;
+    while (l_ok $ifirsthunkhead and
+          m{^diff|^index|^---|^\Q+++\E}) {
+       $ifirsthunkhead++
+    }
+    $ihunkhead = $ifirsthunkhead;
     while (l_ok $ihunkhead) {
        m{^\@\@} or confess "$ihunkhead $_ ?";
        my $i = $ihunkhead + 1;
@@ -276,10 +322,9 @@ for ($ifilehead = 0; l_ok $ifilehead; $ifilehead++) {
                    $ichunkend = $i;
                    eval { analyse_chunk(); 1; };
                    if (length $@) {
-                       print Dumper('REPORT',
-                                    $ichunkstart, $ichunkend,
-                                    $before, $after,
-                                    $@);
+                       push @report, { M => $@,
+                                       S => $ichunkstart,
+                                       E => $ichunkend };
                    }
                    $ichunkstart = $ichunkend = $before = $after = undef;
                }
@@ -294,6 +339,8 @@ for ($ifilehead = 0; l_ok $ifilehead; $ifilehead++) {
                confess "$i $_ ?";
            }
        }
+       $ihunkend = $i;
+       report_on_hunk();
        $ichunkend = $i;
        $ihunkhead = $i;
     }