]> git.lyx.org Git - lyx.git/blob - development/autotests/examineXmllintOutput.pl
Update sk.po
[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 $saxchartoprint = 0;
16   while(my $l = <FI>) {
17     $line++;
18     chomp($l);
19     if ($l =~ /^SAX.startElementNs\(([^, \)]+)/) {
20       # new tag
21       my $tag = $1;
22       $saxchartoprint = 0;
23       #print "Start tag $tag at line $line, tagindex = $tagindex\n";
24       my $newentry = 1;
25       if (defined($tag[$tagindex]->{"name"})) {
26         if ($tag[$tagindex]->{"name"} eq $tag) {
27           $tag[$tagindex]->{"count"} = $tag[$tagindex]->{"count"}+1;
28           $newentry = 0;
29         }
30       }
31       if ($newentry) {
32         $tag[$tagindex] = {};
33         $tag[$tagindex]->{"name"} = $tag;
34         $tag[$tagindex]->{"count"} = 1;
35       }
36       $tagindex++;
37       $tag[$tagindex] = {};
38     }
39     elsif ($l =~ /^SAX.endElementNs\(([^, \)]+)/) {
40       $saxchartoprint = 0;
41       my $tag = $1;
42       $tagindex--;
43       #print "End tag $tag at line $line, tagindex = $tagindex\n";
44       if ($tagindex < 0) {
45         die("tagindex < 0");
46       }
47       if ($tag[$tagindex]->{"name"} ne $tag) {
48         die("End tag $tag does not match " . $tag[$tagindex]->{"name"} . " at line $line");
49       }
50     }
51     elsif ($l =~ /^SAX.error: (.*)$/) {
52       my $err = $1;
53       if ($err =~ /Entity\s+'([a-zA-Z0-9]+)'\s+not defined$/) {
54         # Ignore Entity 'xxxx' not defined
55       }
56       elsif (! defined($errors{$err})) {
57         my $errmsg = "";
58         my $trenner = "";
59         for (my $i = 0; $i < $tagindex; $i++) {
60           $errmsg .= $trenner . $tag[$i]->{"name"} . "(" . $tag[$i]->{"count"} . ")";
61           $trenner = ", ";
62         }
63         $errors{$err} = $errmsg;
64         print "$err -> $errmsg\n";
65         # Print the next 3 lines starting with 'SAX.characters('
66         $saxchartoprint = 3;
67       }
68     }
69     elsif ($saxchartoprint > 0) {
70       $saxchartoprint--;
71       if ($l =~ /^SAX.characters\(([^\)]+)\)/) {
72         print "\t$1\n";
73       }
74     }
75   }
76 }
77 exit(0);