#!/bin/csh -f

# Usage: htmlmakesoln fileroot ...

# You can actually include an extension in fileroot, but you get the
# same behavior from "htmlmakesoln foo.html" or "htmlmakesoln foo.dvi" as from
# "htmlmakesoln foo".

# This command creates a slightly modified version of fileroot.html on
# fileroot-soln.html by removing the word "soln" and the HTML comment
# syntax from constructs in the form "<-- soln ... -->" (one such per line).

umask 22

set tempfile = /tmp/htmlmakesoln.$user.$$

foreach file ($*)

set inputbase = $file:r

sed 's+<\!-- soln \(.*\) -->+\1+' $inputbase.html \
  > $tempfile

diff $tempfile $inputbase.html > /dev/null
if ($status == 1) then
  del . ${inputbase}-soln.html
  echo "htmlmakesoln: Creating new ${inputbase}-soln.html"
  mv $tempfile ${inputbase}-soln.html
else
  echo "htmlmakesoln: Could not convert ${inputbase}.html to ${inputbase}-soln.html"
  rm -f $tempfile
endif

end
