chiark / gitweb /
auditor wip can call analyse_chunk
[dgit-junk.git] / i18n-diff-auditor
1 #!/usr/bin/perl -w
2 use strict;
3 use Carp;
4 use Data::Dumper;
5
6 my @d = <>;
7 unshift @d, "# dummy line to make line 1 index 1 in \@d\n";
8
9 our $i_last_l_ok = -1;
10 our $count_i_last_l_ok;
11
12 sub l_ok ($) {
13     my ($i) = @_;
14
15     if ($i == $i_last_l_ok) {
16         confess $i if $count_i_last_l_ok++ > 50;
17     } else {
18         $count_i_last_l_ok = 0;
19         $i_last_l_ok = $i;
20     }
21
22     return unless $i < @d;
23     $_ = $d[$i];
24     #print STDERR "L $i\n";
25     1;
26 }
27
28 sub l ($) {
29     my ($i) = @_;
30     confess $i unless l_ok $i;
31 };
32
33 our ($ifilehead, $ihunkhead, $ichunkstart, $ichunkend);
34 our ($before, $after);
35
36 sub analyse_chunk () {
37     print Dumper($ichunkstart, $ichunkend, $before, $after);
38     flush STDOUT;
39 }
40
41 for ($ifilehead = 0; l_ok $ifilehead; $ifilehead++) {
42     m{^diff} or next;
43     while (l_ok $ifilehead and m{^diff|^index|^---|^\Q+++\E}) { $ifilehead++ }
44     $ihunkhead = $ifilehead;
45     while (l_ok $ihunkhead) {
46         m{^\@\@} or confess "$ihunkhead $_ ?";
47         my $i = $ihunkhead + 1;
48         for (; ; $i++) {
49             if (!l_ok $i or m{^ } or m{^\@\@}) {
50                 if (defined $ichunkstart) {
51                     $ichunkend = $i;
52                     analyse_chunk();
53                     $ichunkstart = $ichunkend = $before = $after = undef;
54                 }
55                 l_ok $i or last;
56                 m{^\@\@} and last;
57             } elsif (m{^[-+]}) {
58                 my $which = $& eq '-' ? \$before : \$after;
59                 $ichunkstart //= $i;
60                 $$which //= '';
61                 $$which .= $';
62             } else {
63                 confess "$i $_ ?";
64             }
65         }
66         $ichunkend = $i;
67         $ihunkhead = $i;
68     }
69 }