#! /bin/csh -f 
# Last edited on 2008-02-04 20:49:25 by stolfi

set usage = "$0 FNUM VERS COMMENTS SIMILAR CTABLE" 

# Produces a listing of page FNUM, transcription VERS, in headerless
# HTML format, with words color-highlighted according to the
# dictionary file CTABLE.
#
# If COMMENTS is 1, includes #-comments; if 0, omits them.
#
# If SIMILAR = 0 colors only exact matches.
# If SIMILAR = 1 assumes [ktfp] [aoy] equivalence when coloring words.
# If SIMILAR = 2 also assumes [rsche] equivalence.

set script = "$0"; set script = "${script:t}"
set wdir = ${STOLFIHOME}/projects/voynich/work
set vdir = ${STOLFIHOME}/projects/voynich/work/Notes/050
set path = ( ${vdir} ${wdir} /bin /usr/bin )

# Gather command-line options:

if ( $#argv != 5 ) then
  html-error "$script: usage: ${usage}"; exit 0
endif

set fnum = "$1"; shift;
set version = "$1"; shift;
set comments = "$1"; shift;
set similar = "$1"; shift;
set ctable = "$1"; shift;

set vars = ( )

set pfile = "${vdir}/evt-pages/${fnum}"

if ( ! ( -r "${pfile}" ) ) then
  html-error 'Page "'"${fnum}"'" does not exist'; exit 0
endif

# Define word equivalence options:

if ( ${similar} == 1 ) then
  set vars = ( ${vars} \
    -v showSimilar=1 \
    -v erase_ligatures=0 \
    -v erase_plumes=0 \
    -v ignore_gallows_eyes=1 \
    -v join_ei=1 \
    -v equate_aoy=1 \
    -v collapse_ii=0 \
    -v equate_eights=0 \
    -v equate_pt=1 \
    -v erase_q=1 \
    -v erase_word_spaces=1 \
  )
else if ( ${similar} == 2 ) then
  set vars = ( ${vars} \
    -v showSimilar=1 \
    -v erase_ligatures=1 \
    -v erase_plumes=1 \
    -v ignore_gallows_eyes=1 \
    -v join_ei=1 \
    -v equate_aoy=1 \
    -v collapse_ii=1 \
    -v equate_eights=1 \
    -v equate_pt=1 \
    -v erase_q=1 \
    -v erase_word_spaces=1 \
  )
else
  set vars = ( ${vars} \
    -v showSimilar=0 \
  )
endif

# Add default color options:

set vars = ( \
  -v defaultColor="ff0000" \
  -v commentColor="99aabb" \
  -v indent=2 \
  ${vars} \
  -v script="${script}" \
)

# Text
cat ${pfile} \
  | colorize-text -f ${vdir}/eva2erg.gawk \
      -v colorTable="${ctable}" \
      -v version="${version}" \
      -v comments="${comments}" \
      -v similar="${similar}" \
      -v fnum="${fnum}" \
      ${vars}