#! /bin/csh -f

set cmd = "$0"
set usage = "${cmd:t} [ -title STRING ] < IMAGELIST > PAGE.html"

# Writes an HTML page to stdout displaying
# all image files listed in the standard input.

set title = "Image index"

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

if ( $#argv != 0 ) then
  echo "usage: ${usage}"; exit 1
endif

set tmp = "/tmp/$$"
set imlist = ${tmp}-list
cat > ${imlist}

if ( -z ${imlist} ) then
  /bin/rm ${imlist}
  exit 1
endif

cat <<EOF
<html>
<head><title>${title}</title></head>
<body>
<h1>${title}</h1>

<p>
EOF

foreach img ( `cat ${imlist}` )
  echo '<img src = "'"${img}"'" border=0 alt="'"${img}"'">' 
end

cat <<EOF
</p>

<hr>
<i>Generated on `date`</i>
</body>
</html>
EOF

/bin/rm -f ${imlist}
