#!/usr/bin/perl
# "fortune" multiplexer, to make "fortune" more fun! Honest.
# Not at all here to troll Harry by causing his xterms to be titled with
# "All Your Base" quotes. -- EvilLionsPhil 26/7/05
# Fixed to not randomly explode when given arguments. -- EvilLionsPhil 4/8/05
# Fixed to retry with fortune-real if the fake one exits without output (umeme
# dying again due to library issues on flora). -- EvilLionsPhil 17/8/05

#use warnings; # Don't use this -- makes Perl observe that the fallbacks are unlikely to be reached (like, duh).
use strict; # This is fine, though.

# The Real Deal has a 50% chance of pwning the opposition to keep this "subtle".
#my @f = qw(fortune-real fortune-real fortune-real fortune-AYB ememe umeme);
my @f = qw(fortune-real fortune-real fortune-AYB ememe); # umeme == dead due to libgcj foo
my $ff = $f[rand(@f)];
my $a = ($ff eq 'fortune-real') ? \@ARGV : []; # umeme dies horribly if given fortune's arguments; ememe/f-AYB ignore them. Only pass through to f-real.
#exec "/usr/cslib/bin/$ff", @$a; # Can't just exec -- umeme may crash
my $aa = join ' ', @$a; my $o = `/usr/cslib/bin/$ff $aa 2>/dev/null`;
if ($o) { print $o; exit 0; }
exec '/usr/cslib/bin/fortune-real', @ARGV;
# Ensure that there's some STDOUT before we barf to STDERR, for the sake of
# things which lazily slurp output from "sh $COMMAND" where $COMMAND = fortune
# (e.g. plenty of xscreensaver hacks)
print "Something Bad has happened.\n"; die "Fortune's broken.\n";
# Something Bad *HAS* happened. This joke Perl script has more lines of
# comments than actual code. How the hell did THAT happen?
