#!/bin/sh

# Bourne Shell Server Pages compiler (shspc.sh)

SED=/bin/sed

out=`dirname $1`/`basename $1 it`

if [ -f $out ];
then
  if [ `ls -t $1 $out | head -1` != "$1" ];
  then
    sh $out;
    exit 0;
  fi
fi

# .shit file is newer than .sh file, so regenerate the .sh file.


rm -f $out

( echo "#!/bin/sh"
echo "# Generated from $1 on `date` by $0"
echo "#"
echo "echo '<!-- Bourne Shell Server Pages -->'"
echo "cat <<EOF";

cat $1 | $SED 's/<\$/EOF\n/g' | $SED 's/\$>/\ncat <<EOF\n/g' \
  | $SED 's/<`/\nEOF\neval /g' | $SED 's/`>/\ncat <<EOF\n/g' \
  | $SED 's/<\^/\nEOF\n\/usr\/local\/bin\/shspc\.sh/g' | $SED 's/\^>/\ncat <<EOF\n/g'

echo -e "\nEOF"; ) > $out

sh $out # shout, let it all out...
