#!/bin/sh

PATH=@l_prefix@/bin:${PATH}

echo "<?xml version='1.0'?>"
echo '<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">'
echo '<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">'

if test $# != 0 ; then
sed -n \
    -e ':input' \
    -e '/PUBLIC[^"]*$/{ N; b input }' \
    -e '/PUBLIC[^"]*"[^"]*$/{ N; b input }' \
    -e '/PUBLIC[^"]*"[^"]*"[^"]*$/{ N; b input }' \
    -e '/PUBLIC[^"]*"[^"]*"[^"]*"[^"]*$/{ N; b input }' \
    -e 's/\n/ /g' \
    -e 's/^ *\(--.*--\)/<!\1>/gp' \
    -e 's/PUBLIC *\("[^"]*"\) *\("[^"]*"\)/<public publicId=\1 uri=\2\/>/gp' \
    "$@"
fi

echo '</catalog>'
