#! /bin/csh -f

set usage = "$0 [ -bgcolor BG ] [ -fgcolor FG ] [ -title TITLE ] [ -date DT] < IN.txt > OUT.html "

set bgcolor = "#ffffff"
set fgcolor = "#000000"
set date = ""

set title = "No Title"

while ( ( $#argv >= 1 ) && ( "x$1" =~ x-* ) ) 
  if ( ( $#argv >= 2 ) && ( "x$1" == "x-bgcolor" ) ) then
    set bgcolor = "$2"; shift; shift;
  else if ( ( $#argv >= 2 ) && ( "x$1" == "x-fgcolor" ) ) then
    set fgcolor = "$2"; shift; shift;
  else if ( ( $#argv >= 2 ) && ( "x$1" == "x-title" ) ) then
    set title = "$2"; shift; shift;
  else if ( ( $#argv >= 2 ) && ( "x$1" == "x-date" ) ) then
    set date = "$2"; shift; shift;
  else 
    echo "unknown option $1";
    echo "usage: ${usage}"; exit 1
  endif
end

if ( $#argv != 0 ) then
  echo "excess arguments";
  echo "usage: ${usage}"; exit 1
endif

/bin/cat <<EOF
<html>
<head>
<title>${title}</title>
</head>
<body bgcolor="${bgcolor}" text="${fgcolor}">

EOF
if ( "x${date}" != "x" ) then
  echo "<small>${date}</small>" 
  echo " "
endif
if ( "x${title}" != "xNo Title" ) then
  echo "<h1>${title}</h1>" 
endif
/bin/cat <<EOF

<b><pre>
EOF
/bin/cat | /bin/sed -e 's/>/\&gt;/g' -e 's/</\&lt;/g' 
/bin/cat <<EOF
</pre></b>
</body>
</html>
EOF

