#!/bin/ksh -f
# Builds composite DTD from modules. Expects $1 to be name of DTD,
# $2 to be a reference to a valid, minimal XML file. See below.
#
# The result is a flattened DTD '[$1].flat'.
# Requires James Clark's spam, UNIX sed.
#
# The dummy file should be a valid, minimal XHTML document whose
# DOCTYPE declaration contains a SYSTEM reference to the desired
# DTD. For example:
#
#     <?xml version="1.0" ?>
#     <!DOCTYPE html SYSTEM "xhtml-custom.dtd" >
#     <html>
#     ...
#     </html>
#
# Author: Murray Altheim <altheim@eng.sun.com>
# origin $Id: _flat,v 1.4 1999/04/02 14:27:28 ahby Exp $

# set source dtd filename
if [ $# -ne 2 ]; then
  echo "Usage: % _flat dtd-filename dummy.xml"
  exit 0
else
  # set flattened dtd filename
  flat="$1.flat"
  # set dummy file
  dummy="$2" 
fi

dtd=$1 

echo "_flat: Removing old files..."
#rm sperr
[ -f $flat ] && rm $flat

#spam a new dtd:
echo "_flat: Creating new '$flat'..."
spam -p -p $dummy > /tmp/flat.temp

#replace %charents; with file, then remove document wrapper:
sed 's/<\!DOCTYPE [Hh][Tt][Mm][Ll] \[//' /tmp/flat.temp > /tmp/flat.temp2
sed '/^]>$/,$d' /tmp/flat.temp2 > $flat

rm /tmp/flat.temp
rm /tmp/flat.temp2

echo "_flat: complete."
