chiark / gitweb /
auditor wip
[dgit-junk.git] / i18n-diff-auditor
1 #!/usr/bin/perl -w
2 use strict;
3 use Carp;
4
5 my @d = <>;
6
7 sub l_ok ($) {
8     my ($i) = @_;
9     return unless $i < @d;
10     $_ = $d[$i];
11     1;
12 }
13
14 sub l ($) {
15     my ($i) = @_;
16     confess $i unless l_ok $i;
17 };
18
19 our ($ifilehead, $ihunkhead, $ichunkstart, $ichunkend);
20 our ($before, $after);
21
22 sub analyse_chunk () {
23     print Dumper($before, $after);
24 }
25
26 for ($ifilehead = 0; l_ok $ifilehead; $ifilehead++) {
27     m{^diff} or next;
28     while (l_ok $ifilehead and m{^index|^---|^\Q+++\E}) { }
29     $ihunkhead = $ifilehead;
30     while (l_ok $ihunkhead) {
31         m{^\@\@} or confess "$_ ?";
32         my $i = $ihunkhead + 1;
33         for (;;) {
34             if (!l_ok $i or m{^ } or m{^\@\@}) {
35                 if (defined $ichunkstart) {
36                     $ichunkend = $i;
37                     analyse_chunk();
38                     $ichunkstart = $ichunkend = $before = $after = undef;
39                 }
40                 l_ok $i or last;
41                 m{^\@\@} and last;
42             } elif (m{^[-+]}) {
43                 my $which = $& eq '-' ? \$before : \$after;
44                 $ichunkfirst //= $i;
45                 $$which //= '';
46                 $$which .= $';
47             } else {
48                 confess "$_ ?";
49             }
50         }
51         $ihunkhead = $i;
52     }
53 }