1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#!@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 (%checksums);
while (<>) {
chomp;
my ($sum, @keys) = split;
my (@pchunks) = ();
foreach my $k (@keys) {
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 $key = join('_', @chunks), '.prn';
if (! defined $checksums{$sum}) {
$checksums{$sum} = [];
}
push @{$checksums{$sum}}, $key;
}
}
sub min($$) {
my ($a, $b) = @_;
if ($a < $b) {
return $a;
} else {
return $b;
}
}
sub get_printer($) {
my ($mode) = @_;
$mode =~ s/_PrintingMode.*//;
return $mode;
}
sub get_mode($) {
my ($mode) = @_;
$mode =~ s/.*_PrintingMode/PrintingMode/;
return $mode;
}
foreach my $sum (sort keys %checksums) {
my ($out) = $sum;
my ($prun) = "";
my (@pchunks) = ();
my ($plen) = 0;
my (@runs) = sort map {
s/^\*//;
s/\.prn$//;
my ($printer) = get_printer($_);
my ($mode) = get_mode($_);
"${mode}_:$printer"
} @{$checksums{$sum}};
foreach my $run (@runs) {
my (@chunks) = split(/_/, $run);
my ($mchunks) = min(scalar @pchunks, scalar @chunks);
my ($i) = 0;
$out .= " ";
while ($i < $mchunks) {
if ($i > 0) {
$out .= '_';
}
if ($chunks[$i] ne $pchunks[$i]) {
my ($plen) = length $pchunks[$i];
my ($len) = length $chunks[$i];
my ($maxc) = min($len, $plen);
my ($dup) = 0;
while ($dup < $maxc) {
last if (substr($pchunks[$i], $dup, 1) ne
substr($chunks[$i], $dup, 1));
$dup++;
}
if ($dup > 2) {
$out .= "$dup+" . substr($chunks[$i], $dup);
} else {
$out .= "$chunks[$i]";
}
} else {
$out .= "";
}
$i++;
}
if ($i < scalar @chunks) {
if ($i > 0) {
$out .= '_';
}
$out .= join("_", @chunks[$i..$#chunks]);
}
$out =~ s/________/=/g;
$out =~ s/_______/!/g;
$out =~ s/______/"/g;
$out =~ s/_____/,/g;
$out =~ s/____/'/g;
$out =~ s/___/%/g;
$out =~ s/__/>/g;
@pchunks = @chunks;
}
print "$out\n";
}
|