#!/bin/sh
# USAGE: 
#        htmconv <filename> 
#   Where <filename> is the source file (or files) to be updated.
#  
# EXAMPLES:
#	htmconv ch1.htm
#	htmconv ch1.htm ch5.htm apa.htm
#	htmconv server.813/a63840/*.htm
#
# NOTES:
#   Before running this script, you must set the HTMCONV_HOME environment
#   variable.  This is the working directory where temporary files are
#   created (and later removed).
#   

#check arguments
if  [ $# -eq 0 ] 
then
  echo "Usage: htmconv <filename1> [<filename2>] ... [<filenamen>]"
  echo ""
  echo "Note that <filename> is read AND CHANGED!" 
  echo ""
  exit
fi

# set temporary filename
temp=tmp"$$"htmconv

#Now for each file passed as an argument, run sed script
for i in $* 
do 
  echo Converting file....$i
  for j in htm.sed ;
  do
    if [ -f $HTMCONV_HOME/$j ]
    then
      sed -f $HTMCONV_HOME/$j $i > $temp
      cp $temp $i
    else
      echo Error: $HTMCONV_HOME/$j does not exist. Did you set HTMCONV_HOME "?"
    fi
  done
done
rm $temp
