X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=driver%2Fxscreensaver-getimage-file;h=f7f4c8746d1133042f2817d6058d28d1ceed5974;hb=6cee540bdbb571485cd5e519f89f389faebd0495;hp=6370db1c24b4d47ca4a1647e55a6d697b1fb3e40;hpb=8eb2873d7054e705c4e83f22d18c40946a9e2529;p=xscreensaver diff --git a/driver/xscreensaver-getimage-file b/driver/xscreensaver-getimage-file index 6370db1c..f7f4c874 100755 --- a/driver/xscreensaver-getimage-file +++ b/driver/xscreensaver-getimage-file @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# Copyright © 2001 Jamie Zawinski , all rights reserved. +# Copyright © 2001, 2002, 2003 Jamie Zawinski . # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that @@ -24,15 +24,34 @@ # Created: 12-Apr-01. require 5; +#require v5.6; use diagnostics; use strict; use POSIX; use Fcntl; +# Apparently the "old way" to get S_ISLNK and friends is to do this: +# +use POSIX ':fcntl_h'; + +# But apparently the "new way" is to do this: +# +# use Fcntl ':mode'; +# +# but of course that will generate an error on "old" (pre-5.6?) Perl versions. +# So we do it like this instead: +# +BEGIN { + if (! defined(&S_ISLNK)) { # perhaps defined by "POSIX"? + require Fcntl; + import Fcntl ':mode'; # if not, look for it in "Fcntl". + } +} + my $progname = $0; $progname =~ s@.*/@@g; -my $version = q{ $Revision: 1.6 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/; +my $version = q{ $Revision: 1.12 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/; my $verbose = 0; @@ -44,7 +63,7 @@ my $verbose = 0; # my @programs = ( "chbg -once -xscreensaver -max_grow 4 -max_size 100", - "xv -root -quit -viewonly -maxpect -noresetroot -quick24 -rmode 5" . + "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", @@ -84,7 +103,7 @@ sub find_all_files { local *DIR; if (! opendir (DIR, $dir)) { - print STDERR "$progname: couldn't open $dir: $!\n"; + print STDERR "$progname: couldn't open $dir: $!\n" if ($verbose); return; } my @files = readdir (DIR); @@ -99,8 +118,21 @@ sub find_all_files { 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; @@ -129,10 +161,16 @@ sub find_random_file { 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); + 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];