#!/bin/tcsh -f

set fulldir = "`pwd`"
set dirtail = $fulldir:t
set dirhead = $fulldir:h
set dirpar = $dirhead:t

set wwwacargs = Greenberg-friends
set rolldescr = rolldescr.html

if ($#argv >= 1) then
  set wwwacargs = "$*"
endif

wwwac $wwwacargs

set title = "$dirpar $dirtail"

if (! -e $rolldescr) then
  echo $title > $rolldescr
  chmod go-r .
  chmod go+x .
  chmod -x *.jpg *.JPG
  chmod +r *.jpg *.JPG
else
  set title = "$title = `head -n 1 $rolldescr`"
endif

if (! -e $dirtail.html) ln -s index.html $dirtail.html

echo "<HTML>\
<HEAD>\
<TITLE>Ronald I. Greenberg's $title</TITLE>" > index.html
echo '</HEAD>\
<BODY>\
<\!--#include virtual="'$rolldescr'" -->\
<p>Click on picture or exposure number appearing <em>before</em> it to see full size version.  Selected pictures have captions at bottom.\
<p>' >> index.html

foreach file ([0-9][^0-9]*.{jpg,JPG,html} /dev/null*)
   if ("$file" !~ /dev/null*) mv $file 0$file
end

mved =_edited.jpg =.jpg
mved =_edited.JPG =.JPG

foreach foto (*.jpg *.JPG)
   echo >`tty` processing $foto
   set froot = $foto:r
   set expnum = `echo $froot | sed 's+\([0-9]*\)[hv]+\1+'`
   set thumbnail = .$foto
   set caption = $froot.html
   set fotowrap = .$caption
   djpeg -scale 1/8 $foto | cjpeg -optimize > $thumbnail
   echo '<A HREF="'$fotowrap'"><font size=-2>'$expnum'</font><IMG SRC="'$thumbnail'" ALT="[picture '$froot" thumbnail: `rdjpgcom -verbose $thumbnail`"']"></A>' >> index.html
   echo '<IMG SRC="'$foto'" ALT="[picture '$froot": `rdjpgcom -verbose $foto`"']">' > $fotowrap
   if (-e $caption) echo '<\!--#include virtual="'$caption'" -->' >> $fotowrap
end

echo '<\!--#include virtual="/~rig/cgi-bin/silentcount/~rig/counts/photos/'$dirpar$dirtail'.txt" -->' >> index.html

echo '<\!--#include virtual="/~rig/include/update-validate.html" -->' >> index.html
