#!/usr/bin/perl -w
#
# Copyleft (Cl) 1999, 2000 by Malekith / The Final Crash of Corp. System
# <malekith@topnet.pl> / <http://malekith.topnet.pl>
# This is part of gallery image viewer. See file copying-left for details.
#
# this file can be used as wrapper for gallery
# you can run it w/o parameters and it will display all files in
# current directory
# it also intercepts special option:
# -r or --recursive, which is used if and only if no filenames has been
# pased
#

@opt = ();
@files = ();
$last_opt = 0;
$r = 0;

while ($_ = shift) {
	if (!$last_opt && /^-/) {
		/^--$/ and $last_opt = 1 or
		(/^--recursive$/ or /^-r$/) and $r = 1 or
			push @opt, $_;
	} else {
		push @files, $_;
		$last_opt = 1;
	}
}
if (@files == 0) {
	$/ = "\0";
	open(FH, "find . " . ($r ? "" : "-maxdepth 1 ") . " -print0 |") or die;
	while (<FH>) {
		chomp;
	/^.*\.(jpe?g|png|tiff?|iff|i?lbm|gif|xpm|pcx|bmp|p[ngbp]m|xbm|tga)$/i
		and push @files, $_;
	}
	@files = sort @files;
}

exec ("gallery", @opt, "--", @files);
