http://packetstormsecurity.org/UNIX/admin/xscreensaver-3.31.tar.gz
[xscreensaver] / hacks / webcollage
index 2a727006d90446729e39e1df73dfb05972e322b4..b1f1c96ba2ce3ee826e003f02e9dc9afc0f91774 100755 (executable)
@@ -1,6 +1,6 @@
-#!/usr/local/bin/perl5 -w
+#!/usr/bin/perl -w
 #
-# webcollage, Copyright (c) 1999 by Jamie Zawinski <jwz@jwz.org>
+# webcollage, Copyright (c) 1999, 2000 by Jamie Zawinski <jwz@jwz.org>
 # This program decorates the screen with random images from the web.
 # One satisfied customer described it as "a nonstop pop culture brainbath."
 #
@@ -25,9 +25,10 @@ use Socket;
 require Time::Local;
 require POSIX;
 use Fcntl ':flock'; # import LOCK_* constants
+use POSIX qw(strftime);
 
 
-my $version = q{ $Revision: 1.36 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
+my $version = q{ $Revision: 1.63 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
 my $copyright = "WebCollage $version, Copyright (c) 1999" .
     " Jamie Zawinski <jwz\@jwz.org>\n" .
     "            http://www.jwz.org/xscreensaver/\n";
@@ -36,15 +37,15 @@ my $argv0 = $0;
 my $progname = $argv0; $progname =~ s@.*/@@g;
 
 my $random_redirector = "http://random.yahoo.com/bin/ryl";
-my $image_randomizer_1 = "http://image.altavista.com/cgi-bin/avncgi" .
-                         "?do=3" .
-                         "&verb=n" .
-                         "&oshape=n" .
-                         "&oorder=" .
-                         "&ophoto=1&oart=1&ocolor=1&obw=1" .
+my $image_randomizer_1 = "http://www.altavista.com/query" .
+                         "?mmdo=3" .
+                         "&nbq=12" .
                          "&stype=simage" .
-                         "&oprem=0" .
-                         "&query=";
+                         "&iclr=1" .
+                         "&ibw=1" .
+                         "&iexc=1" .
+                         "&what=web" .
+                         "&q=";
 my $image_randomizer_2 = "http://www.hotbot.com/?clickSrc=search" .
                          "&submit=SEARCH&SM=SC&LG=any" .
                          "&AM0=MC&AT0=words&AW0=" .
@@ -56,9 +57,15 @@ my $image_randomizer_2 = "http://www.hotbot.com/?clickSrc=search" .
                          "&MT=";
 my $image_randomizer_3 = "http://www.altavista.com/cgi-bin/query?pg=q" .
                          "&text=yes&kl=XX&stype=stext&q=";
-my $photo_randomizer   = "http://albums.photopoint.com/j/View?u=1&a=1&p=";
-my $photo_randomizer_lo = 10000001;
-my $photo_randomizer_hi = 12400000;
+my $image_randomizer_4 = "http://search.news.yahoo.com/search/news_photos?" .
+                         "&z=&n=100&o=o&2=&3=&p=";
+
+# I guess Photopoint got wise to me, because now they are doing error
+# checking on the user ("u=") and album ("a=") parameters.  Oh well.
+#
+#my $photo_randomizer   = "http://albums.photopoint.com/j/View?u=1&a=1&p=";
+#my $photo_randomizer_lo = 10000001;
+#my $photo_randomizer_hi = 12400000;
 
 my $image_ppm   = ($ENV{TMPDIR} ? $ENV{TMPDIR} : "/tmp") . "/webcollage." . $$;
 my $image_tmp1  = $image_ppm . "-1";
@@ -71,10 +78,11 @@ my $http_proxy = undef;
 my $http_timeout = 30;
 my $cvt_timeout = 10;
 
-# if we have xli, use it to write to the root window.  else use xv.
-my $ppm_to_root_window_cmd_1 = "xli -quiet -onroot -center" .
+# programs we can use to write to the root window (tried in ascending order.)
+my $ppm_to_root_window_cmd_1 = "xloadimage -onroot -quiet %%PPM%%";
+my $ppm_to_root_window_cmd_2 = "xli -quiet -onroot -center" .
                                " -border black %%PPM%%";
-my $ppm_to_root_window_cmd_2 = "xv -root -rmode 5 -viewonly" .
+my $ppm_to_root_window_cmd_3 = "xv -root -rmode 5 -viewonly" .
                                " +noresetroot %%PPM%% -quit";
 
 my $ppm_to_root_window_cmd = undef;     # initialized by x_output()
@@ -89,7 +97,10 @@ my $delay = 0;
 my $wordlist = "/usr/dict/words";
 
 if (!-r $wordlist) {
-    $wordlist = "/usr/share/lib/dict/words";    # irix
+    $wordlist = "/usr/share/dict/words";       # BSD
+}
+if (!-r $wordlist) {
+    $wordlist = "/usr/share/lib/dict/words";    # Irix
 }
 die "$wordlist doesn't exist!\n" unless (-r $wordlist);
 
@@ -108,6 +119,9 @@ my @tripwire_words = ("aberrate", "abode", "amorphous", "antioch",
                       "eggplant");
 
 
+sub blurb {
+    return "$progname: " . strftime ("%H:%M:%S: ", localtime);
+}
 
 
 ##############################################################################
@@ -127,13 +141,13 @@ sub get_document_1 {
     if ($timeout > $http_timeout) { $timeout = $http_timeout; }
 
     if ( $verbose > 3 ) {
-       print STDERR "$progname: get_document_1 $url " .
+       print STDERR blurb() . "get_document_1 $url " .
             ($referer ? $referer : "") . "\n";
     }
 
     my($url_proto, $dummy, $serverstring, $path) = split(/\//, $url, 4);
     if (! ($url_proto && $url_proto =~ m/^http:$/i)) {
-        if ($verbose) { print STDERR "$progname: not an HTTP URL: $url\n"; }
+        if ($verbose) { print STDERR blurb() . "not an HTTP URL: $url\n"; }
         return ();
     }
 
@@ -158,11 +172,14 @@ sub get_document_1 {
     $paddr   = sockaddr_in($port2, $iaddr);
 
 
+    my $head = "";
+    my $body = "";
+
     @_ =
     eval {
         local $SIG{ALRM}  = sub {
             if ($verbose > 0) {
-                print STDERR "$progname: timed out ($timeout) for $url\n";
+                print STDERR blurb() . "timed out ($timeout) for $url\n";
             }
             die "alarm\n"
             };
@@ -170,11 +187,11 @@ sub get_document_1 {
 
         $proto   = getprotobyname('tcp');
         if (!socket(S, PF_INET, SOCK_STREAM, $proto)) {
-            print STDERR "$progname: socket: $!\n" if ($verbose);
+            print STDERR blurb() . "socket: $!\n" if ($verbose);
             return;
         }
         if (!connect(S, $paddr)) {
-            print STDERR "$progname: connect($serverstring): $!\n"
+            print STDERR blurb() . "connect($serverstring): $!\n"
                 if ($verbose);
             return;
         }
@@ -187,16 +204,14 @@ sub get_document_1 {
             $cookie = "AV_ALL=1";
         }
 
-        print S ("GET " . ($http_proxy ? $url : "/$path") . " HTTP/1.0\n" .
-                 "Host: $them\n" .
-                 "User-Agent: $progname/$version\n" .
-                 ($referer ? "Referer: $referer\n" : "") .
-                 ($cookie ? "Cookie: $cookie\n" : "") .
-                 "\n");
+        print S ("GET " . ($http_proxy ? $url : "/$path") . " HTTP/1.0\r\n" .
+                 "Host: $them\r\n" .
+                 "User-Agent: $progname/$version\r\n" .
+                 ($referer ? "Referer: $referer\r\n" : "") .
+                 ($cookie ? "Cookie: $cookie\r\n" : "") .
+                 "\r\n");
         my $http = <S>;
 
-        my $head = "";
-        my $body = "";
         while (<S>) {
             $head .= $_;
             last if m@^[\r\n]@;
@@ -208,7 +223,7 @@ sub get_document_1 {
         close S;
 
         if ( $verbose > 3 ) {
-            print STDERR "$progname:    ==> $http\n";
+            print STDERR blurb() . "   ==> $http\n";
         }
 
         return ( $http, $head, $body );
@@ -216,6 +231,8 @@ sub get_document_1 {
     die if ($@ && $@ ne "alarm\n");       # propagate errors
     if ($@) {
         # timed out
+        $head = undef;
+        $body = undef;
         return ();
     } else {
         # didn't
@@ -257,7 +274,7 @@ sub get_document {
                 $location =~ s/[\r\n]$//;
 
                if ( $verbose > 3 ) {
-                   print STDERR "$progname: redirect from " .
+                   print STDERR blurb() . "redirect from " .
                         "$url to $location\n";
                }
                 $referer = $url;
@@ -279,14 +296,16 @@ sub get_document {
 
             if ($loop_count++ > $max_loop_count) {
                if ( $verbose > 1 ) {
-                   print STDERR "$progname: too many redirects " .
+                   print STDERR blurb() . "too many redirects " .
                         "($max_loop_count) from $orig_url\n";
                }
+                $body = undef;
                 return ();
             }
 
         } elsif ( $http =~ m@HTTP/[0-9.]+ [4-9][0-9][0-9]@ ) {
             # http errors -- return nothing.
+            $body = undef;
             return ();
 
        } else {
@@ -319,7 +338,7 @@ sub pick_image_from_body {
     }
 
     if ( $verbose > 3 ) {
-       print STDERR "$progname: base is $base\n";
+       print STDERR blurb() . "base is $base\n";
     }
 
 
@@ -365,10 +384,12 @@ sub pick_image_from_body {
     }
     if ($trip_count >= $#tripwire_words - 2) {
         if ($verbose > 1) {
-            print STDERR "$progname: there is probably a dictionary in" .
+            print STDERR blurb() . "there is probably a dictionary in" .
                 " \"$url\": rejecting.\n";
         }
         $rejected_urls{$url} = -1;
+        $body = undef;
+        $_ = undef;
         return ();
     }
 
@@ -387,13 +408,15 @@ sub pick_image_from_body {
                 my $L = length($1);
                 if ($L > 1000) {
                     if ($verbose > 1) {
-                        print STDERR "$progname: keywords of" .
+                        print STDERR blurb() . "keywords of" .
                             " length $L in $url: rejecting.\n";
                     }
                     $rejected_urls{$url} = $L;
+                    $body = undef;
+                    $_ = undef;
                     return ();
                 } elsif ( $verbose > 2 ) {
-                    print STDERR "$progname: keywords of length $L" .
+                    print STDERR blurb() . "keywords of length $L" .
                         " in $url (ok.)\n";
                 }
             }
@@ -431,7 +454,7 @@ sub pick_image_from_body {
            if ( $width && $width < $min_width) {
                if ( $verbose > 2 ) {
                     if (!$height) { $height = "?"; }
-                   print STDERR "$progname: skip narrow image " .
+                   print STDERR blurb() . "skip narrow image " .
                         "$_ (${width}x$height)\n";
                }
                next;
@@ -440,7 +463,7 @@ sub pick_image_from_body {
            if ( $height && $height < $min_height) {
                if ( $verbose > 2 ) {
                     if (!$width) { $width = "?"; }
-                   print STDERR "$progname: skip short image " .
+                   print STDERR blurb() . "skip short image " .
                         "$_ (${width}x$height)\n";
                }
                next;
@@ -451,7 +474,7 @@ sub pick_image_from_body {
                 ($width * $min_ratio ) > $height ) {
                if ( $verbose > 2 ) {
                     if (!$height) { $height = "?"; }
-                   print STDERR "$progname: skip bad ratio " .
+                   print STDERR blurb() . "skip bad ratio " .
                         "$_ (${width}x$height)\n";
                }
                next;
@@ -461,13 +484,13 @@ sub pick_image_from_body {
 
            if ( $unique_urls{$url} ) {
                if ( $verbose > 2 ) {
-                    print STDERR "$progname: skip duplicate image $_\n";
+                    print STDERR blurb() . "skip duplicate image $_\n";
                 }
                next;
            }
 
            if ( $verbose > 2 ) {
-               print STDERR "$progname: got $url" . 
+               print STDERR blurb() . "got $url" . 
                    ($width && $height ? " (${width}x${height})" : "") .
                    ($was_inline ? " (inline)" : "") . "\n";
            }
@@ -489,9 +512,12 @@ sub pick_image_from_body {
        }
     }
 
+    $_ = undef;
+    $body = undef;
+
     if ( $#urls == 0 ) {
        if ( $verbose > 2 ) {
-           print STDERR "$progname: no images on $base\n";
+           print STDERR blurb() . "no images on $base\n";
        }
        return ();
     }
@@ -503,7 +529,7 @@ sub pick_image_from_body {
     $url = $urls[$i];
 
     if ( $verbose > 2 ) {
-       print STDERR "$progname: picked $url\n";
+       print STDERR blurb() . "picked $url\n";
     }
 
     return $url;
@@ -523,8 +549,12 @@ sub pick_from_url_randomizer {
 
     my ( $base, $body ) = get_document ($random_redirector, undef, $timeout);
 
-    return if (!$base || !$body);
+    if (!$base || !$body) {
+        $body = undef;
+        return;
+    }
     my $img = pick_image_from_body ($base, $body);
+    $body = undef;
 
     if ($img) {
         return ($base, $img, "yahoo");
@@ -544,6 +574,10 @@ sub random_word {
             $word = <IN>;   # toss partial line
             $word = <IN>;   # keep next line
         }
+       if (!$word) {
+          seek( IN, 0, 0 );
+          $word = <IN>;
+       }
         close (IN);
     }
 
@@ -559,6 +593,10 @@ sub random_word {
     $word =~ s/izes$/ize/;
     $word =~ tr/A-Z/a-z/;
 
+    if ( $word =~ s/[ \t\n\r]/\+/g ) {  # convert intra-word spaces to "+".
+      $word = "\%22$word\%22";         # And put quotes (%22) around it.
+    }
+
     return $word;
 }
 
@@ -579,7 +617,8 @@ sub pick_from_image_randomizer {
 
     my $search_url = ($which == 0 ? $image_randomizer_1 :
                       $which == 1 ? $image_randomizer_2 :
-                      $image_randomizer_3) .
+                      $which == 2 ? $image_randomizer_3 :
+                      $image_randomizer_4) .
         $words;
 
     # Pick a random search-result page instead of always taking the first.
@@ -591,7 +630,7 @@ sub pick_from_image_randomizer {
     }
 
     if ( $verbose > 3 ) {
-        $_ = $words; s/%20/ /g; print STDERR "$progname: search words: $_\n";
+        $_ = $words; s/%20/ /g; print STDERR blurb() . "search words: $_\n";
     }
 
     if ( $verbose > 3 ) {
@@ -602,7 +641,10 @@ sub pick_from_image_randomizer {
     my ( $base, $body ) = get_document ($search_url, undef, $timeout);
     if (defined ($timeout)) {
         $timeout -= (time - $start);
-        return () if ($timeout <= 0);
+        if ($timeout <= 0) {
+            $body = undef;
+            return ();
+        }
     }
 
     return () if (! $body);
@@ -626,9 +668,13 @@ sub pick_from_image_randomizer {
     my $href_count = 0;
 
     $_ = $body;
-    s/[\r\n\t ]+/ /g;
 
-    s/Result Pages:.*$//;               # trim off page footer
+#    s/Result [Pp]ages:.*$//s;            # trim off page footer
+#    s/^.*?IMAGE RESULTS//s;              # trim off page header
+
+    s/Have you tried these resources.*//s;  # let's try it again
+
+    s/[\r\n\t ]+/ /g;
 
     s/(<A )/\n$1/gi;
     foreach (split(/\n/)) {
@@ -646,26 +692,53 @@ sub pick_from_image_randomizer {
 
         next unless ($u =~ m@^http://@i);  # skip non-http and relative urls.
 
-        next if ($u =~ m@[/.]altavista\.com@i);  # skip altavista builtins
-        next if ($u =~ m@[/.]digital\.com@i);
-        next if ($u =~ m@[/.]doubleclick\.net@i);
+        next if ($u =~ m@[/.]altavista\.com\b@i);     # skip altavista builtins
+        next if ($u =~ m@[/.]altavista\.[a-z]{2}\b@i); # altavista.fr, etc
+        next if ($u =~ m@[/.]av\.com\b@i);
+        next if ($u =~ m@[/.]virage\.com\b@i);
+        next if ($u =~ m@[/.]photoloft\.com\b@i);
+        next if ($u =~ m@[/.]shopping\.com\b@i);
+        next if ($u =~ m@[/.]thetrip\.com\b@i);
+        next if ($u =~ m@[/.]cmgi\.com\b@i);
+        next if ($u =~ m@[/.]intelihealth\.com\b@i);
+        next if ($u =~ m@[/.]wildweb\.com\b@i);
+        next if ($u =~ m@[/.]digital\.com\b@i);
+        next if ($u =~ m@[/.]doubleclick\.net\b@i);
+        next if ($u =~ m@[/.]freeim\.org\b@i);
+        next if ($u =~ m@[/.]clicktomarket\.com\b@i);  # you cretins
+        next if ($u =~ m@[/.]teragram\.com\b@i);
+
+        # must lose this one for altavista, even though it loses images of
+        # every single customer of akamai.  Oh well, those people have lots
+        # of money, and so their images are probably boring anyway.
+        next if ($u =~ m@[/.]akamai\.net@i);
 
         if ($which == 0 && $u =~ m@[/.]corbis\.com@) {
-            $skipped = 1;
+           $skipped = 1;
+            if ( $verbose > 3 ) {
+                print STDERR blurb() . "skipping corbis URL: $u\n";
+            }
+            next;
+
+        } elsif ($which == 3 &&
+                 ($u =~ m@^http://[^/]+$@ ||             # no slashes
+                  $u =~ m@/$@ ||                         # ends in /
+                  ! ($u =~ m@dailynews\.yahoo\.com@))) {  # not dailynews
+#            $skipped = 1;
             if ( $verbose > 3 ) {
-                print STDERR "$progname: skipping corbis URL: $u\n";
+                print STDERR blurb() . "skipping non-AP URL: $u\n";
             }
             next;
 
         } elsif ( $rejected_urls{$u} ) {
             if ( $verbose > 3 ) {
                 my $L = $rejected_urls{$u};
-                print STDERR "$progname: pre-rejecting sub-page: $u\n";
+                print STDERR blurb() . "pre-rejecting sub-page: $u\n";
             }
             next;
 
         } elsif ( $verbose > 3 ) {
-            print STDERR "$progname: sub-page: $u\n";
+            print STDERR blurb() . "sub-page: $u\n";
         }
 
         $subpages[++$#subpages] = $u;
@@ -673,9 +746,11 @@ sub pick_from_image_randomizer {
 
     if ( $#subpages < 0 ) {
         if (!$skipped && $verbose > 1) {
-            print STDERR "$progname: found nothing on $base " .
+            print STDERR blurb() . "found nothing on $base " .
                 "($length bytes, $href_count links).\n";
         }
+        $body = undef;
+        $_ = undef;
        return ();
     }
 
@@ -684,21 +759,29 @@ sub pick_from_image_randomizer {
     my $subpage = $subpages[$i];
 
     if ( $verbose > 3 ) {
-       print STDERR "$progname: picked page $subpage\n";
+       print STDERR blurb() . "picked page $subpage\n";
     }
 
 
+    $body = undef;
+    $_ = undef;
 
     my ( $base2, $body2 ) = get_document ($subpage, $base, $timeout);
 
-    return () if (!$base2 || !$body2);
+    if (!$base2 || !$body2) {
+        $body2 = undef;
+        return ();
+    }
 
     my $img = pick_image_from_body ($base2, $body2);
+    $body2 = undef;
 
     if ($img) {
         return ($base2, $img,
                 ($which == 0 ? "imagevista" :
-                 $which == 1 ? "hotbot" : "altavista") .
+                 $which == 1 ? "hotbot" :
+                 $which == 2 ? "altavista" :
+                 "ap") .
                 "/$search_count");
     } else {
         return ();
@@ -710,13 +793,13 @@ sub pick_from_image_randomizer {
 # to an image.  Returns two URLs, both of which are the URL of the image.
 # Returns () if nothing found this time.
 #
-sub pick_from_photo_randomizer {
-    my ( $timeout ) = @_;
-    my $n = ($photo_randomizer_lo +
-             int(rand() * ($photo_randomizer_hi - $photo_randomizer_lo)));
-    my $url = $photo_randomizer . $n;
-    return ( $url, $url, "photopoint" );
-}
+#sub pick_from_photo_randomizer {
+#    my ( $timeout ) = @_;
+#    my $n = ($photo_randomizer_lo +
+#             int(rand() * ($photo_randomizer_hi - $photo_randomizer_lo)));
+#    my $url = $photo_randomizer . $n;
+#    return ( $url, $url, "photopoint" );
+#}
 
 
 # Picks a random image on a random page, and returns two URLs:
@@ -737,8 +820,8 @@ my $count_4 = 0;
 
 sub pick_image {
     my ( $timeout ) = @_;
-
     my $r = int(rand(100));
+
     my ($base, $img, $source, $total, $count);
 
     if ($r < 20) {
@@ -751,10 +834,15 @@ sub pick_image {
         $total = ++$total_1;
         $count = ++$count_1 if $img;
 
-    } elsif ($r < 70) {
-        ($base, $img, $source) = pick_from_photo_randomizer ($timeout);
-        $total = ++$total_4;
-        $count = ++$count_4 if $img;
+     } elsif ($r < 65) {
+         ($base, $img, $source) = pick_from_image_randomizer ($timeout, 3);
+         $total = ++$total_4;
+         $count = ++$count_4 if $img;
+
+#    } elsif ($r < 70) {
+#        ($base, $img, $source) = pick_from_photo_randomizer ($timeout);
+#        $total = ++$total_4;
+#        $count = ++$count_4 if $img;
 
 #    } elsif ($r < 80) {
 #        # HotBot sucks: 98% of the time, it says "no pages match your
@@ -906,7 +994,7 @@ sub url_only_output {
 
 sub x_cleanup {
     my ($sig) = @_;
-    if ($verbose > 0) { print STDERR "$progname: caught signal $sig.\n"; }
+    if ($verbose > 0) { print STDERR blurb() . "caught signal $sig.\n"; }
     unlink $image_ppm, $image_tmp1, $image_tmp2;
     exit 1;
 }
@@ -921,29 +1009,29 @@ sub nontrapping_system {
     if ($verbose > 1) {
         $_ = join(" ", @_);
         s/\"[^\"]+\"/\"...\"/g;
-        print STDERR "$progname: executing \"$_\"\n";
+        print STDERR blurb() . "executing \"$_\"\n";
     }
 
     my $rc = system @_;
 
     if ($rc == 0) {
         if ($verbose > 1) {
-            print STDERR "$progname: subproc exited normally.\n";
+            print STDERR blurb() . "subproc exited normally.\n";
         }
     } elsif (($rc & 0xff) == 0) {
         $rc >>= 8;
         if ($verbose) {
-            print "$progname: subproc exited with status $rc.\n";
+            print blurb() . "subproc exited with status $rc.\n";
         }
     } else {
         if ($rc & 0x80) {
             if ($verbose) {
-                print "$progname: subproc dumped core.\n";
+                print blurb() . "subproc dumped core.\n";
             }
             $rc &= ~0x80;
         }
         if ($verbose) {
-            print "$progname: subproc died with signal $rc.\n";
+            print blurb() . "subproc died with signal $rc.\n";
         }
         # die that way ourselves.
         kill $rc, $$;
@@ -973,7 +1061,14 @@ sub image_to_pnm {
 
     $cmd2 = "exec $cmd";        # yes, this really is necessary.  if we don't
                                 # do this, the process doesn't die properly.
-    if ($verbose == 0) {
+    if ($verbose <= 1) {
+        #
+        # We get a "giftopnm: got a 'Application Extension' extension"
+        # warning any time it's an animgif.
+        #
+        # Note that "giftopnm: EOF / read error on image data" is not
+        # always a fatal error -- sometimes the image looks fine anyway.
+        #
         $cmd2 .= " 2>/dev/null";
     }
 
@@ -987,49 +1082,53 @@ sub image_to_pnm {
 
         local $SIG{ALRM}  = sub {
             if ($verbose > 0) {
-                print STDERR "$progname: timed out ($cvt_timeout) for " .
+                print STDERR blurb() . "timed out ($cvt_timeout) for " .
                     "$cmd on \"$url\" in pid $pid\n";
             }
             kill ('TERM', $pid) if ($pid);
             $timed_out = 1;
+            $body = undef;
         };
 
         if (($pid = open(PIPE, "| $cmd2 > $output"))) {
             $timed_out = 0;
             alarm $cvt_timeout;
             print PIPE $body;
+            $body = undef;
             close PIPE;
 
-            if ($verbose > 3) { print STDERR "$progname: awaiting $pid\n"; }
+            if ($verbose > 3) { print STDERR blurb() . "awaiting $pid\n"; }
             waitpid ($pid, 0);
-            if ($verbose > 3) { print STDERR "$progname: $pid completed\n"; }
+            if ($verbose > 3) { print STDERR blurb() . "$pid completed\n"; }
 
 
             my $size = (stat($output))[7];
             if ($size < 5) {
                 if ($verbose) {
-                    print STDERR "$progname: $cmd on ${w}x$h \"$url\" failed" .
+                    print STDERR blurb() . "$cmd on ${w}x$h \"$url\" failed" .
                         " ($size bytes)\n";
                 }
                 return ();
             }
 
             if ($verbose > 1) {
-                print STDERR "$progname: created ${w}x$h $output ($cmd)\n";
+                print STDERR blurb() . "created ${w}x$h $output ($cmd)\n";
             }
             return ($w, $h);
         } else {
-            print STDERR "$progname: $cmd failed: $!\n";
+            print STDERR blurb() . "$cmd failed: $!\n";
             return ();
         }
     };
     die if ($@ && $@ ne "alarm\n");       # propagate errors
     if ($@) {
         # timed out
+        $body = undef;
         return ();
     } else {
         # didn't
         alarm 0;
+        $body = undef;
         return @_;
     }
 }
@@ -1038,21 +1137,25 @@ sub x_output {
 
     my $win_cmd_1 = $ppm_to_root_window_cmd_1;
     my $win_cmd_2 = $ppm_to_root_window_cmd_2;
+    my $win_cmd_3 = $ppm_to_root_window_cmd_3;
     $win_cmd_1 =~ s/^([^ \t\r\n]+).*$/$1/;
     $win_cmd_2 =~ s/^([^ \t\r\n]+).*$/$1/;
+    $win_cmd_3 =~ s/^([^ \t\r\n]+).*$/$1/;
 
     # make sure the various programs we execute exist, right up front.
     foreach ("ppmmake", "giftopnm", "djpeg", "pnmpaste", "pnmscale",
              "pnmcut") {
-        which ($_) || die "$progname: $_ not found on \$PATH.\n";
+        which ($_) || die blurb() . "$_ not found on \$PATH.\n";
     }
 
     if (which($win_cmd_1)) {
         $ppm_to_root_window_cmd = $ppm_to_root_window_cmd_1;
     } elsif (which($win_cmd_2)) {
         $ppm_to_root_window_cmd = $ppm_to_root_window_cmd_2;
-    } else {
-        die "$progname: neither $win_cmd_1 nor $win_cmd_2 found on \$PATH.\n";
+    } elsif (which($win_cmd_3)) {
+        $ppm_to_root_window_cmd = $ppm_to_root_window_cmd_3;
+     } else {
+        die blurb() . "didn't find $win_cmd_1, $win_cmd_2, or $win_cmd_3 on \$PATH.\n";
     }
 
     $SIG{HUP}  = \&x_cleanup;
@@ -1067,9 +1170,12 @@ sub x_output {
 
     if (!$img_width || !$img_height) {
         $_ = "xdpyinfo";
-        which ($_) || die "$progname: $_ not found on \$PATH.\n";
+        which ($_) || die blurb() . "$_ not found on \$PATH.\n";
         $_ = `$_`;
         ($img_width, $img_height) = m/dimensions: *(\d+)x(\d+) /;
+        if (!defined($img_height)) {
+            die blurb() . "xdpyinfo failed.\n";
+        }
     }
 
     my $bgcolor = "#000000";
@@ -1082,7 +1188,7 @@ sub x_output {
             $bgimage = $background;
             
         } elsif (! $background =~ m@^[-a-z0-9 ]+$@i) {
-            print STDERR "$progname: not a color or readable file: " .
+            print STDERR blurb() . "not a color or readable file: " .
                 "$background\n";
             exit 1;
         } else {
@@ -1095,7 +1201,7 @@ sub x_output {
     #
     $_ = "ppmmake '$bgcolor' $img_width $img_height";
     if ($verbose > 1) {
-        print STDERR "$progname: creating base image: $_\n";
+        print STDERR blurb() . "creating base image: $_\n";
     }
     nontrapping_system "$_ > $image_ppm";
 
@@ -1116,27 +1222,28 @@ sub x_output {
         } elsif ((@_ = jpeg_size ($body))) {
             ($iw, $ih) = @_;
             $cmd = "djpeg |";
-        } elsif ($body =~ "^P\d\n(\d+) (\d+)\n") {
+        } elsif ($body =~ m/^P\d\n(\d+) (\d+)\n/) {
             $iw = $1;
             $ih = $2;
             $cmd = "";
         } else {
-            die "$progname: $bgimage is not a GIF, JPEG, or PPM.\n";
+            die blurb() . "$bgimage is not a GIF, JPEG, or PPM.\n";
         }
 
         my $x = int (($img_width  - $iw) / 2);
         my $y = int (($img_height - $ih) / 2);
         if ($verbose > 1) {
-            print STDERR "$progname: pasting $bgimage (${iw}x$ih) into base ".
+            print STDERR blurb() . "pasting $bgimage (${iw}x$ih) into base ".
                 "image at $x,$y\n";
         }
 
         $cmd .= "pnmpaste - $x $y $image_ppm > $image_tmp1";
         open (IMG, "| $cmd") || die ("running $cmd: $!\n");
         print IMG $body;
+        $body = undef;
         close (IMG);
         if ($verbose > 1) {
-            print STDERR "$progname: subproc exited normally.\n";
+            print STDERR blurb() . "subproc exited normally.\n";
         }
         rename ($image_tmp1, $image_ppm) ||
             die ("renaming $image_tmp1 to $image_ppm: $!\n");
@@ -1148,6 +1255,7 @@ sub x_output {
             my ($headers, $body) = get_document ($img, $base);
             if ($body) {
                 handle_image ($base, $img, $body, $source);
+                $body = undef;
             }
         }
         unlink $image_tmp1, $image_tmp2;
@@ -1159,10 +1267,11 @@ sub handle_image {
     my ($base, $img, $body, $source) = @_;
 
     if ($verbose > 1) {
-        print STDERR "$progname: got $img (" . length($body) . ")\n";
+        print STDERR blurb() . "got $img (" . length($body) . ")\n";
     }
 
     my ($iw, $ih) = image_to_pnm ($img, $body, $image_tmp1);
+    $body = undef;
     return 0 unless ($iw && $ih);
 
     my $ow = $iw;  # used only for error messages
@@ -1173,14 +1282,14 @@ sub handle_image {
     #
     if ($filter_cmd) {
         if ($verbose > 1) {
-            print STDERR "$progname: running $filter_cmd\n";
+            print STDERR blurb() . "running $filter_cmd\n";
         }
 
         my $rc = nontrapping_system "($filter_cmd) < $image_tmp1 >$image_tmp2";
         if ($rc != 0) {
             if ($verbose) {
-                print STDERR "$progname: failed command: \"$filter_cmd\"\n";
-                print STDERR "$progname: failed url: \"$img\" (${ow}x$oh)\n";
+                print STDERR blurb() . "failed command: \"$filter_cmd\"\n";
+                print STDERR blurb() . "failed url: \"$img\" (${ow}x$oh)\n";
             }
             return;
         }
@@ -1218,14 +1327,14 @@ sub handle_image {
         }
         if ($iw <= 10 || $ih <= 10) {
             if ($verbose > 1) {
-                print STDERR "$progname: scaling to ${iw}x$ih would " .
+                print STDERR blurb() . "scaling to ${iw}x$ih would " .
                     "have been bogus.\n";
             }
             return 0;
         }
 
         if ($verbose > 1) {
-            print STDERR "$progname: scaling to ${iw}x$ih\n";
+            print STDERR blurb() . "scaling to ${iw}x$ih\n";
         }
 
         $cmd .= " | pnmscale -xsize $iw -ysize $ih";
@@ -1257,7 +1366,7 @@ sub handle_image {
     }
 
     if ($verbose > 2 && $crop_chance > 0.1) {
-        print STDERR "$progname: crop chance: $crop_chance\n";
+        print STDERR blurb() . "crop chance: $crop_chance\n";
     }
 
     if (rand() < $crop_chance) {
@@ -1283,7 +1392,7 @@ sub handle_image {
         if ($verbose > 1 &&
             ($crop_x != 0   || $crop_y != 0 ||
              $crop_w != $iw || $crop_h != $ih)) {
-            print STDERR "$progname: randomly cropping to " .
+            print STDERR blurb() . "randomly cropping to " .
                 "${crop_w}x$crop_h \@ $crop_x,$crop_y\n";
         }
     }
@@ -1302,7 +1411,7 @@ sub handle_image {
         $y + $crop_h > $img_height) {
 
         if ($verbose > 1) {
-            print STDERR "$progname: cropping for effective paste of " .
+            print STDERR blurb() . "cropping for effective paste of " .
                 "${crop_w}x$crop_h \@ $x,$y\n";
         }
 
@@ -1321,13 +1430,13 @@ sub handle_image {
         $ih = $crop_h;
         $cmd .= " | pnmcut $crop_x $crop_y $iw $ih";
         if ($verbose > 1) {
-            print STDERR "$progname: cropping to ${crop_w}x$crop_h \@ " .
+            print STDERR blurb() . "cropping to ${crop_w}x$crop_h \@ " .
                 "$crop_x,$crop_y\n";
         }
     }
 
     if ($verbose > 1) {
-        print STDERR "$progname: pasting ${iw}x$ih \@ $x,$y in $image_ppm\n";
+        print STDERR blurb() . "pasting ${iw}x$ih \@ $x,$y in $image_ppm\n";
     }
 
     $cmd .= " | pnmpaste - $x $y $image_ppm";
@@ -1337,8 +1446,8 @@ sub handle_image {
 
     if ($rc != 0) {
         if ($verbose) {
-            print STDERR "$progname: failed command: \"$cmd\"\n";
-            print STDERR "$progname: failed url: \"$img\" (${ow}x$oh)\n";
+            print STDERR blurb() . "failed command: \"$cmd\"\n";
+            print STDERR blurb() . "failed url: \"$img\" (${ow}x$oh)\n";
         }
         return;
     }
@@ -1356,7 +1465,7 @@ sub handle_image {
         $rc = nontrapping_system "($post_filter_cmd) < $image_ppm > $target";
         if ($rc != 0) {
             if ($verbose) {
-                print STDERR "$progname: filter failed: " .
+                print STDERR blurb() . "filter failed: " .
                     "\"$post_filter_cmd\"\n";
             }
             return;
@@ -1385,13 +1494,13 @@ sub handle_image {
 
             if ($rc != 0) {
                 if ($verbose) {
-                    print STDERR "$progname: display failed: \"$cmd\"\n";
+                    print STDERR blurb() . "display failed: \"$cmd\"\n";
                 }
                 return;
             }
 
         } elsif ($verbose > 1) {
-            print STDERR "$progname: $target size is $tsize\n";
+            print STDERR blurb() . "$target size is $tsize\n";
         }
     }
 
@@ -1448,7 +1557,7 @@ sub main {
                 $img_width = $1;
                 $img_height = $2;
             } else {
-                die "$progname: argument to \"-size\" must be" .
+                die blurb() . "argument to \"-size\" must be" .
                     " of the form \"640x400\"\n";
             }
         } elsif ($_ eq "-proxy" || $_ eq "-http-proxy") {
@@ -1471,11 +1580,11 @@ sub main {
 
     if (!$root_p && !$no_output_p) {
         die "$copyright" .
-            "$progname: the -root argument is manditory (for now.)\n";
+            blurb() . "the -root argument is mandatory (for now.)\n";
     }
 
     if (!$no_output_p && !$ENV{DISPLAY}) {
-        die "$progname: \$DISPLAY is not set.\n";
+        die blurb() . "\$DISPLAY is not set.\n";
     }
 
     if ($urls_only_p) {