#!/bin/csh -f

# Sets up .html files to be used by all the include constructs on the
# same line as a <!-- incite --> construct in the HTML files in the
# argument list or for standard input.

set debug = 1

set webroots = (`cat $* | sed -n 's+.*<\\!-- incite -->.*virtual="\(.*\).html".*+\1+p'`)

set noglob

foreach webroot ($webroots)
  set fullroot = $webroot
  if ("$webroot" =~ /*) then # Path translation as in ~/bin/www/avail
    set noglob
    set fullroot = `echo $webroot | sed "s@^/\(~[a-zA-Z][^/]*\)@\1/$WEB_USER_DIR@"`
    set fullroot = `echo $fullroot | sed "s@^/[^~]*@$DOCUMENT_ROOT&@"`
    unset noglob
  endif
  set dir = $fullroot:h
  set roottail = $fullroot:t
  if ($dir == $roottail)  set dir = .
  if ($debug) echo htmlincites:   webroot: $webroot  fullroot: $fullroot
  if ($debug) echo htmlincites:   dir: $dir roottail:  $roottail
  del $dir $roottail.html
  echo "Generating $fullroot.html ..."
  htmlcite $roottail > $fullroot.html
  echo '<\!--#include virtual="/~rig/cgi-bin/avail/'"$webroot.{fulltext,abstract}"'" -->'\
    >> $fullroot.html
end
