#!/usr/bin/perl
#
# album.pl -- make photo albums on your webpage!
#
# Copyright (C) 2001, Robert Harlander. All rights reserved.
#
# Comments, bug reports, and suggestions to 
# robert.harlander@cern.ch
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Emacs; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#

#- {{{ RCS

# $Id: album.pl,v 1.11 2007/11/27 11:16:31 rharland Exp $
# $Log: album.pl,v $
# Revision 1.11  2007/11/27 11:16:31  rharland
# *** empty log message ***
#
# Revision 1.10  2007/11/27 11:16:20  rharland
# * 'enlargebutton' introduced
# * clicking on picture moves to next picture
#
# Revision 1.9  2007/11/27 11:04:26  rharland
# *** empty log message ***
#
# Revision 1.8  2006/10/20 10:49:28  rharland
# *** empty log message ***
#
# Revision 1.7  2006/10/20 10:33:13  rharland
# writesettings introduced.
#
# Revision 1.6  2006/08/29 15:51:51  rharland
# - titles.txt is generated by album.pl
# - TITLEKEY added
# - more minor changes
#
# Revision 1.5  2006/08/29 12:33:51  rharland
# *** empty log message ***
#
# Revision 1.4  2006/08/29 11:05:04  rharland
# *** empty log message ***
#
# Revision 1.3  2006/08/28 15:55:29  rharland
# *** empty log message ***
#
# Revision 1.2  2006/08/25 19:44:31  rharland
# *** empty log message ***
#
# Revision 1.1  2006/08/25 15:41:50  rharland
# Initial revision
#
# Revision 1.35  2005/09/08 08:52:31  rharland
# *** empty log message ***
#
# Revision 1.34  2005/09/07 14:52:34  rharland
# -o option removed
# -ext option added
#
# Revision 1.33  2005/09/07 14:34:13  rharland
# -o option added.
#
# Revision 1.32  2005/08/13 12:21:09  rharland
# Previous versions had problems with blanks in names. Fixed.
#
# Revision 1.31  2005/06/19 20:25:38  rharland
# more options added
#
# Revision 1.30  2005/05/28 21:02:25  rharland
# -pack implemented
# -t switch no longer necessary
#
# Revision 1.29  2004/09/02 14:31:12  rharland
# -p introduced.
#
# Revision 1.28  2004/08/03 09:11:26  rharland
# *** empty log message ***
#
# Revision 1.27  2004/08/03 09:00:39  rharland
# Minor changes.
#
# Revision 1.26  2004/02/08 15:36:51  rharland
# *** empty log message ***
#
# Revision 1.25  2004/02/08 15:04:25  rharland
# Bug fix.
#
# Revision 1.24  2004/02/07 17:38:12  rharland
# *** empty log message ***
#
# Revision 1.23  2004/02/07 17:28:46  rharland
# - All customization is now done in a separate file "$settingsfile"
# - THUMBBAR can now be skipped by setting this variable to "none"
#
# Revision 1.22  2004/02/07 14:38:49  rharland
# *** empty log message ***
#
# Revision 1.21  2004/02/07 14:35:46  rharland
# *** empty log message ***
#
# Revision 1.20  2004/02/07 14:31:33  rharland
# *** empty log message ***
#
# Revision 1.19  2004/02/07 14:28:09  rharland
# VERSION 1.0!!
#
# Revision 1.18  2004/02/07 14:27:37  rharland
# * [previous] and [next] buttons can now be chosen to be the thumb of the
#   previous and next picture by setting $ICONPREVIOUS and $ICONNEXT to
#   "THUMB".
# * Layout changed a little.
#
# Revision 1.17  2004/01/27 10:00:21  rharland
# Bug fixes.
#
# Revision 1.16  2004/01/22 17:56:10  rharland
# rotate option added.
#
# Revision 1.15  2004/01/22 10:38:19  rharland
# [previous] and [next] appear even if there is no next/previous.
# This ensures (roughly) the same position for the [next]/[previous]
# buttons on each page. Should be improved at some point.
#
# Revision 1.14  2004/01/22 10:31:29  rharland
# Don't remember the changes...
#
# Revision 1.13  2003/12/17 15:18:51  rharland
# Minor changes.
#
# Revision 1.12  2003/12/17 15:18:01  rharland
# Minor changes.
# Help pages split.
# -c option added.
#
# Revision 1.11  2003/12/17 14:24:42  rharland
# www address changed.
#
# Revision 1.10  2003/11/28 21:43:25  rharland
# -cr option added.
#
# Revision 1.9  2003/11/20 16:58:37  rharland
# Left-Up-Right buttons included.
# Need to define $ICONNEXT, $ICONUP, $ICONPREVIOUS,
# otherwise icons will be replaced by text: "next", "index", "previous".
#
# Revision 1.8  2003/11/11 22:06:35  rharland
# html-files for pics are moved to a directory.
#
# Revision 1.7  2003/11/10 21:39:58  rharland
# Now clicking on large image gives image in ORIGINAL SIZE!
#
# Revision 1.6  2003/11/01 12:19:16  rharland
# further improvements.
#
# Revision 1.5  2003/10/31 20:03:05  rharland
# Improved frame version.
#
# Revision 1.4  2003/10/31 19:23:27  rharland
# With frames!
#
# Revision 1.3  2003/10/29 10:53:59  rharland
# Minor changes.
#
# Revision 1.2  2003/10/29 10:49:09  rharland
# Resize introduced.
# If titles.txt exists, only pictures appearing in titles.txt are resized.
#

#- }}}

$VERSION="1.5.2";
chomp($DATE = `date`);

#- {{{ sub setdefaults:

