Set version to v1.1
[mverbiste] / data / check-data.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use XML::Parser;
5
6
7 my $numErrors = 0;
8 my %personTable = ();
9 my $curTemplate;
10 my $curInflection;
11
12
13 sub error
14 {
15     my ($msg) = @_;
16
17     print "$0: ERROR: $msg\n";
18     $numErrors++;
19 }
20
21
22 sub handleStart
23 {
24     my ($expat, $el, %attr) = @_;
25
26     if ($el eq "template")
27     {
28         $curTemplate = $attr{name};
29         if (!defined $curTemplate)
30         {
31             error("<template> element without a 'name' attribute");
32         }
33     }
34     elsif ($el eq "p")
35     {
36         %personTable = ();
37     }
38     elsif ($el eq "i")
39     {
40         $curInflection = "";
41     }
42 }
43
44
45 sub handleChar
46 {
47     my ($expat, $str) = @_;
48
49     if (defined $curInflection)
50     {
51         $curInflection .= $str;
52     }
53 }
54
55
56 sub handleEnd
57 {
58     my ($expat, $el) = @_;
59
60     if ($el eq "i")
61     {
62         die unless defined $curInflection;
63         if (defined $personTable{$curInflection})
64         {
65             error("person in template $curTemplate has duplicate inflections ($curInflection)");
66         }
67         $personTable{$curInflection} = 1;
68         $curInflection = undef;
69     }
70 }
71
72
73 ###############################################################################
74
75 my $workDir = shift;
76 chdir($workDir) if defined $workDir;
77
78 my $parser = new XML::Parser(Handlers => {
79                 Start => \&handleStart,
80                 End => \&handleEnd,
81                 Char => \&handleChar,
82                 });
83 $parser->parsefile("conjugation-fr.xml");
84
85 exit($numErrors > 0);