#!/usr/bin/perl

$FIFO = "/home/bjared/.signature";
$SIG  = "/home/bjared/.realsig";

@a = (
	"A is for AMY who fell down the stairs",
	"B is for BASIL assaulted by bears",
	"C is for CLARA who wasted away",
	"D is for DESMOND thrown out of a sleigh",
	"E is for ERNEST who choked on a peach",
	"F is for FANNY sucked dry by a leech",
	"G is for GEORGE smothered under a rug",
	"H is for HECTOR done in by a thug",
	"I is for IDA who drowned in a lake",
	"J is for JAMES who took lye by mistake",
	"K is for KATE who was struck with an axe",
	"L is for LEO who swallowed some tacks",
	"M is for MAUD who was swept out to sea",
	"N is for NEVILLE who died of ennui",
	"O is for OLIVE run through with an awl",
	"P is for PRUE trampled flat in a brawl",
	"Q is for QUENTIN who sank in a mire",
	"R is for RHODA consumed by a fire",
	"S is for SUSAN who perished of fits",
	"T is for TITUS who flew into bits",
	"U is for UNA who slipped down a drain",
	"V is for VICTOR squashed under a train",
	"W is for WINNIE embedded in ice",
	"X is for XERXES devoured by mice",
	"Y is for YORICK whose head was knocked in",
	"Z is for ZILLAH who drank too much gin"
);

while (1) {
  unless (-p $FIFO) {
    unlink $FIFO;
    system('mknod', $FIFO, 'p') && die "can't mknod $FIFO: $!";
  }
  open (INFILE, "< $SIG") or die "could not open real sig: $!";
  $real_sig = join('', <INFILE>);
  close (INFILE);

  open (FIFO, "> $FIFO") or die "could not open fifo: $!";
  srand(time()/$$);
  $str = "\"$a[int(rand()*25)]\" -- Edward Gorey";
  $real_sig =~ s/!!quote!!/$str/;
  print FIFO "$real_sig";
  close(FIFO);
  sleep 2;
}
exit;