sub setdefaults {
    #
    # default settings:
    #
    $TITLES = "titles.txt";
    $HEADER = "header.txt";
    $FOOTER = "footer.txt";
    $ALIGN = "center";
    $CONVERT = "convert";
    $HTMLDIR = "html";
    $THUMBDIR = "thumbs";
    $TITDIR = "captions";
    $PICORIG = "pics";
    $INDEX = "index.html";
    $Headerfile = "ahead.html";
    $OVERVIEW = "overview.html";
    $PICDIR = "pics.resize";
    $THUMBTITLE = 0;      #  include titles in the thumb-list?
    @FILETYPES = ("jpg","gif","tif","JPG");
    if ($ENV{'TMPDIR'}) {
	$TMPDIR = $ENV{'TMPDIR'};
    } else {$TMPDIR = "/tmp"}
    if (-e $SETTINGSFILE) {
	do( $SETTINGSFILE );
    }
    else {
	$MYNAME = "YOUR NAME";
	$COPYRIGHT = "";
	$THUMBBAR = "none";
	$THUMBTITLE = 0;          #  include titles in the thumb-list?
	$COLUMNS = 9;
	$PICTITLE = "down";
	$ICONPREVIOUS = "";
	$ICONNEXT = "";
	$ICONINDEX = "icons/upx.gif";
	# "<icon>.gif": use specified icon
	# else: use [previous]
	$SIZE = "750x650";    #  adjust size of pictures
	$WIDTH = "80";        #  size of thumbnails
	$HEIGHT = "100";      #  size of thumbnails
	$BGCOLOR="black";
	$TEXTCOLOR="white";
	$LINKCOLOR="blue";
	$VLINKCOLOR="darkblue";
	$ALINKCOLOR="red";
	$CELLSPACINGOVERVIEW=5;
	$BORDER = 0;
	$TABLEBORDER=0;
	$TITLEKEY=2;            # 0: no titles 
                              # 1: titles on overview page and picpage
                              # 2: titles only on picpage
    }

    unless ($TITLEKEY) {
	print("NOTE: \$NOTITLE is obsolete. Use \$TITLEKEY instead.\n",
	      "(Check the new $settingsfile file on\n",
	      "   http://www.robert-harlander.de/software/album/).\n");
	if ($NOTITLE==0) {$TITLEKEY=1}
	else {$TITLEKEY=0}
    }
}

#- }}}

($albumdir = $0) =~ s/\/([^\/]*)$//;
($rotate,$angle) = argproc("rotate",1);
$NoResize = argproc("noresize",0);
$Pack = argproc("p(ack)?",0);
$Force = argproc("f(orce)?",0);
$Forcethumbs = argproc("ft",0);
($dum,$SETTINGSFILE) = argproc("s",1);
$Forcepics = argproc("fp",0);
$Version = argproc("v(ersion)?",0);
$BasicHelp = argproc("h(elp)?",0);
$Help = argproc("hh",0);
$Custom = argproc("c(ustom)?",0);
$Cleanthumbs = argproc("ct",0);
$Cleanresize = argproc("cr",0);
$Cleanall = argproc("ca",0);
($dum,$Extension) = argproc("ext",1);
($dum,$Albumtitle) = argproc("t(itle)?",1);
unless ($SETTINGSFILE) {
    $settingsfile = "album.settings";
    if (-e "$settingsfile") {
	$SETTINGSFILE = "$settingsfile";
    }
    elsif (-e "$albumdir/$settingsfile") {
	$SETTINGSFILE = "$albumdir/$settingsfile";
    }
}

setdefaults();

if ($Force) {$Forcethumbs = 1; $Forcepics = 1}
if ($BasicHelp) { printusage(); 
	     printbasic();
	     exit; }
if ($Help) { printusage(); 
	     printbasic();
	     printoptions();
	     printtodo();
	     printacknowledge();
	     exit; }
if ($Custom) { printusage();
	       print("\nFor a list of options, see 'album.pl -hh'.\n");
	       printcustom();
	       exit; }
if ($Extension) {
    $INDEX =~ s/\.html/-$Extension.html/;
    $OVERVIEW =~ s/\.html/-$Extension.html/;
    $TITLES =~ s/\.txt/-$Extension.txt/;
    $HTMLDIR .= "-$Extension";
    $TITDIR .= "-$Extension";
    $Headerfile =~ s/\.html/-$Extension.html/;
}

if ($Version) { printversion(); exit; }
if ($Cleanall) { cleanthumbs(); cleanresize(); exit; }
if ($Cleanthumbs) { cleanthumbs(); exit; }
if ($Cleanresize) { cleanresize(); exit; }
if ((!$Albumtitle) && (-e $TITLES)) {
    $Albumtitle = albumtitle($TITLES);
}
if (!$Albumtitle) {
    print("Give a name to your album: ");
    chop($Albumtitle = <STDIN>);
}
if ($NoResize) {$PICDIR = $PICORIG}


%errors = dochecks();

unless (-f $settingsfile) {writesettings();}
album(".");
# album("/media/cdrecorder/Amsterdam-2008");

#- {{{ sub album:

sub album {
    #
    # album($dir)
    #
    # create an album entry for all the pictures in $dir.
    #
    my(@files,$fileroot,$dir,$prevpic,$nextpic,%titles,$title);
    $dir = $_[0];
    #
    # find all pictures and their titles:
    #
    @files = getpics($dir);
    %titles = gettitles($TITLES,@files);
    @files = keys(%titles);
    #
    # rotate if necessary:
    if ($rotate) {
	rotate($dir,$angle,@files);
    }

    @packfiles = ();
    if ($Pack) {
	foreach $file (@files) {
	    ($fileroot = $file) =~ s/\.[^.]*//;
	    if (-e "$PICORIG/$file") {
		push(@packfiles,"$PICORIG/$file");
	    }
	    if (-e "$PICDIR/$file") {
		push(@packfiles,"$PICDIR/$file");
	    }
	    if (-e "$TITDIR/$fileroot.txt") {
		push(@packfiles,"$TITDIR/$fileroot.txt");
	    }
	    if (-e "$THUMBDIR/thumb$file") {
		push(@packfiles,"$THUMBDIR/thumb$file");
	    }
	}
	if (-e "$SETTINGSFILE") {
	    push(@packfiles,"$SETTINGSFILE");
	}
	$packfile = $Albumtitle;
	$packfile =~ s/(\&szlig\;)/ss/g;
	$packfile =~ s/(\&auml\;)/ae/g;
	$packfile =~ s/(\&ouml\;)/oe/g;
	$packfile =~ s/(\&uuml\;)/ue/g;
	$packfile =~ s/(\&Auml\;)/ae/g;
	$packfile =~ s/(\&Ouml\;)/oe/g;
	$packfile =~ s/(\&Uuml\;)/ue/g;
	$packfile =~ s/[ ;:]/_/g;
    	system("tar cvf $packfile.tar $TITLES @packfiles\n");
  	system("gzip $packfile.tar\n");
	exit 0;
    }
    #
    #
    # generate pictures of uniform size:
    #
    if (!$NoResize || $rotate) {
	makepics($dir,@files);
    }
    #
    # generate the thumbnails:
    #
    makethumbs($dir,$THUMBDIR,@files);

    #
    #
    writethumbs({%titles});
    overview({%titles});
    #
    #
    picpage({%titles});
    writeindex();
    header();
}

#- }}}
#- {{{ sub albumtitle:

