File: foomatic-fix-xml.in

package info (click to toggle)
foomatic-db-engine 4.0.11-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,780 kB
  • ctags: 512
  • sloc: perl: 12,175; ansic: 6,958; python: 1,139; makefile: 243; sh: 215; xml: 83
file content (58 lines) | stat: -rw-r--r-- 1,532 bytes parent folder | download | duplicates (10)
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
#!@PERL@

# This is foomatic-fix-xml, run this program if you have compiled
# foomatic-perl-data against libxml 1.x and you have old database
# entries with a leading blank line. libxml 1.x chokes on leading
# blank lines.

my $libdir;
if ($#ARGV > -1) {
    if ($ARGV[0] eq "-h") {
	print STDERR "
Usage: foomatic-fix-xml [ dir ]

       dir: Directory where the Foomatic database is located, default:
            /usr/share/foomatic

";
	exit(1);
    } else {
	$libdir = $ARGV[0];
    }
} else {
    $libdir = "/usr/share/foomatic";
}

# A little bit of statistics
my $filesmodified = 0;

# Read the directory with the driver's XML entries
for my $dir (qw/printer driver opt/) {
    opendir DIR, "$libdir/db/source/$dir" ||
	die "Cannot open driver XML directory!\n";
    my $file;
    while ($file = readdir(DIR)) {
	next if ($file !~ /.xml$/);
	open XMLFILE, "< $libdir/db/source/$dir/$file" || die "   Database entry $file cannot be read!\n";
	my @contents = <XMLFILE>;
	close XMLFILE;
	my $filemodified = 0;
	while ($contents[0] =~ /^\s*$/) {
	    shift @contents;
	    $filemodified = 1;
	}
	if ($contents[0] !~ /^</) {
	    $contents[0] =~ s/^\s*</</;
	    $filemodified = 1;
	}
	if ($filemodified) {
	    open XMLFILE, "> $libdir/db/source/$dir/$file" || die "   Database entry $file cannot be written!\n";
	    print XMLFILE join('', @contents);
	    close XMLFILE;
	    print "Corrected file $libdir/db/source/$dir/$file\n";
	    $filesmodified ++;
	}
    }
}
closedir DIR;
print "\nCorrected $filesmodified files.\n\n";