File: xjig-random

package info (click to toggle)
xjig 2.4-14.1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 892 kB
  • sloc: cpp: 10,177; makefile: 1,142; perl: 23
file content (37 lines) | stat: -rw-r--r-- 1,178 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/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
# Modified: Innocent De Marchi <tangram.peces@gmail.com> 2018
# Added extension filter to file names

@files=();
use File::HomeDir;
foreach $dir ('/usr/share/games/xjig', '/usr/local/lib/games/xjig', $ENV{'HOME'}."/.xjig", $ENV{'HOME'}, './', File::HomeDir->my_pictures) {
  opendir(DIR, $dir) || next;
#  @s = grep { /^[^\.]/ && -s "$dir/$_" } readdir(DIR);
#  push @files, map ( $dir.'/'.$_, @s );
    while (readdir(DIR)) {
	if (index("$dir/$_", ".jpg")!= -1 ||
	    index("$dir/$_", ".JPG")!= -1 ||
	    index("$dir/$_", ".gif")!= -1 ||
	    index("$dir/$_", ".GIF")!= -1 ||
	    index("$dir/$_", ".jpeg")!= -1 ||
	    index("$dir/$_", ".JPEG")!= -1 ||
	    index("$dir/$_", ".ppm")!= -1 ||
	    index("$dir/$_", ".PPM")!= -1 ) {
 	  @s = "$dir/$_";
	  push @files, map ( ''.$_, @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";