#!/usr/bin/perl -w
-# Copyright © 2001 Jamie Zawinski <jwz@jwz.org>, all rights reserved.
+# Copyright © 2001, 2002 Jamie Zawinski <jwz@jwz.org>.
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
use POSIX;
use Fcntl;
-
+use Fcntl ':mode';
my $progname = $0; $progname =~ s@.*/@@g;
-my $version = q{ $Revision: 1.4 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
+my $version = q{ $Revision: 1.8 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
my $verbose = 0;
# If you add other programs to this list, please let me know!
#
my @programs = (
+ "chbg -once -xscreensaver -max_grow 4 -max_size 100",
"xv -root -quit -viewonly -maxpect -noresetroot -quick24 -rmode 5" .
" -rfg black -rbg black",
"xli -quiet -fullscreen -onroot -center -border black",
"xloadimage -quiet -fullscreen -onroot -center -border black",
- "chbg -once -xscreensaver -max_grow 4",
# this lame program wasn't built with vroot.h:
# "xsri -scale -keep-aspect -center-horizontal -center-vertical",
next if ($file eq "core");
$file = "$dir/$file";
+ my @st = stat($file);
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
- $atime,$mtime,$ctime,$blksize,$blocks) = stat($file);
+ $atime,$mtime,$ctime,$blksize,$blocks) = @st;
+
+ if ($#st == -1) {
+ if ($verbose) {
+ my $ll = readlink $file;
+ if (defined ($ll)) {
+ print STDERR "$progname: dangling symlink: $file -> $ll\n";
+ } else {
+ print STDERR "$progname: unreadable: $file\n";
+ }
+ }
+ next;
+ }
next if ($seen_inodes{$ino}); # break symlink loops
$seen_inodes{$ino} = 1;
print STDERR "$progname: recursively reading $dir...\n" if ($verbose > 1);
find_all_files ($dir);
- print STDERR "$progname: found $#all_files files\n" if ($verbose > 1);
+ print STDERR "$progname: found " . ($#all_files+1) . " files\n"
+ if ($verbose > 1);
@all_files = sort(@all_files);
- my $n = int (rand ($#all_files));
+ if ($#all_files < 0) {
+ print STDERR "$progname: no files in $dir\n";
+ exit 1;
+ }
+
+ my $n = int (rand ($#all_files + 1));
my $file = $all_files[$n];
print STDERR "$progname: chose file $n: $file\n" if ($verbose > 1);