sub albumtitle {
    my($titles,$title);
    $titles = $_[0];
    open(TIT,$titles);
    while (<TIT>) {
	if (m/^TITLE (.*)$/) {
	    $title = $1;
	}
    }
    close(TIT);
    return ($title);
}

#- }}}
#- {{{ sub cleanthumbs:

sub cleanthumbs {
    opendir(TDIR,$THUMBDIR);
    @thumbs = readdir(TDIR);
    shift(@thumbs);
    shift(@thumbs);
    close(TDIR);
    foreach $thumb (@thumbs) {
	($file = $thumb) =~ s/^thumb//;
	if (!(-e "$PICORIG/$file")) {
	    print("removing $THUMBDIR/$thumb\n");
	    unlink("$THUMBDIR/$thumb");
	}
    }
}

#- }}}
#- {{{ sub cleanresize:

sub cleanresize {
    opendir(TDIR,$PICDIR);
    @resize = readdir(TDIR);
    shift(@resize);
    shift(@resize);
    close(TDIR);
    foreach $pic (@resize) {
	if (!(-e "$PICORIG/$pic")) {
	    print("removing $PICDIR/$pic\n");
	    unlink("$PICDIR/$pic");
	}
    }
}

#- }}}
#- {{{ sub convimages:

sub convimages {
    my(@files,$convert,$width,$height,$newwidth,$newheight,@size);
    
    $dir = shift;
    $convert = shift;
    $width = shift;
    $height = shift;
    @files = @_;
    
    foreach $file (@files) {
	if(!(-e "$dir/thumb$file") || $Forcethumbs || $rotate) {
	    @size = getsize($file);
	    if ( ($size[0] - $size[1]) > 0 ) {
		# Querformat:
		$newwidth = $size[0]*$height/$size[1];
		$geomopt = "-geometry $size[0]"."x"."$height";
		$cropopt = "-crop $width"."x"."$height"."+".
		    int(($newwidth-$width)/2)."+0";
	    }
	    else {
		# Hochformat:
		$newheight = $size[1]*$width/$size[0];
		$geomopt = "-geometry $width"."x"."$size[1]";
		$cropopt = "-crop $width"."x"."$height"."+".
		    "0+".int(($newheight-$height)/2);
	    }
	    unless (exists($errors{"convert"})) {
		print("generating thumbnail for $file...\n");
		system("$convert $geomopt $cropopt \'$PICORIG/$file\' ".
		       "\'$dir/thumb$file\'\n");
	    }
	    else {
		print("WARNING: '$CONVERT' not found. Stopped.\n");
		exit 0;
	    }
	}
    }

}

#- }}}
#- {{{ sub dochecks:

sub dochecks {
    my(%errors,$convert);
    chop($convert = `which $CONVERT`);
    unless (-x $convert) {%errors = ("convert" => 1)};
    return(%errors);
}

#- }}}
#- {{{ sub getpics:

sub getpics {
    #
    # getpics($dir)
    #
    # move pictures found in $dir to $PICORIG
    # and - AFTER THAT - return a list with all the filenames 
    # of pictures found in $PICORIG
    #
    my($dir,@files);
    $dir = $_[0];
    unless (-e $PICORIG) {mkdir($PICORIG,0755)}
    foreach $ext (@FILETYPES) {
	system("mv $dir/*.$ext $dir/$PICORIG > album.log 2>&1");
    }
    if (@ARGV) {
	@files = @ARGV;
    } else {
	opendir(DIR,$PICORIG);
	@files = sort(readdir(DIR));
	close(DIR);
    }
    $" = "|";
    @files = grep(/\.(@FILETYPES)/,@files);
    $" = " ";
    return(@files);
}

#- }}}
#- {{{ sub getsize:

sub getsize {
    my($pic,$size);
    $pic = shift;
    $convout = `$CONVERT -verbose \'$PICORIG/$pic\' \'$TMPDIR/album.$pic\'`;
    unlink("$TMPDIR/album.$pic");
    @convout = split(/ /,$convout);
    ($size) = grep(/\d+x\d+/,@convout);
    @size = split(/[x+]/,$size);
    return(@size);
}

#- }}}
#- {{{ sub gettitles:

sub gettitles {
    #
    # gettitles($titles,@files)
    #
    # looks for at titles-file and reads its entries
    # 
    # returns a hash of the form
    # picname1 => title1, picname2 => title2,...
    #
    # The titles file must have the form
    # <picname1> <title1>
    # <picname2> <title2>
    # ...
    # where <picname1> etc is the filename of the picture, and
    # <title1> etc is the picture title.
    #
    my(%info,$titles,@files,@extrafiles);
    $titles = shift;
    @files = @_;
    %info = ();
    if (!(-e "$titles")) {
	open(TIT,">$titles");
	print {TIT} ("TITLE $Albumtitle\n");
	foreach (@files) { 
	    print {TIT} ("$_\n");
	}
	close(TIT);
    }
    open(TIT,"$titles");
    $count = -1;
    while (<TIT>) {
	$count++;
	if (/^ *$/ || /^TITLE /) {next};
	chop;
	@infotmp = split(/ /,$_);
	if ($#infotmp == 0) {
	    if ($TITLEKEY > 10) {
		@infotmp = ($infotmp[0],"");
	    } else {
		@infotmp = ($infotmp[0],$infotmp[0]);
	    }
	}
	$key = shift(@infotmp);
	%info = (%info, $key => [($count,@infotmp)]);
    }
    close(TIT);
    #
    # remove titles of non-existing pictures 
    # (for example, old entries in the titles file)
    #
    grep(delete($info{$_}),diff([@files],[keys(%info)]));
    
    @extrafiles = diff([@files],[keys(%info)]);
    $firstcheck = 1;
    open(TIT,">>$titles");
  ADDLOOP: foreach $file (sort(@extrafiles)) {
      if ( !(-e "$THUMBDIR/thumb".$file) && !(-e "$PICDIR/$file") ) {
	  if ($firstcheck) {
	      print("You seem to have added new pictures. Include them? ",
		    "[y/n] ");
	      chop($yn = <>);
	      if ($yn !~ /^y/) { last ADDLOOP }
	      $firstcheck = 0;
	  }
	  print {TIT} ($file,"\n");
	  $count++;
	  if ($TITLEKEY > 10) {
	      %info = (%info, $file => [($count,$file)]);
	  } else {
	      %info = (%info, $file => [($count,"")]);
	  }
      }
  }

    return(%info);
}

#- }}}
#- {{{ sub header:

