#!/usr/bin/perl

# Random Pornography - Jim Bumgardner 1998
#
# revision history:
#
# Feb 21, 1998 -- Created TIRED database system to allow users to add words
#                 TIRED = tiny interactive random erotica database
#
# Feb 10, 1998 -- added more adjectives and other stuff :) Mike Melo
#

# invoke fate & randomize this baby
#
srand(time | $$);

#
# built-in lists we don't need to modify
#

@possproList = ("his", "her", "his", "her", "his", "her", "his or her");

#
# subroutine to read file into array (ignore empty lines and comments)
#
sub ReadWordlistFromFile {
	local($filename, *wordlist) = @_;
  open(INFILE, "pornodir/" . $filename) || die "Cannot open $filename for reading.";
  while (<INFILE>) {
	chop;
	if (!($_ eq "")) {
		push(@wordlist, $_);
	}
  }
  close(INFILE);
}


#
# read all the dirty word files
#
&ReadWordlistFromFile("exclaim.words",*exclaimList);
&ReadWordlistFromFile("name.words",*nameList);
&ReadWordlistFromFile("utter.words",*utteredList);
&ReadWordlistFromFile("diddle.words",*diddledList);
&ReadWordlistFromFile("insert.words",*insertedList);
&ReadWordlistFromFile("adjective.words",*adjList);
&ReadWordlistFromFile("concave.words",*concaveList);
&ReadWordlistFromFile("convex.words",*convexList);

#
# then we output our HTML headers
#
print "Content-type: text/html\n";
print "Cache-Control: no-cache\n";
print "Pragma: no-cache\n\n";

&EchoFile("random1.html");

#
# Display a random fruit (URL needs to be fixed)
#
$fruitPic = "fruit" . int(rand(6)) . ".gif";
print "<img src=\"http://www.jbum.com/jbum/tl/$fruitPic\" align=right>\n";

#
# then we figure out how many sentences we're gonna output 
# (anywhere from 6 to 11)
#

$nbrSentences = 6 + int(rand(5));


#
# then we utter them...
#

for (1..$nbrSentences) 
{
	#
	# compute random words
	#
	$person   = $nameList[int(rand($#nameList+1))];
	$person2  = $nameList[int(rand($#nameList+1))];
	$posspro  = $possproList[int(rand($#possproList+1))];
	$posspro2  = $possproList[int(rand($#possproList+1))];
	$exclaim  = $exclaimList[int(rand($#exclaimList+1))];
	$uttered  = $utteredList[int(rand($#utteredList+1))];
	$diddled  = $diddledList[int(rand($#diddledList+1))];
	$inserted = $insertedList[int(rand($#insertedList+1))];
	$adj      = $adjList[int(rand($#adjList+1))] . " ";
	$adj2     = $adjList[int(rand($#adjList+1))] . " ";
	$concave  = $concaveList[int(rand($#concaveList+1))];
	$convex   = $convexList[int(rand($#convexList+1))];
	$adj = "" if int(rand(3)) == 0;
	$adj2 = "" if int(rand(3)) == 0;
	$object = $convex;
	$object = $concave if int(rand(2)) == 0;
	$sentenceType = int(rand(5));

	#
	# output random sentance, based on type
	#
	if ($sentenceType == 0) {
		print "\"$exclaim\"\n";
	} elsif ($sentenceType == 1) {
		print "\"$exclaim\", $person $uttered.\n";
	} elsif ($sentenceType == 2) {
		print "$person $diddled $posspro $adj$object.\n";
	} elsif ($sentenceType == 3) {
		print "\"$exclaim\", $person $uttered, as $person2 $diddled $posspro $adj$object.\n";
	} elsif ($sentenceType == 4) {
		print "\"$exclaim\", $person $uttered, as $person2 $inserted $posspro $adj$convex into $posspro2 $adj2$concave.\n";
	}
	print "<p>\n";
}

#
# then we output our html footers
#
&EchoFile("random2.html");

# subroutine to echo the contents of a file from the "pornodir" directory
#
sub EchoFile {
  local ($filename) = @_;
  open(INFILE, "pornodir/" . $filename) || die "Cannot open $filename for reading.";
  while (<INFILE>) {
  	print;
  }
  close(INFILE);
}
