#!/usr/bin/perl -w
use strict;

#  Copyright (C) 2003 Anthony de Boer
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of version 2 of the GNU General Public License as
#  published by the Free Software Foundation.
#
#  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 this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

my %p;
my %t;

my $gal = $ENV{'GALLERY'};
die "No GALLERY in environment\n" unless $gal;
my $dfile = $gal . '/.data';

open(D, $dfile) || die "Cannot read $dfile: $!\n";
while(<D>) {
	$p{$2} = $1 if /^(\S+) \d+ img_(\d+)\.jpg$/;
	$t{$1} = $2 if /^(\S+) title (.*)$/;
	}

my $sqs;
my $sqe;
my $sqn = '';

for my $n (sort {$a <=> $b} (keys %p)) {
	if ($sqn ne $p{$n}) {
		&foo if $sqs;
		$sqn = $p{$n};
		$sqs = $n;
		}
	$sqe = $n;
	}

&foo if $sqs;

sub foo {
	my $ti = $t{$sqn} || "UNDEFINED";
	printf "%5d %5d %s %s\n", $sqs, $sqe, $sqn, $ti;
	}