sub header {
    #
    # header({%titles});
    #
    # uses the global variables: 
    # $HEADER, $FOOTER, $TITDIR, $PICORIG, $Albumtitle
    #
    open(PIC,">$Headerfile");
    print {PIC} ("<base target=\"mainframe\">\n");
    print {PIC} ("<html>\n");
    print {PIC} ("<body bgcolor=$BGCOLOR text=$TEXTCOLOR");
    print {PIC} (" link=$LINKCOLOR vlink=$VLINKCOLOR alink=$ALINKCOLOR>\n");
    print {PIC} ("<a href=\"./".$OVERVIEW."\">\n");
    print {PIC} ("<center>\n");
    print {PIC} ("<h2>$Albumtitle</h2></a>\n");
    print {PIC} ("</center>\n");
    print {PIC} ("</body>\n");
    print {PIC} ("</html>\n");
}

#- }}}
#- {{{ sub indexbutton:

sub indexbutton {
    my($i);
    print {PIC} ("<a href=\"../".$OVERVIEW."\">");
    if (-e "$ICONINDEX") {
	print {PIC} ("<img src=\"../$ICONINDEX\" border=\"$BORDER\"\n",
		     "alt=\"index\" title=\"index\">");
    }
    else {
	print {PIC} ("[index]</a>");
    }
}

#- }}}
#- {{{ sub enlargebutton:

sub enlargebutton {
    my($ref);
    $ref = $_[0];
    print {PIC} ("<a href=\"$ref\">");
    print {PIC} ("[enlarge]</a>");
}

#- }}}
#- {{{ sub makepics:

sub makepics {
#
# makepics($dir,@files)
#
# bring the pictures to a uniform size
# such that they fit in the browser
#
    my($dir,@files);
    $dir = shift;
    @files = @_;
    mkdir("$dir/$PICDIR",0755);
    foreach $pic (@files) {
	if(!(-e "$dir/$PICDIR/$pic") || $Forcepics || $rotate) {
	    unless (exists($errors{"convert"})) {
		print("$PICORIG/$pic  -->  $PICDIR/$pic\n");
		system("$CONVERT \'$dir/$PICORIG/$pic\' -resize ".
		       "$SIZE \'$dir/$PICDIR/$pic\'\n");
	    }
	    else {
		print("WARNING: '$CONVERT' not found. Stopped.\n");
		exit 0;
	    }
	}
    }
}

#- }}}
#- {{{ sub makethumbs:

sub makethumbs {
    my($dir,$subdir,@files);
    $dir = shift;
    $subdir = shift;
    @files = @_;
    mkdir("$dir/$subdir",0755);
    convimages("$dir/$subdir",$CONVERT,$WIDTH,$HEIGHT,@files);
}

#- }}}
#- {{{ sub nextbutton:

