]> git.lyx.org Git - lyx.git/blob - development/autotests/examineXmllintOutput.pl
Fix screen display of parts and chapters in default classes
[lyx.git] / development / autotests / examineXmllintOutput.pl
1 #! /usr/bin/env perl
2 # -*- mode: perl; -*-
3
4 # Examine output of 'xmllint --sax --html'
5
6 my $file = $ARGV[0];            # file to examine
7
8 my @tag = ();                   # tag entries = {"name" => strng, "count" => sequence number}
9 my $tagindex = 0;               # next tag to be written
10 $tag[$tagindex] = {};
11 my %errors = ();
12
13 if (open(FI, $file)) {
14   my $line = 0;
15   my %entities = ();
16   my $saxchartoprint = 0;
17   while(my $l = <FI>) {
18     $line++;
19     chomp($l);
20     if ($l =~ /^SAX.startElementNs\(([^, \)]+)/) {
21       # new tag
22       my $tag = $1;
23       $saxchartoprint = 0;
24       #print "Start tag $tag at line $line, tagindex = $tagindex\n";
25       my $newentry = 1;
26       if (defined($tag[$tagindex]->{"name"})) {
27         if ($tag[$tagindex]->{"name"} eq $tag) {
28           $tag[$tagindex]->{"count"} = $tag[$tagindex]->{"count"}+1;
29           $newentry = 0;
30         }
31       }
32       if ($newentry) {
33         $tag[$tagindex] = {};
34         $tag[$tagindex]->{"name"} = $tag;
35         $tag[$tagindex]->{"count"} = 1;
36       }
37       $tagindex++;
38       $tag[$tagindex] = {};
39     }
40     elsif ($l =~ /^SAX.endElementNs\(([^, \)]+)/) {
41       $saxchartoprint = 0;
42       my $tag = $1;
43       $tagindex--;
44       #print "End tag $tag at line $line, tagindex = $tagindex\n";
45       if ($tagindex < 0) {
46         die("tagindex < 0");
47       }
48       if ($tag[$tagindex]->{"name"} ne $tag) {
49         die("End tag $tag does not match " . $tag[$tagindex]->{"name"} . " at line $line");
50       }
51     }
52     elsif ($l =~ /^SAX.error: (.*)$/) {
53       my $err = $1;
54       if ($err =~ /Entity\s+'([a-zA-Z0-9]+)'\s+not defined$/) {
55         # Ignore Entity 'xxxx' not defined
56       }
57       elsif (! defined($errors{$err})) {
58         my $errmsg = "";
59         my $trenner = "";
60         for (my $i = 0; $i < $tagindex; $i++) {
61           $errmsg .= $trenner . $tag[$i]->{"name"} . "(" . $tag[$i]->{"count"} . ")";
62           $trenner = ", ";
63         }
64         $errors{$err} = $errmsg;
65         print "$err -> $errmsg\n";
66         # Print the next 3 lines starting with 'SAX.characters('
67         $saxchartoprint = 3;
68       }
69     }
70     elsif ($l =~ /: parser error :\s+(.*)$/) {
71       my $err = $1;
72       $errors{$err} = $errmsg;
73       if ($errmsg =~ /Entity\s+'([a-zA-Z0-9]+)'\s+not defined/) {
74         my $entity = $1;
75         if (! defined($entities{$entity})) {
76           $entities{$entity} = 1;
77           print "$errmsg\n";
78         }
79       }
80       else {
81         print "$l\n";
82         die("Unknown error $l");
83       }
84     }
85     elsif ($saxchartoprint > 0) {
86       $saxchartoprint--;
87       if ($l =~ /^SAX.characters\(([^\)]+)\)/) {
88         print "\t$1\n";
89       }
90     }
91   }
92 }
93 if (keys %errors) {
94   exit(1);
95 }
96 exit(0);