Listing of lemcheck.plx

#!/usr/bin/perl
use warnings; use strict; use open 'utf8';
use lib '/usr/local/share/epsd/lib';
use lib '/usr/local/share/cdl/tools';
use ePSD; ePSD::load();
use CDL::Expand2;
use CDL::XML;
use CDL::NS;

binmode STDERR, 'utf8';

my $file = '';
my $line = 0;
my %reported = ();

if ($#ARGV >= 0) {
    foreach my $f (@ARGV) {
        do_one_file($f);
    }
} else {
    while (<>) {
        chomp;
        do_one_file($_);
    }
}

sub
do_one_file {
    my $f = shift;
    if ($f =~ /^[A-Z]\d+$/) {
        $f = expand("$f.xtf");
    }
    my $x = load_xml($f) || return;
    walk($x);
}

sub
walk {
    my $n = shift;
    foreach my $c ($n->childNodes()) {
        if ($c->isa('XML::LibXML::Element')) {
            if ($c->localName() eq 'w') {
                my $lemma = $c->getAttribute('lemma') || next;
                foreach my $l (split(/\|/,$lemma)) {
                    if ($l && $l =~ /\[/) {
                        $l =~ s/^\++//;
                        my $eid = ePSD::sid_from_cfgw($l);
                        if (!$eid) {
                            warn("$file:$line: $l not in ePSD\n")
                                unless $reported{$l}++;
                        }
                    }
                }
            } else {
                walk($c);
            }
        } elsif ($c->isa('XML::LibXML::PI')) {
            my $n = $c->getName();
            my $d = $c->getData() || '';
            if ($n eq 'atf-file') {
                $file = $d;
            } elsif ($n eq 'atf-line') {
                $line = $d;
            }
        }
    }
}

1;