Commit c83b36bc authored by Pino Toscano's avatar Pino Toscano

Rewrite checkxrefs in Perl, and add it as test

Create a new version of checkxrefs in Perl, which makes working with
data structures a bit easier than in shell... (and there is no need to
spawn executables all the time)

Also, add it as build time test, so it isn't forgotten anymore.
parent d4908f43
########### install files ###############
kdoctools_create_handbook(index.docbook INSTALL_DESTINATION ${HTML_INSTALL_DIR}/en SUBDIR khelpcenter/glossary)
add_test(NAME glossary-checkxrefs
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/checkxrefs.pl
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
#!/bin/sh
DEFINED_ENTRIES=`sed -ne "s^.*<glossentry id=\"\(.*\)\">.*^\1^p" *.docbook`
REFERENCED_ENTRIES=`sed -ne "s^.*<glossseealso otherterm=\"\(.*\)\">.*^\1^p" *.docbook | uniq`
# Check for entries which are referenced but not defined.
for ENTRY in $REFERENCED_ENTRIES; do
if ! echo $DEFINED_ENTRIES | grep $ENTRY - > /dev/null 2>&1; then
echo "'$ENTRY' referenced but not defined!"
fi
done
#!/usr/bin/env perl
# Copyright (C) 2016 Pino Toscano <pino@kde.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
use warnings;
use strict;
use File::Find;
# Collect the *.docbook files in the current directory.
my @docbook_files = ();
sub collect {
push @docbook_files, $File::Find::name if $_ =~ /\.docbook$/;
}
find(\&collect, '.');
# Collect the list of entries, defined and referenced.
my %defined_entries;
my %referenced_entries;
for my $file (@docbook_files) {
open(DOCBOOK, "<", $file) || die "$0: can't open $file: $!";
while(<DOCBOOK>) {
if (/<glossentry id="(.*)">/) {
$defined_entries{$1} = 1;
} elsif (/<glossseealso otherterm="(.*)">/) {
$referenced_entries{$1} = 1;
}
}
close DOCBOOK;
}
# Check for entries which are referenced but not defined.
foreach my $entry (keys %referenced_entries) {
die "'$entry' referenced by not defined"
unless defined($defined_entries{$entry});
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment