#!@PERL@ ## Copyright (C) 2016 Robert Krawitz ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use strict; my (%old_modes, %old_printers, %new_modes, %new_printers); my ($detail1) = 0; while ($#ARGV >= 0 && $ARGV[0] eq '-d') { $detail1++; shift @ARGV; } if ($#ARGV != 1) { die "Usage: $0 old_checksum_file new_checksum_file\n"; } sub get_printer($) { my ($mode) = @_; $mode =~ s/_PrintingMode.*//; return $mode; } sub get_mode($) { my ($mode) = @_; $mode =~ s/.*_PrintingMode/PrintingMode/; return $mode; } sub load_file($\%\%) { my ($file, $modes, $printers) = @_; if ($file =~ /\.bz2$/) { open(IN, "bunzip2 -c $file|") or die("Can't open checksum file $file: $!\n"); } elsif ($file =~ /.gz$/) { open(IN, "gunzip -c $file|") or die("Can't open checksum file $file: $!\n"); } else { open(IN, "$file") or die("Can't open checksum file $file: $!\n"); } my ($inline); while ($inline = ) { chomp $inline; my ($sum, @okeys) = split(/ /, $inline); my @keys = map { s/\.prn$//; s/^\*//; $_; } @okeys; my (@pchunks) = (); foreach my $k (@keys) { $k =~ s/=/________/g; $k =~ s/!/_______/g; $k =~ s/"/______/g; $k =~ s/,/_____/g; $k =~ s/'/____/g; $k =~ s/%/___/g; $k =~ s/>/__/g; my (@chunks) = split(/_/, $k, -1); foreach my $i (0..$#chunks) { if ($chunks[$i] eq '') { $chunks[$i] = $pchunks[$i]; } elsif ($chunks[$i] =~ /^([0-9]+)\+(.*)/) { $chunks[$i] = substr($pchunks[$i], 0, $1) . $2; } } my ($val) = join('_', @chunks); $val =~ s/(^[^:]*)_:(.*)/$2_$1/; $$modes{$val} = $sum; $$printers{get_printer($val)} = 1; @pchunks = @chunks; } } close IN; } load_file($ARGV[0], %old_modes, %old_printers); load_file($ARGV[1], %new_modes, %new_printers); my (%only_old_printers, %only_new_printers); foreach my $new_printer (keys %new_printers) { if (! defined $old_printers{$new_printer}) { $only_new_printers{$new_printer} = 1; } } foreach my $old_printer (keys %old_printers) { if (! defined $new_printers{$old_printer}) { $only_old_printers{$old_printer} = 1; } } my (@only_old_modes, @only_new_modes, @changed_modes); foreach my $old_mode (sort keys %old_modes) { next if defined $only_old_printers{get_printer($old_mode)}; if (defined $new_modes{$old_mode}) { if ($new_modes{$old_mode} ne $old_modes{$old_mode}) { push @changed_modes, $old_mode; } } else { push @only_old_modes, $old_mode; } } foreach my $new_mode (sort keys %new_modes) { next if defined $only_new_printers{get_printer($new_mode)}; if (!defined $old_modes{$new_mode}) { push @only_new_modes, $new_mode; } } my (@only_old_printers) = sort keys %only_old_printers; my (@only_new_printers) = sort keys %only_new_printers; sub print_changes($$@) { my ($tag, $detail, @changes) = @_; my ($prev_printer); return if ($#changes < 0); if (! $detail1) { print "$tag:\n"; } foreach my $m (@changes) { my ($printer) = get_printer($m); my ($mode) = get_mode($m); if ($detail > 1) { print "${printer}_${mode}\n"; } elsif ($detail) { if ($printer ne $prev_printer) { print " $printer:\n"; $prev_printer = $printer; } print " $mode\n"; } else { print " $mode\n"; } } print "\n"; } if (! $detail1) { print "*** Changes from $ARGV[0] to $ARGV[1] ***\n\n"; print_changes("Printers removed from $ARGV[1]", 0, @only_old_printers); print_changes("Printers added to $ARGV[1]", 0, @only_new_printers); print_changes("Modes removed from $ARGV[1]", 1, @only_old_modes); print_changes("Modes added to $ARGV[1]", 1, @only_new_modes); } print_changes("Changed printing modes", 1 + $detail1, @changed_modes);