#! /bin/csh -f

set usage = "$0 [EQUIVOPTIONS] UNITS..."

# Colorizes the specified text units and writes them to 
# files pages/${fnum}.html

set eqops = ( )

while ( ( $#argv > 0 ) && ( "x$1" =~ x-* ) )
  if ( ( $#argv >= 2 ) && ( "x$1" == "x-v" ) ) then
    set eqops = ( ${eqops} $1 $2 ); shift; shift
  else
    echo "usage: ${usage}"; exit 1
  endif
end

/bin/rm -f pages/*

set fnums = ( )
set ppfnum = "f0"
set pfnum = "f0"
foreach unit ( $* f999.P )
  set fnum = `echo ${unit} | sed -e 's/[.].*$//g'`
  echo ${fnum} ${unit}
  if ( ${fnum} != ${pfnum} ) then
    if ( ${pfnum} != "f0" ) then
      echo "</pre>" >> pages/${pfnum}.html
      if ( ${ppfnum} != "f0" ) then
        echo '<a href="'"${ppfnum}"'.html">Prev</a>' >> pages/${pfnum}.html
      endif
      echo '<a href="index.html">Index</a>' >> pages/${pfnum}.html
      if ( ${fnum} != "f999" ) then
        echo '<a href="'"${fnum}"'.html">Next</a>' >> pages/${pfnum}.html
      endif
      cat page-trailer.html \
        >> pages/${pfnum}.html
    endif
    if ( ${fnum} == "f999" ) break
    cat page-header.html \
      | sed -e 's/@PAGE@/'"${fnum}"'/g' \
      > pages/${fnum}.html
    echo "<pre>" >> pages/${fnum}.html
    set ppfnum = ${pfnum}
    set pfnum = ${fnum}
    set fnums = ( ${fnums} ${fnum} )
  else
    echo " " >> pages/${fnum}.html
  endif
  cat L16-eva/${unit} \
    | grep ';F>' \
    | colorize-text -f word-equiv.gawk \
        -v colorTable=pat-to-color.tbl \
        -v default="000000" \
        -v missing="9900ff" \
        ${eqops} \
    >> pages/${fnum}.html
end