#!/bin/csh -f

set ipp = 20;	#Image Per a Page

switch($argv[1])
case '-s':
	set subdirectory = "small_size";
	set head = "sm"
	set file_name = index
breaksw;
default:
case '-m':
	set subdirectory = "middle_size";
	set head = "md"
	set file_name = mindex
breaksw;
endsw

set a = 0
set b = 0
set c = 1
echo "<html>" > $file_name$b.html
echo "<head>" >> $file_name$b.html
echo "<title>" >> $file_name$b.html
echo "Images" >> $file_name$b.html
echo "</title>" >> $file_name$b.html
echo "<body>" >> $file_name$b.html
echo "<center>" >> $file_name$b.html

set tphoto = ( $subdirectory/* )

######## print "Index ..."
  set d = 0
  @ n = $#tphoto / $ipp + 1
  echo "<h2>" >> $file_name$b.html
  echo "Index" >> $file_name$b.html
  while( $d < $n ) 
  echo \<a href=\"$file_name$d.html\"\>$d \</a\> >> $file_name$b.html
  @ d = $d + 1
  end
  echo "</h2>" >> $file_name$b.html
  echo "<br><br><br>" >> $file_name$b.html

foreach i ( $tphoto )
@ a = $a + 1

set bigimage=`echo $i | sed -e 's;'$subdirectory'/'$head'_;;'`
echo $bigimage
if ( -f $bigimage )  then
echo \<a href=\"$bigimage\"\> >> $file_name$b.html
echo \<img src=\"$i\"\> >> $file_name$b.html
echo \</a\> >> $file_name$b.html
else
echo \<img src=\"$i\"\> >> $file_name$b.html
endif

if ( $a == $ipp ) then
@ c = $b + 1
echo "<br><h2>"  >> $file_name$b.html
######## print "Index ..."
  set d = 0
  @ n = $#tphoto / $ipp + 1
  echo "Index" >> $file_name$b.html
  while( $d < $n ) 
  echo \<a href=\"$file_name$d.html\"\>$d \</a\> >> $file_name$b.html
  @ d = $d + 1
  end
  echo "<br>" >> $file_name$b.html

echo \<a href=\"$file_name$c.html\"\>next\</a\> >> $file_name$b.html
echo "</h2>"  >> $file_name$b.html
echo "</center>" >> $file_name$b.html
echo "</body>"  >> $file_name$b.html
  @ c = $b
  @ b = $b + 1
  @ a = 0
  
echo "<html>" > $file_name$b.html
echo "<head>" >> $file_name$b.html
echo "<title>" >> $file_name$b.html
echo "Images" >> $file_name$b.html
echo "</title>" >> $file_name$b.html
echo "<body>" >> $file_name$b.html
echo "<center>" >> $file_name$b.html
echo "<h2>"  >> $file_name$b.html
echo \<a href=\"$file_name$c.html\"\>previous\</a\> >> $file_name$b.html
echo "<br>"  >> $file_name$b.html
######## print "Index ..."
  set d = 0
  @ n = $#tphoto / $ipp + 1
  echo "Index" >> $file_name$b.html
  while( $d < $n ) 
  echo \<a href=\"$file_name$d.html\"\>$d \</a\> >> $file_name$b.html
  @ d = $d + 1
  end
  echo "</h2>" >> $file_name$b.html
  echo "<br>" >> $file_name$b.html


endif

end

echo "<br>"  >> $file_name$b.html
######## print "Index ..."
  set d = 0
  @ n = $#tphoto / $ipp + 1
  echo "Index" >> $file_name$b.html
  while( $d < $n ) 
  echo \<a href=\"$file_name$d.html\"\>$d \</a\> >> $file_name$b.html
  @ d = $d + 1
  end
  echo "</h2>" >> $file_name$b.html

echo "</center>" >> $file_name$b.html
echo "</body>"  >> $file_name$b.html
