#!/bin/sh

intro=intro/yref
platform=platform/yref

find ${intro} ${platform} -type f ! -name '*.bak' ! -name '*~' \
| xargs perl -p -i.bak -e 's/\n//'

( cd ${intro}; ls | sed -ne 's/\.xml$//p' ) \
| while read term
do
  find intro -type f -name '*.xml' \
  | xargs grep "\&yref\.${term};" > /dev/null \
  || echo "Not referenced: ${intro}/${term}.xml"
done

sed -ne "s#^<!ENTITY yref\.\([a-z0-9.]*\) SYSTEM .*#\1#p" \
	intro/yref.xml \
| while read term
do
  [ -r "${intro}/${term}.xml" ] \
  || echo "Entity ${term} from ${intro}.xml points to nowhere."
done
