#!/usr/bin/perl -w
#
# start xjig with a random image from /usr/share/games/xjig/*
# or other directories
#
# Dave Holland <dave@debian.org> 22 June 1999

@files=();

foreach $dir ('/usr/share/games/xjig', '/usr/local/lib/games/xjig', $ENV{'HOME'}."/.xjig") {
  opendir(DIR, $dir) || next;
  @s = grep { /^[^\.]/ && -s "$dir/$_" } readdir(DIR);
  push @files, map ( $dir.'/'.$_, @s );
  closedir(DIR);
}

if ($#files == -1) { die "couldn't find any files to choose from!\n"; }

$index = rand @files;
chomp($file = $files[$index]);

exec "/usr/games/xjig",@ARGV,"-file","$file" || die "Couldn't start xjig: $!\n";
