#!/usr/bin/perl -w
use strict;
use Carp;
+use Data::Dumper;
my @d = <>;
+unshift @d, "# dummy line to make line 1 index 1 in \@d\n";
+
+our $i_last_l_ok = -1;
+our $count_i_last_l_ok;
sub l_ok ($) {
my ($i) = @_;
+
+ if ($i == $i_last_l_ok) {
+ confess $i if $count_i_last_l_ok++ > 50;
+ } else {
+ $count_i_last_l_ok = 0;
+ $i_last_l_ok = $i;
+ }
+
return unless $i < @d;
$_ = $d[$i];
+ #print STDERR "L $i\n";
1;
}
our ($before, $after);
sub analyse_chunk () {
- print Dumper($before, $after);
+ print Dumper($ichunkstart, $ichunkend, $before, $after);
+ flush STDOUT;
}
for ($ifilehead = 0; l_ok $ifilehead; $ifilehead++) {
m{^diff} or next;
- while (l_ok $ifilehead and m{^index|^---|^\Q+++\E}) { }
+ while (l_ok $ifilehead and m{^diff|^index|^---|^\Q+++\E}) { $ifilehead++ }
$ihunkhead = $ifilehead;
while (l_ok $ihunkhead) {
- m{^\@\@} or confess "$_ ?";
+ m{^\@\@} or confess "$ihunkhead $_ ?";
my $i = $ihunkhead + 1;
- for (;;) {
+ for (; ; $i++) {
if (!l_ok $i or m{^ } or m{^\@\@}) {
if (defined $ichunkstart) {
$ichunkend = $i;
}
l_ok $i or last;
m{^\@\@} and last;
- } elif (m{^[-+]}) {
+ } elsif (m{^[-+]}) {
my $which = $& eq '-' ? \$before : \$after;
- $ichunkfirst //= $i;
+ $ichunkstart //= $i;
$$which //= '';
$$which .= $';
} else {
- confess "$_ ?";
+ confess "$i $_ ?";
}
}
+ $ichunkend = $i;
$ihunkhead = $i;
}
}