#!/bin/csh
# script to recreate picture index
echo "<title>Quozl's Pictures</title>" > index.html
echo "<h1>Quozl's Pictures</h1>" >> index.html
echo "<i>(Each small image below is linked to the full size copy.  Collection prepared `date`)</i><p><hr noshade>">>index.html

# make the icons directory if it isn't present
if ( ! -d icons ) then
  mkdir icons
endif

# clean out old icons
foreach file (icons/*.jpg)
  if ( ! -f ${file:t} ) then
    rm ${file}
  endif
end

# echo "<table border=0 cellpadding=10>" >> index.html

# build the new icons
foreach file (*.jpg)

  # if the icon file is not present
  if ( ! -f icons/${file:r}.jpg ) then
    echo ${file}

    # build a low quality progressive 1/8th scale jpg
    djpeg -scale 1/4 -pnm ${file} | \
      cjpeg -quality 40 -optimize -progressive > icons/${file:r}.jpg
  endif

  # write the HTML code for this image
  set dimensions=`rdjpgcom -verbose icons/${file:r}.jpg|grep "JPEG image is"`
  set x=`echo "${dimensions}"|cut -f4 -d" "|tr -d "w"`
  set y=`echo "${dimensions}"|cut -f6 -d" "|tr -d "h,"`
  set md=`stat ${file}|grep Modify|cut -f2-6 -d" "`
  set text=`rdjpgcom $file`
#   echo "<tr><td>" >> index.html
  cat << EOF >> index.html
<a href="${file}" title="${md} ${text}"><img src="icons/${file:r}.jpg" border=0 width=${x} height=${y}></a>
EOF
  # echo "</td><td>${text}</td></tr>" >> index.html
  # echo "</tr>" >> index.html
end

# echo "</table>" >> index.html
echo "<hr noshade>" >> index.html

echo "<i><a href=reindex.csh>Quozl's reindexing script</a></i><br>" >> index.html
echo "<i><a href=../>Quozl's main page</a></i><br>" >> index.html
echo "<i><a href=mailto:quozl@us.netrek.org>Quozl's mail address is quozl@us.netrek.org</a></i>" >> index.html
