#!/bin/csh 
#
# Using ls create the list of images you want to work with.
# Here my images are all p000xxx.jpg and I am converting them to smaller
# files
# $Id: onetwothree.csh,v 1.8 2007/03/26 23:07:17 teuben Exp $
#
# WARNING: this is pretty old code and not used anymore. I'm now using
#          jigl with add-jpg and do_sync instead.

if ( $#argv < 2 ) goto Usage

foreach settable ( $* )
   echo $settable
   set $settable
end

set files=(`cat $photos`)
set copyright=`date +%Y`
set username=`grep $USER /etc/passwd | awk '{split($0,a,":");print a[5]}'`
set nfiles=$#files
echo Found $nfiles files to check for.

if ($?title == 0 && -e title.txt) then
  set title=(`cat title.txt`)
endif


#
# create the index page.
#
if ( -e index.html ) then
   echo "Saving old index.html in index.html.back"
   mv index.html index.html.back
endif

echo '<body bgcolor=#ffffff fgcolor=#000000>'  > index.html
echo '<html>'                  >> index.html
echo '<head>'                  >> index.html
echo "<title> $title </title>" >> index.html
echo '</head>'                 >> index.html
echo '<h1>' $title '</h1><hr>' >> index.html
echo '<b>Photos</b><br>'       >> index.html

foreach f ($files)
  set fr=$f:r
  set fe=$f:e
  echo '<a href="sm_'$fr'.html"><img src="th_'$fr'.'$fe'" alt="' >> index.html
  if (-e $f.desc) then
    head -1 $f.desc >> index.html
  else
    echo "no description yet" >> index.html
  endif
  echo '"></a>' >> index.html
end

if ( $?movies ) then
   set movielist=(`cat $movies`)
   echo "<hr><b>Movies</b><br>"                                  >> index.html
   foreach f ( $movielist )
      set msize = `du -sk $f | awk '{print $1}'`
      echo '<a href="'$f'"> '                                    >> index.html
      if (-e $f.desc) then
         head -1 $f.desc                                         >> index.html
      else
	echo "Undescribed movie"                                 >> index.html
      endif
      echo "($msize KB)"                                         >> index.html
      echo '</a><br>'                                            >> index.html
   end
endif
echo '<hr><a href="..">Back to pictures directory</a>'>>index.html
echo '<br></body></html>'                                        >>index.html

#
# Create thumbnails and browser-sized images
#
foreach f ($files)
  if (! -e sm_$f) then
    echo sm_$f
    convert -quality 100 -geometry 640x480 $f sm_$f
    convert -quality 50 -geometry 160x120 sm_$f th_$f
  endif
end

#
#        start working on all files
#
set i=1
loop:

set f=$files[$i]
set fr=$f:r
set fe=$f:e

echo '<html>'                   > sm_$fr.html
echo '<head>'                  >> sm_$fr.html
echo "<title> $title </title>" >> sm_$fr.html
echo '</head>'                 >> sm_$fr.html

echo '<body bgcolor=#ffffff>'  >> sm_$fr.html
echo '<center>'                >> sm_$fr.html

echo "<h2> $title </h2> Copyright $copyright $username<hr>" >> sm_$fr.html

set prev=$i
set next=$i
@ prev--
@ next++
if ($i == 1)       set prev=$nfiles
if ($i == $nfiles) set next=1
set pfile=$files[$prev]
set nfile=$files[$next]


echo '<br> <B><<<<</B>'                                                 >>sm_$fr.html
echo '<A HREF='sm_${pfile:r}.html'>Previous picture</A> <b> |||| </B>'  >>sm_$fr.html
echo '<A HREF=index.html> Up</A> <b>||||</b> '                          >>sm_$fr.html
echo '<A HREF='sm_${nfile:r}.html'>Next picture</A> <b> >>>> </b>'      >>sm_$fr.html


if (-e $f.wav) then
  echo "<br>"                                                           >>sm_$fr.html
   echo '<a href="'$f'.wav">click here for a few seconds of sound</a>'  >>sm_$fr.html
endif

echo 'Click on any image for an even larger version<br>'                >>sm_$fr.html

echo '<a href="'$fr'.'${fe}'"><img src="sm_'$fr'.'${fe}'"></a><br><b>'  >>sm_$fr.html
if (-e $f.desc) then
  head -1 $f.desc                                                       >>sm_$fr.html
else
  #echo "no description yet"                                             >>sm_$fr.html
  echo "&nbsp;"                                             >>sm_$fr.html
endif
echo '</b><br>'                                                         >>sm_$fr.html
if (-e $f.desc) then
  tail -1 $f.desc                                                       >>sm_$fr.html
endif

echo '</center>'                                                        >>sm_$fr.html

echo '</body></html>'                                                   >>sm_$fr.html


@ i++
if ($i <= $nfiles) goto loop


exit 0

Usage:
echo 'Usage: $0 title="Your title" photos=<file containing list of images> [ movies=<file containing list of movies> ]'
echo '  Titles of more than one word must be quoted and use "&nbsp;" for spaces.'
exit 1

