normalize-gnumeric 1.72 KB
Newer Older
1 2 3
#!/usr/bin/perl -w
# -----------------------------------------------------------------------------

Morten Welinder's avatar
Morten Welinder committed
4 5 6 7 8 9
# 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.

10 11
my @items;
my $item = '';
12 13 14

while (<STDIN>) {
    # "x" out version numbers.
Morten Welinder's avatar
Morten Welinder committed
15
    if (m|^\s*<gnm:Version\s+Epoch="\d+"\s+Major="\d+"\s+Minor="\d+"\s+Full="[.0-9]+"/>\s*$|) {
16 17
	s/="[.0-9]+"/="x"/g;
    }
18 19 20
    if (m|^\s*<office:document-meta |) {
	s/( office:version=")[.0-9]+(")/$1XXX$2/;
    }
21

22 23
    s{(\bxmlns:gnm="http://www.gnumeric.org/v)\d+(\.dtd)"}{$1XX$2};

24
    if (m|^\s*<gnm:PrintInformation>\s*$| .. m|^\s*</gnm:PrintInformation>\s*$|) {
25
        # "x" out margins.
26
	if (m|^\s*<gnm:Margins>\s*$| .. m|^\s*</gnm:Margins>\s*$|) {
27
	    s/="[-.0-9a-zA-Z]+"/="x"/g;
28
	}
29 30 31

	# "x" out information from cups.
	s{(<gnm:(paper|orientation)>).*(</gnm:\2>)}{$1xxx$3};
32 33
    }

34 35 36 37
    if (m|^\s*<office:meta>\s*$| .. m|^\s*</office:meta>\s*$|) {
        s|(<meta:creation-date>).*(</meta:creation-date>)|$1XXX$2|;
    }

38 39 40 41 42
    if (m|^\s*<gnm:name>WorkbookView::do_auto_completion</gnm:name>\s*$| ..
	m|^\s*</gnm:Attribute>\s*$|) {
	s|(<gnm:value>).*(</gnm:value>)|$1xxx$2|;
    }

43
    # Sort names.
44
    if (0 && m|^\s*<gnm:Sheets>\s*$| .. m|^\s*</gnm:Sheets>\s*$|) {
45 46 47 48
	if (m|^\s*<gnm:Names>\s*$| .. m|^\s*</gnm:Names>\s*$|) {
	    if (m|^\s*<gnm:Names>\s*$|) {
		# Zip.
	    } elsif (m|^\s*</gnm:Names>\s*$|) {
49 50
		print sort @items;
		@items = ();
51
	    } else {
52
		$item .= $_;
53 54

		if (m|^\s*</gnm:Name>\s*$|) {
55 56
		    push @items, $item;
		    $item = '';
57 58 59 60 61 62 63 64
		}
		next;
	    }
	}
    }

    print;
}