#!/bin/zsh
#
# Genererar indexsida fr fotoalbum.
#
# albumsida --help fr anvndarinstruktion.
#
# Av Johan Sundstrm <johan@id3.org>, 1998-10-11
#

if [[ $1 == "--help" || $1 == "hjlp" || $1 == "-h" || $ARGC == 0 ]]; then
   name=$(basename $0)
   echo "$name - Genererar indexsida fr fotoalbum"
   echo "Format: $name <titel>"
   echo
   echo "Exempel:"
   echo "$name \"DmD '$(date +%y)\""
   echo "En indexsida fr bilderna i nuvarande katalog skapas (\"${PWD}/index.html\") med titeln DmD '$(date +%y)."
else
   if [[ ! -r $PWD ]]; then
      echo "Du har ej lsrttighet i \"${PWD}\"."
   else
      if [[ ! -w $PWD ]]; then
	 echo "Du har inte skrivrttigheter i \"${PWD}\"!"
	 exit 5
      else
         if [[ -f ${PWD}/index.html && ! -w ${PWD}/index.html ]]; then
	    echo "Filen ${PWD}/index.html r skrivskyddad."
	    exit 5
	 else
            titel="$@"
	    bilder=(*.([jJ][pP][gG]|[gG][iI][fF]|[pP][nN][gG]))
	    echo "Skapar \"${PWD}/index.html\" med titeln \"$titel\""
	    ( echo "<comment>\$Id: albumsida,v 1.1 1998/12/23 01:04:40 johan Exp $</comment>"
	      echo "<dsida titel=\"$titel\">"
	      echo
	      echo "<stycke>"
              echo "<fotoalbum titel=\"$titel\">"
     
	      for a in $bilder; { echo "<fotobild bild=\"$a\"></fotobild>" }

              echo "</fotoalbum>"
              echo "</stycke>"
              echo
              echo "</dsida>" ) > index.html
 	    echo "Fotokatalogen innehller fljande bilder:"
	    echo $bilder
	    echo
	    echo "Glm inte att lgga till bildtexter mellan taggarna <fotobild>...</fotobild>!"
	 fi
      fi
   fi
fi