sub nextbutton {
    my($i,$iin,@piclist);
    $iin = shift;
    @piclist = @_;
    $i = ($iin+1) % ($#piclist+1);
    ($nextpic = $piclist[$i]) =~ s/\.[^.]*$//;
    print {PIC} ("<a href=\"$nextpic.html\">");
    if (-e "$ICONNEXT") {
	print {PIC} ("<img src=\"../$ICONNEXT\" border=\"$BORDER\"\n",
		     "alt=\"next\" title=\"next\">");
    }
    elsif ("$ICONNEXT" eq "THUMB") {
	print {PIC} ("<img src=\"../thumbs/thumb".$piclist[$i].
		     "\" border=\"$BORDER\"\n",
		     "alt=\"next\" title=\"next\">");
    }
    else {
	print {PIC} ("[next]");
    }
    print {PIC} ("</a>\n");
}

#- }}}
#- {{{ sub ordernum:

sub ordernum {
    my(%info,$key);
    $key = shift;
    %info = %{$_[0]};
    return(${$info{$key}}[0]);
}

#- }}}
#- {{{ sub overview:

sub overview {
    my(%info);
    %info = %{$_[0]};
    open(INDEX,">".$OVERVIEW);
    print {INDEX} ("<! ".$OVERVIEW." -- generated by album.pl-v$VERSION >\n");
    print {INDEX} ("<! on $DATE >\n");
    print {INDEX} ("<html><head>\n");
    print {INDEX} ("<title>$MYNAME: $Albumtitle - Overview</title>");
    print {INDEX} ("</head>\n");
    print {INDEX} ("<body bgcolor=$BGCOLOR text=$TEXTCOLOR ");
    print {INDEX} ("link=$LINKCOLOR vlink=$VLINKCOLOR alink=$ALINKCOLOR>\n");
    print {INDEX} ("<center>\n");
    print {INDEX} ("<table cellspacing=$CELLSPACINGOVERVIEW ",
		   "width=30\% border=$TABLEBORDER>\n");
    $count = 1;
    foreach $pic (sort {ordernum($a,{%info}) <=> ordernum($b,{%info}) }
		  (keys(%info))) {
	if ($count > $COLUMNS) {
	    print {INDEX} ("<tr>\n");
	    $count = 1;
	}
	$count++;
	($picroot = $pic) =~ s/\.[^.]*$//;
	@pictitle = pictitle($pic,{%info});
	print {INDEX} ("<th valign=\"top\" align=\"$ALIGN\">");
	print {INDEX} ("<a href=\"$HTMLDIR/$picroot.html\">");
	print {INDEX} ("<img src=\"$THUMBDIR/thumb$pic\" border=\"$BORDER\"\n",
		       "alt=\"@pictitle\" title=\"@pictitle\">\n");
	print {INDEX} ("</a>\n");
	print {INDEX} ("<br>\n");
	if ($TITLEKEY % 10 == 1 ) {
	    print {INDEX} ("@pictitle\n");
	}
    }
    print {INDEX} ("</table>\n");
    print {INDEX} ("</center>\n");
    print {INDEX} ("<hr>\n");
    if (-e "$FOOTER") {
	open(FOOTER,"$FOOTER");
	while (<FOOTER>) {
	    print {INDEX} $_;
	}
	close(FOOTER);
	print {INDEX} ("<br>\n");
	print {INDEX} ("<hr>\n");
    }
    print {INDEX} ("<a href=\"..\" target=\"\_top\">[up]</a>\n");
    print {INDEX} ("<em>Created on ",`date`,"\n");
    print {INDEX} ("using\n");
    print {INDEX} ("<a href=\"http://www.robert-harlander.de/software/\"\n",
	"target=\"\_top\">album.pl</a></em>, ");
    print {INDEX} ("&copy; by ");
    print {INDEX} ("<a href=\"http://www.robert-harlander.de/\"\n",
	"target=\"\_top\">Robi</a>\n");
    print {INDEX} ("</body></html>\n");
    close(INDEX);
}

#- }}}
#- {{{ sub picpage:

sub picpage {
    #
    # picpage({%titles});
    #
    # uses the global variables: 
    # $HEADER, $FOOTER, $TITDIR, $PICORIG, $Albumtitle
    #
    my(%titles);
    %titles = %{$_[0]};
    mkdir("$HTMLDIR",0755);
    @piclist = (sort {ordernum($a,{%titles}) <=> ordernum($b,{%titles}) }
		(keys(%titles)));
    foreach $i (0..$#piclist) {
	$pic = $piclist[$i];
	($picroot = $pic) =~ s/.[^.]*$//;
	@title = pictitle($pic,{%titles});
	if (($TITLEKEY % 10 == 1 )|| ($TITLEKEY % 10 == 2 )) {
	    $title = "@title";
	} else {
	    $title = "";
	}
	open(PIC,">$HTMLDIR/$picroot.html");
	print {PIC} ("<! $picroot.html -- generated by album.pl-v$VERSION>\n");
	print {PIC} ("<! on $DATE >\n");
	print {PIC} ("<html><head>\n");
	print {PIC} ("<title>$MYNAME: $Albumtitle - $title</title>");
	print {PIC} ("</head>\n");
	print {PIC} ("<body bgcolor=$BGCOLOR text=$TEXTCOLOR ");
	print {PIC} ("link=$LINKCOLOR vlink=$VLINKCOLOR alink=$ALINKCOLOR>\n");
	print {PIC} ("<center>\n");
	if ($PICTITLE eq "up") { print {PIC} ("<h2>$title</h2>\n") }
	print {PIC} ("<table cellpadding=\"2\" cellspacing=\"2\"".
		     "border=\"$TABLEBORDER\"".
		     "width=\"100%\">\n");
	print {PIC} ("<tbody>\n");
	print {PIC} ("<tr>\n");
	print {PIC} ("<td valign=\"top\" align=\"left\">");
	previousbutton($i,@piclist);
	print {PIC} ("<br>\n");
	print {PIC} ("</td>\n");
	print {PIC} ("<td valign=\"top\" align=\"center\">");
	indexbutton($i,@piclist);
	enlargebutton("../$PICORIG/$pic");
	print {PIC} ("<br><br>\n");
	$inext = ($i+1) % ($#piclist+1);
	($nextpic = $piclist[$inext]) =~ s/\.[^.]*$//;
	if (-e "$PICORIG/$pic") {
	    print {PIC} ("<a href=\"$nextpic.html\">".
			 "<img src=\"../$PICDIR/$pic\" align=\"center\" ".
			 "border=\"$BORDER\"\n",
			 "alt=\"@title\" title=\"@title\"></a>\n");
	} else {
	    print {PIC} ("<img src=\"../$PICDIR/$pic\" align=\"center\"\n",
			 "alt=\"@title\" title=\"@title\">\n");
	}
	print {PIC} ("<br>\n");
	print {PIC} ("</td>\n");
	print {PIC} ("<td valign=\"top\" align=\"right\">");
	nextbutton($i,@piclist);
	print {PIC} ("<br>\n");
	print {PIC} ("</td>\n");
	print {PIC} ("</tr>\n");
	print {PIC} ("</tbody>\n");
	print {PIC} ("</table>\n");
	print {PIC} ("<br>\n");
	if (-e "$TITDIR/$picroot.txt") {
	    print {PIC} ("<br>\n");
	    open(SUBTITLE,"$TITDIR/$picroot.txt");
	    while (<SUBTITLE>) {
		print {PIC} $_;
	    }
	    close(SUBTITLE);
	}
	if ($PICTITLE eq "down") { print {PIC} ("<h2>$title</h2>\n") }
	print {PIC} ("</center>\n");
	if ($COPYRIGHT) {
	    print {PIC} ("<div align=\"right\"><font size=\"-2\">\n");
	    print {PIC} ("Copyright: $COPYRIGHT\n");
	    print {PIC} ("</div>\n");
# 	    print {PIC} ("");
# 	    print {PIC} ("");
	}		
	print {PIC} ("<br><br>\n");
	print {PIC} ("</body></html>");
	close(PIC);
    }
}

#- }}}
#- {{{ sub previousbutton:

sub previousbutton {
    my($i,$iin,@piclist);
    $iin = shift;
    @piclist = @_;
    $i = ($#piclist+$iin) % ($#piclist+1);
    ($previouspic = $piclist[$i]) =~ s/\.[^.]*$//;
    print {PIC} ("<a href=\"$previouspic.html\">");
    if (-e "$ICONPREVIOUS") {
	print {PIC} ("<img src=\"../$ICONPREVIOUS\" border=\"$BORDER\"\n".
		     "alt=\"previous\" title=\"previous\">");
    }
    elsif ("$ICONPREVIOUS" eq "THUMB") {
	print {PIC} ("<img src=\"../thumbs/thumb".$piclist[$i].
		     "\" border=\"$BORDER\"\n",
		     "alt=\"previous\" title=\"previous\">");
    }
    else {
	print {PIC} ("[previous]");
    }
    print {PIC} ("</a>\n");
}

#- }}}
#- {{{ sub pictitle:

sub pictitle {
    my(%info,$key,@dum);
    $key = shift;
    %info = %{$_[0]};
    @dum = @{$info{$key}};
    shift(@dum);
    return(@dum);
}

#- }}}
#- {{{ sub writesettings:

sub writesettings {
    open(OSET,">$settingsfile") || die;
    print {OSET} 
    ("#\n",
     "# This is your album customization file. It works with\n",
     "# album.pl, version >= 1.4.0.\n",
     "# You may put it as \'$settingsfile\' in the same directory",
     " as album.pl,\n",
     "# or in the directory from where you call album.pl\n",
     "# (if you have both, album.pl will take the latter).\n",
     "# You may also put it in any other path, but then you should\n",
     "# use the -s option of album.pl.\n",
     "#\n",
     "# You can get the latest version of album.pl from\n",
     "# http://www.robert-harlander.de/software/\n");

    print {OSET} ("\n# put your name here:\n");
    print {OSET} ("\$MYNAME = \"$MYNAME\";\n");

    print {OSET} ("\n# copyright (leave empty, if not required):\n");
    print {OSET} ("\$COPYRIGHT = \"$COPYRIGHT\";\n");

    print {OSET} ("\n# do you want a frame with all thumbnails, and where?\n");
    print {OSET} ("# possible values: \"up\",\"down\",\"left\",\"right\",",
		  "\"none\":\n");
    print {OSET} ("\$THUMBBAR = \"$THUMBBAR\";\n");

    print {OSET} ("\n# how many columns of thumbs on the index page?\n");
    print {OSET} ("\$COLUMNS = \"$COLUMNS\";\n");

    print {OSET} ("\n# title of picture above or below picture?\n");
    print {OSET} ("\$PICTITLE = \"$PICTITLE\";\n");

    print {OSET} ("\n# which icons to go to next and previous?\n",
		  "#   \"THUMB\": use next/previous thumbnail\n",
		  "#   \"<icon>.gif\": use specified icon\n",
		  "#   else: use [next]/[previous]\n");
    print {OSET} ("\$ICONNEXT = \"$ICONNEXT\";\n");
    print {OSET} ("\$ICONPREVIOUS = \"$ICONPREVIOUS\";\n");

    print {OSET} ("\n# which icon to go to index page?\n");
    print {OSET} ("\$ICONINDEX = \"$ICONINDEX\";\n");

    print {OSET} ("\n# size of resized picture (keeps aspect ratio):\n");
    print {OSET} ("\$SIZE = \"$SIZE\";\n");

    print {OSET} ("\n# size of thumbnails\n");
    print {OSET} ("\$WIDTH = \"$WIDTH\";\n");
    print {OSET} ("\$HEIGHT = \"$HEIGHT\";\n");

    print {OSET} ("\n# colors:\n");
    print {OSET} ("\$BGCOLOR = \"$BGCOLOR\";\n");
    print {OSET} ("\$TEXTCOLOR = \"$TEXTCOLOR\";\n");
    print {OSET} ("\$LINKCOLOR = \"$LINKCOLOR\";\n");
    print {OSET} ("\$VLINKCOLOR = \"$VLINKCOLOR\";\n");
    print {OSET} ("\$ALINKCOLOR = \"$ALINKCOLOR\";\n");

    print {OSET} ("\n# borders:\n");
    print {OSET} ("\$BORDER = \"$BORDER\";\n");
    print {OSET} ("\$TABLEBORDER = \"$TABLEBORDER\";\n");

    print {OSET} ("\n# space between thumbnails:\n");
    print {OSET} ("\$CELLSPACINGOVERVIEW = \"$CELLSPACINGOVERVIEW\";\n");

    print {OSET} ("\n# This one determines whether to show titles",
		  " of the pictures or not. \n",
		  "# The title is defined in file titles.txt that",
		  " album.pl generates\n",
		  "# upon its first call. See album.pl -c, ",
		  " \"GIVING TITLES TO YOUR PICTURES\". \n");
    print {OSET} ("\$TITLEKEY = \"$TITLEKEY\";\n");

    close($SETTINGSFILE);
}

#- }}}
#- {{{ sub printusage:

sub printusage {
    print("\nUsage: album.pl [-t <title>] [-options] [pics]\n");
}

#- }}}
#- {{{ sub printbasic:

sub printbasic {
    print("\n");
    print("http://www.robert-harlander.de/software/album/\n\n");
    print("GETTING STARTED:\n");
    print("----------------\n");
    print("* Copy all your pictures to a separate directory.\n");
    print("* In that directory, type:  album.pl\n");
    print("  album.pl will ask you for a name for you album, which can be\n",
	  "  anything you want.\n");
    print("* THAT'S ALL!\n\n");
    print("* Watch what's happening:\n");
    print("  - album.pl resizes all your pictures and moves them\n");
    print("    to a subdirectory 'pics.resize'.  The originals are kept\n");
    print("    in the subdirectory 'pics'.\n");
    print("  - thumbnails are created from all your pictures and copied\n");
    print("    to the subdirectory 'thumbs'.\n");
    print("  - an index.html file is generated in the main directory.\n");
    print("  - for every picture, an html-file is generated in the main\n");
    print("    directory.\n");
    print("* Look at the index.html with your web-browser,\n");
    print("  and click on the thumbnails.\n");
    print("\n");
    print("To learn more, see 'album.pl -c' or 'album.pl -hh'.\n");
}

#- }}}
#- {{{ sub printcustom:

sub printcustom {
    print("\n");
    print("CUSTOMIZATION:\n");
    print("--------------\n");
    print("* SETTINGS FILE:\n");
    print("  You have many options to change the layout of your album\n");
    print("  by changing the variables in the settings file. This file\n");
    print("  is usually called \"$SETTINGSFILEy\" and is located in the\n");
    print("  same directory as album.pl. It may also be in the directory\n");
    print("  of your album. Priority is given to the latter.\n");
    print("  You may also put the settings file somewhere else, in which\n");
    print("  case you have to specify the file (including its path)\n");
    print("  with the -s option.");
    print("  Find a template at\n");
    print("  http://www.robert-harlander.de/software/album/\n");
    print("  If no settings file is found, album.pl will choose some\n");
    print("  great settings for you :-)\n\n");
    print("* GIVING TITLES TO YOUR PICTURES:\n");
    print("  If it doesn't already exist, album.pl will generate a file\n");
    print("  'titles.txt' in the main directory which lists all the\n",
	  "  pictures of your album. The first line of 'titles.txt' ",
	  "contains\n",
	  "  the overall title of your album (album.pl then won't ask you\n",
	  "  again for it).\n",
	  "  You can then use 'titles.txt' to modify your album:\n",
	  "  - if you remove an entry from titles.txt, this picture will\n",
	  "    no longer appear in your album (but the file will be kept\n",
	  "    of course!)\n", 
	  "  - you can add a short title to your picture by modifying the\n",
	  "    entry in 'titles.txt' as follows:\n");
    print("    <filename1> <pictitle1>\n");
    print("    <filename2> <pictitle2>\n");
    print("    ...\n");
    print("  For example, if you have a picture named 'pamela.jpg',\n");
    print("  you may want to have a line in your 'titles.txt' like this:\n");
    print("    pamela.jpg Pamela's new swimsuit.\n");
    print("  Now where do the titles appear? This is ruled by the variable\n");
    print("  \$TITLEKEY, defined in the settings file (see above).\n",
	  "  It can assume the following values:\n",
	  "             0 - do not print titles anywhere\n",
	  "       1 or 11 - print titles on thumbnail page and on\n",
	  "                 the actual picture page\n",
	  "       2 or 12 - print titles only on the picture page\n");
    print("  The difference between 1 and 11 (and 2 and 12) is that,\n",
	  "  if \$TITLEKEY < 10 and any of the <pictitle> is blank,\n",
	  "  album.pl will use <filename> as the title for that picture.\n\n");
    print("  For another way to add descriptions to your pictures,\n",
	  "  please check the DESCRIPTIONS item below.\n\n");
    print("");
    print("");
    print("* GLOBAL TITLE:\n");
    print("  The line\n");
    print("    TITLE <albumtitle>\n");
    print("  in 'titles.txt' determines the global title of your album.\n");
    print("  On the other hand, giving the -t option overrides the\n");
    print("  TITLE entry in 'titles.txt'.\n\n");
    print("* DESCRIPTIONS:\n");
    print("  You can add more elaborate descriptions to your pictures\n");
    print("  by creating a file 'captions/<fileroot>.txt',\n");
    print("  where <fileroot> is the root name of the particular picture.\n");
    print("  For example, if you have a picture called pamela.jpg,\n");
    print("  then the contents of a file called captions/pamela.txt will\n");
    print("  become visible when clicking on the icon for pamela.jpg.\n\n");
    print("* HEADER AND FOOTER (temporarily disabled!):\n");
    print("  You can include a personal header and/or footer in your html\n");
    print("  pages by putting the corresponding html code to the files\n");
    print("  header.txt and footer.txt.\n\n");
    print("* NAVIGATION ICONS:\n");
    print("  album.pl lets you navigate through your pictures with\n");
    print("  [previous], [up], and [next] buttons. You can modify these\n");
    print("  by defining $ICONPREVIOUS, $ICONINDEX, and $ICONNEXT in\n");
    print("  'sub setdefaults'.\n\n");
    print("* SORTING:\n");
    print("  If you don't have a titles.txt file, the order in which\n");
    print("  the pictures appear is what you would get by typing\n");
    print("  `/bin/ls -1' in the pictures directory.\n");
    print("  If you DO have a titles.txt file, the order in which\n");
    print("  the pictures are listed there determines the order in which\n");
    print("  they are displayed.\n\n");
    print("* ROTATING:\n");
    print("  You can rotate pictures with the -rotate option.\n");
    print("  In this case, you should specify the pictures that you want\n");
    print("  to rotate in the command line. album.pl will then produce an\n");
    print("  album with only the rotated pictures. To include all pictures,\n");
    print("  you should run album.pl again, without the -rotate option.\n");
    print("  To restore the unrotated picture, rotate by an angle 0.\n");
    print("");
    print("");
    print("");
}

#- }}}
#- {{{ sub printoptions:

sub printoptions {
    print("\n");
    print("OPTIONS:\n");
    print("--------\n");
    print("-t <title> -- define global album title.\n");
    print("-rotate <angle> -- rotate clockwise by <angle>.\n");
    print("-s  -- settings file, if different from default\n");
    print("       (see 'album.pl -c', \"SETTINGS FILE\")\n");
    print("-fp -- force the resize of pics. Without this option,\n");
    print("       resized pics are only generated if they don't already\n");
    print("       exist. Size can be changed in the settings file.\n");
    print("-ft -- force the generation of thumbnails. Without this option,\n");
    print("       thumbnails are only generated if they don't already\n");
    print("       exist.\n");
    print("-f  -- same as setting both -fp and -ft\n");
    print("-ct -- clean thumbs: delete unused thumbnails.\n");
    print("-cr -- clean resize: delete unused resized pictures.\n");
    print("-ca -- clean all: same as setting both -ct and -cr.\n");
    print("-h  -- print basic help pages.\n");
    print("-hh -- print these help pages.\n");
    print("-c  -- how to customize your album.\n");
    print("-p  -- pack all files listed in titles.txt.\n");
    print("-v  -- print version number.\n\n");
    print("");
}

#- }}}
#- {{{ sub printtodo:

sub printtodo {
    print("\n");
    print("TODO:\n");
    print("  Well, this is Version $VERSION, so it's almost perfect.\n\n");
}

#- }}}
#- {{{ sub printacknowledge:

sub printacknowledge {
    print("\n");
    print("ACKNOWLEDGMENTS:\n");
    print("  I got the idea for this from the `album' script by\n");
    print("  MarginalHacks (http://MarginalHacks.com/).\n");
    print("  However, when I tried this one out, it didn't really work\n");
    print("  (most probably my fault), and the result I got was kind of\n");
    print("  ugly. But the main reason for writing my own album.pl was\n");
    print("  the fun...\n\n");
    print("  Further thanks go to:\n");
    print("    - Sabine Lammers for being the first user(!)\n");
    print("    - Zhen Xie for getting album.pl to run under cygwin,\n");
    print("      and many suggestions for improvement.\n");
    print("    - The idea of inserting [previous]/[next] thumbnails was\n");
    print("      stolen from Burkhard Zittel's script.\n\n");
    print("");
}

#- }}}
#- {{{ sub printversion:

sub printversion {
    print("\n");
    print("album.pl, Version $VERSION.\n");
    print("Copyright March 2001 by R.V. Harlander.\n\n");
}

#- }}}
#- {{{ sub rotate:

sub rotate {
#
# rotate($dir,$angle,@files)
#
# bring the pictures to a uniform size
# such that they fit in the browser
#
    my($dir,$angle,@files);
    $dir = shift;
    $angle = shift;
    @files = @_;
    unless (-e "$dir/unrotated") { mkdir("$dir/unrotated",0755) }
    foreach $pic (@files) {
	if (-e "$dir/unrotated/$pic.unrotated") {
	    system("cp $dir/unrotated/$pic.unrotated $dir/$PICORIG/$pic");
	} else {
	    system("cp $dir/$PICORIG/$pic $dir/unrotated/$pic.unrotated");
	}
	if ($angle == 0) {
	    print("restoring unrotated $PICORIG/$pic\n");
	    system("mv $dir/unrotated/$pic.unrotated $dir/$PICORIG/$pic");
	}
	else {
	    print("rotating $PICORIG/$pic by $angle degrees\n");
	    system("$CONVERT -rotate $angle $dir/unrotated/$pic.unrotated ".
		   "$dir/$PICORIG/$pic\n");
	}
    }
}

#- }}}
#- {{{ sub writethumbs:

sub writethumbs {
    my(%info);
    %info = %{$_[0]};
    open(THUMBS,">thumbs.html");
    print {THUMBS} ("<! thumbs.html -- generated by album.pl-v$VERSION >\n");
    print {THUMBS} ("<! on $DATE >\n");
    print {THUMBS} ("<html><head>\n");
    print {THUMBS} ("<title>$MYNAME: $Albumtitle - Thumbnails</title>");
    print {THUMBS} ("</head>\n");
    print {THUMBS} ("<base target=\"mainframe\">\n");
    print {THUMBS} ("<body bgcolor=$BGCOLOR text=$TEXTCOLOR ");
    print {THUMBS} ("link=$LINKCOLOR vlink=$VLINKCOLOR alink=$ALINKCOLOR>\n");
    print {THUMBS} ("<center>\n");
    print {THUMBS} ("<table cellspacing=10 frame=\"void\" border=1>\n");
    foreach $pic (sort {ordernum($a,{%info}) <=> ordernum($b,{%info}) }
		  (keys(%info))) {
	($picroot = $pic) =~ s/\.[^.]*$//;
	@pictitle = pictitle($pic,{%info});
	if (($THUMBBAR eq "left") or ($THUMBBAR eq "right")) { 
	    print {THUMBS} ("<tr>\n") }
	print {THUMBS} ("<th valign=\"top\" align=\"$ALIGN\">");
	print {THUMBS} ("<a href=\"$HTMLDIR/$picroot.html\">");
	print {THUMBS} ("<img src=\"thumbs/thumb$pic\" border=\"$BORDER\"\n",
			"alt=\"@pictitle\" title=\"@pictitle\">\n");
	print {THUMBS} ("</a>\n");
	if ($THUMBTITLE) {
	    print {THUMBS} ("<br>\n");
	    print {THUMBS} ("@pictitle\n");
	}
    }
    print {THUMBS} ("</table>\n");
    print {THUMBS} ("</center>\n");
    if (-e "$FOOTER") {
	open(FOOTER,"$FOOTER");
	while (<FOOTER>) {
	    print {THUMBS} $_;
	}
	close(FOOTER);
	print {THUMBS} ("<br>\n");
	print {THUMBS} ("<hr>\n");
    }
    print {THUMBS} ("</body></html>\n");
    close(THUMBS);
}

#- }}}
#- {{{ sub writeindex:

sub writeindex {
    #
    # writeindex();
    #
    # uses the global variables: 
    # $HEADER, $FOOTER, $TITDIR, $PICORIG, $Albumtitle
    #
    # start with the first picture:
    open(PIC,">$INDEX");
    print {PIC} ("<! $INDEX -- generated by album.pl-v$VERSION >\n");
    print {PIC} ("<! on ",$DATE," >\n");
    print {PIC} ("<html><head>\n");
    print {PIC} ("<title>$MYNAME: $Albumtitle</title>\n");
    print {PIC} ("</head>\n");
    if ($THUMBBAR eq "left") {
	print {PIC} ("<frameset frameborder=1 rows=\"10%,90%\">\n");
	print {PIC} ("   <frame src=\"$Headerfile\">\n");
	print {PIC} ("   <frameset frameborder=0 cols=\"18%,82%\">\n");
	print {PIC} ("    <frame name=\"thumbs\" src=\"thumbs.html\">\n");
	print {PIC} ("    <frame name=\"mainframe\" src=\"".$OVERVIEW."\">\n");
	print {PIC} ("   </frameset>\n");
	print {PIC} ("</frameset>\n");
    } 
    elsif ($THUMBBAR eq "right") {
	print {PIC} ("<frameset frameborder=1 rows=\"10%,90%\">\n");
	print {PIC} ("   <frame src=\"$Headerfile\">\n");
	print {PIC} ("   <frameset frameborder=0 cols=\"82%,18%\">\n");
	print {PIC} ("    <frame name=\"mainframe\" src=\"".$OVERVIEW."\">\n");
	print {PIC} ("    <frame name=\"thumbs\" src=\"thumbs.html\">\n");
	print {PIC} ("   </frameset>\n");
	print {PIC} ("</frameset>\n");
    } 
    elsif ($THUMBBAR eq "up") {
	print {PIC} ("<frameset frameborder=1 rows=\"7%,23\%,70%\">\n");
	print {PIC} ("   <frame src=\"$Headerfile\">\n");
	print {PIC} ("   <frame name=\"thumbs\" src=\"thumbs.html\">\n");
	print {PIC} ("   <frame name=\"mainframe\"".
		     " src=\"".$OVERVIEW."\">\n");
	print {PIC} ("   </frameset>\n");
    } 
    elsif ($THUMBBAR eq "down") {
	print {PIC} ("<frameset frameborder=1 rows=\"7%,73%,20%\">\n");
	print {PIC} ("   <frame src=\"$Headerfile\">\n");
	print {PIC} ("   <frame name=\"mainframe\"".
		     " src=\"".$OVERVIEW."\">\n");
	print {PIC} ("   <frame name=\"thumbs\" src=\"thumbs.html\">\n");
	print {PIC} ("   </frameset>\n");
    }
    else {
	print {PIC} ("<frameset frameborder=1 rows=\"10%,90%\">\n");
	print {PIC} ("   <frame src=\"$Headerfile\">\n");
	print {PIC} ("   <frame name=\"mainframe\" src=\"".$OVERVIEW."\">\n");
	print {PIC} ("</frameset>\n");
    }
    print {PIC} ("</body>\n");
    print {PIC} ("</html>\n");
}


#- }}}
#- {{{ sub argproc:

sub argproc {
    #
    # get the options from the argument list
    #
    # Usage: argproc($optkey,$optnum)
    #
    #  $optkey is the name of the option (may be a pattern)
    #  $optnum is the number of arguments for the option
    #
    # Example: argproc("d(efault)?",1) together with the program call
    #          'program -d test1 test2'  returns the list (-d,test1).
    #          @ARGV is (test2) afterwards.
    #
    my($optkey,$optnum,$val,@optlist);
    $optkey = $_[0];
    $optnum = $_[1];
    
    foreach $val (0..$#ARGV) {
	if ($ARGV[$val] =~ m/^-$optkey$/) {
	    @optlist = splice(@ARGV,$val,$optnum+1);
	    last;
	}
    }
    return(@optlist);

}

#- }}}
#- {{{ sub diff:

sub diff {
#
# diff([@ARRAY1],[@ARRAY2]) returns the difference of @ARRAY1 and @ARRAY2
#
    my(@IN1,@IN2);
    my($i1,$i2,$j1,$j2,$k);
    @IN1 = @{$_[0]};
    @IN2 = @{$_[1]};

    $j1 = 0;
    foreach $i1 (0..$#IN1) {
      LDIFF: foreach $i2 (0..$#IN2) {
          if ("$IN1[$i1-$j1]" eq "$IN2[$i2]") {
              splice(@IN1,$i1-$j1++,1,());
              splice(@IN2,$i2,1,());
              last LDIFF;
          }
      }
    }
    return(@IN1,@IN2);
}

#- }}}





