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
|
#!/usr/bin/perl -w
# -----------------------------------------------------------------------------
# This script tries to normalize gnumeric files, i.e., remove insignificant
# differences due to versions, environment, or hash ordering.
#
# It is a perl script mucking with an xml file. Think it over. It is not
# hard to cheat this, but for purposes of testing code, it is fine.
my @items;
my $item = '';
while (<STDIN>) {
# "x" out version numbers.
if (m|^\s*<gnm:Version\s+Epoch="\d+"\s+Major="\d+"\s+Minor="\d+"\s+Full="[.0-9]+"/>\s*$|) {
s/="[.0-9]+"/="x"/g;
}
if (m|^\s*<gnm:PrintInformation>\s*$| .. m|^\s*</gnm:PrintInformation>\s*$|) {
# "x" out margins.
if (m|^\s*<gnm:Margins>\s*$| .. m|^\s*</gnm:Margins>\s*$|) {
s/="[-.0-9a-zA-Z]+"/="x"/g;
}
# "x" out information from cups.
s{(<gnm:(paper|orientation)>).*(</gnm:\2>)}{$1xxx$3};
}
if (m|^\s*<office:meta>\s*$| .. m|^\s*</office:meta>\s*$|) {
s|(<meta:creation-date>).*(</meta:creation-date>)|$1XXX$2|;
}
# Sort names.
if (0 && m|^\s*<gnm:Sheets>\s*$| .. m|^\s*</gnm:Sheets>\s*$|) {
if (m|^\s*<gnm:Names>\s*$| .. m|^\s*</gnm:Names>\s*$|) {
if (m|^\s*<gnm:Names>\s*$|) {
# Zip.
} elsif (m|^\s*</gnm:Names>\s*$|) {
print sort @items;
@items = ();
} else {
$item .= $_;
if (m|^\s*</gnm:Name>\s*$|) {
push @items, $item;
$item = '';
}
next;
}
}
}
print;
}
|