2001-10-17 16:40:30 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2002-04-17 20:10:18 +02:00
|
|
|
use strict;
|
2001-10-17 16:40:30 +02:00
|
|
|
use IO::File;
|
|
|
|
|
|
|
|
my @differ = qw(diff -bw);
|
|
|
|
my $oldtmp = "/tmp/difflog$$.old";
|
|
|
|
my $newtmp = "/tmp/difflog$$.new";
|
|
|
|
|
|
|
|
my $newfn = pop(@ARGV);
|
|
|
|
my $oldfn = pop(@ARGV);
|
|
|
|
my (%oldhash, %newhash);
|
|
|
|
|
2002-04-18 16:35:17 +02:00
|
|
|
my $article = q[(?:(?:workers?|users?)/)?\d{4,5}];
|
2002-04-17 20:10:18 +02:00
|
|
|
|
2001-10-17 16:40:30 +02:00
|
|
|
read_file($newfn, \%newhash);
|
|
|
|
read_file($oldfn, \%oldhash);
|
|
|
|
|
|
|
|
my @oldentries = reverse sort keys %oldhash;
|
|
|
|
my @newentries = reverse sort keys %newhash;
|
|
|
|
|
|
|
|
my $old = 0;
|
|
|
|
my $new = 0;
|
|
|
|
|
|
|
|
while ($old < @oldentries && $new < @newentries)
|
|
|
|
{
|
|
|
|
my $cmp = $oldentries[$old] cmp $newentries[$new];
|
|
|
|
if ($cmp > 0)
|
|
|
|
{
|
|
|
|
printf("only in %s: %s\n\n", $oldfn, $oldentries[$old++]);
|
|
|
|
}
|
|
|
|
elsif ($cmp < 0)
|
|
|
|
{
|
|
|
|
printf("only in %s: %s\n\n", $newfn, $newentries[$new++]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($oldhash{$oldentries[$old]} ne $newhash{$newentries[$new]}) {
|
|
|
|
my $oldfh = new IO::File("/tmp/difflog$$.old", 'w');
|
|
|
|
$oldfh->print($oldhash{$oldentries[$old]});
|
|
|
|
$oldfh->close();
|
|
|
|
my $newfh = new IO::File("/tmp/difflog$$.new", 'w');
|
|
|
|
$newfh->print($newhash{$newentries[$new]});
|
|
|
|
$newfh->close();
|
|
|
|
open(DIFF, join(' ', @differ, @ARGV, $oldtmp, $newtmp, '|'));
|
|
|
|
my @lines = <DIFF>;
|
|
|
|
close(DIFF);
|
|
|
|
unlink </tmp/difflog$$.*>;
|
|
|
|
if (@lines)
|
|
|
|
{
|
|
|
|
print "diff for ", $oldentries[$old], ":\n";
|
|
|
|
map {
|
|
|
|
s/$oldtmp/$oldfn/;
|
|
|
|
s/$newtmp/$newfn/;
|
|
|
|
} @lines;
|
|
|
|
print @lines, "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++$old;
|
|
|
|
++$new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while ($old < @oldentries)
|
|
|
|
{
|
|
|
|
printf("only in %s: %s\n", $oldfn, $oldentries[$old++]);
|
|
|
|
}
|
|
|
|
|
|
|
|
while ($new < @newentries)
|
|
|
|
{
|
|
|
|
printf("only in %s: %s\n", $newfn, $newentries[$new++]);
|
|
|
|
}
|
|
|
|
|
2002-04-17 20:10:18 +02:00
|
|
|
sub append_entry
|
|
|
|
{
|
|
|
|
my ($hashref, $entry, $tag, $block) = @_;
|
|
|
|
|
|
|
|
if (exists($hashref->{$entry})) {
|
|
|
|
$hashref->{$entry} .= "$tag\n$block";
|
|
|
|
} else {
|
|
|
|
$hashref->{$entry} = '';
|
|
|
|
if (defined($tag) || defined($block)) {
|
|
|
|
$hashref->{$entry} .= "$tag\n$block";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub make_entries
|
|
|
|
{
|
|
|
|
my ($hashref, $entry, $tag, $block) = @_;
|
|
|
|
|
|
|
|
if ($entry =~ s/($article)/ARTICLE/) {
|
|
|
|
my $key = $1;
|
|
|
|
$key =~ s:workers?/::;
|
|
|
|
&append_entry($hashref, $key, $tag, $block);
|
|
|
|
while ($entry =~ s/($article)/ARTICLE/) {
|
|
|
|
$key = $1;
|
|
|
|
$key =~ s:workers?/::;
|
|
|
|
&append_entry($hashref, $key, $tag, $block);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
&append_entry($hashref, $entry, $tag, $block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-17 16:40:30 +02:00
|
|
|
sub read_file
|
|
|
|
{
|
|
|
|
my $fn = shift;
|
|
|
|
my $hashref = shift;
|
|
|
|
my $fh = new IO::File($fn, 'r');
|
|
|
|
my ($tag, $date, $entry, $block);
|
|
|
|
|
2002-04-17 20:10:18 +02:00
|
|
|
my $attrib = q[(?:\w+\s+)*] . $article;
|
|
|
|
$attrib = q[(?:[^/]*\D[:,]\s*)?] . $attrib;
|
2001-10-17 16:40:30 +02:00
|
|
|
$attrib = qq[(?:unposted|$attrib)];
|
|
|
|
$attrib = qq[(?:(?:$attrib,\\s*)*$attrib)];
|
|
|
|
|
|
|
|
$hashref->{unattributed} = $block = '';
|
|
|
|
|
|
|
|
while (my $line = $fh->getline())
|
|
|
|
{
|
|
|
|
if ($line =~ /(\d{4}-\d\d-\d\d)\s+.+\s+<.+\@.+>/i) {
|
|
|
|
$date = $1;
|
|
|
|
$block =~ s/\n*\Z/\n/;
|
|
|
|
if ($entry) {
|
2002-04-17 20:10:18 +02:00
|
|
|
&make_entries($hashref, $entry, $tag, $block);
|
2001-10-17 16:40:30 +02:00
|
|
|
} elsif ($tag) {
|
|
|
|
$hashref->{unattributed} .= "\n$tag$block";
|
|
|
|
}
|
|
|
|
$entry = $block = '';
|
|
|
|
$tag = $line;
|
|
|
|
} elsif ($line =~ /\* ((?:$attrib)[^:]*):/) {
|
|
|
|
my $next = $1;
|
|
|
|
if ($entry) {
|
|
|
|
$block =~ s/\n*\Z/\n/;
|
2002-04-17 20:10:18 +02:00
|
|
|
&make_entries($hashref, $entry, $tag, $block);
|
2001-10-17 16:40:30 +02:00
|
|
|
}
|
2002-04-17 20:10:18 +02:00
|
|
|
&make_entries($hashref, $next);
|
2001-10-17 16:40:30 +02:00
|
|
|
$entry = $next;
|
|
|
|
$block = $line;
|
|
|
|
} else {
|
|
|
|
$block .= $line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$fh->close();
|
|
|
|
}
|