File: normalize-gnumeric

package info (click to toggle)
gnumeric 1.8.3-5%2Blenny1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 76,344 kB
  • ctags: 20,451
  • sloc: ansic: 222,731; xml: 47,792; sh: 9,456; makefile: 2,590; yacc: 1,163; perl: 975; python: 86
file content (50 lines) | stat: -rwxr-xr-x 1,303 bytes parent folder | download
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
#!/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};
    }

    # 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;
}