#!/usr/bin/perl

#
# Globals
#
use vars qw/$deftext %opt /;

#
# Command line options processing
#
sub init()
{
	use Getopt::Std;
	my $opt_string = 'hdoynsi';
	getopts( "$opt_string", \%opt ) or usage();
	usage() if $opt{h};
}

#
# Message about this program and how to use it
#
sub usage()
{
	print STDERR << "EOF";

orly -- Print an O RLY owl

usage: $0 [-hdoyn] [<MESSAGE>]

 -h        : this (help) message
 -o, -d    : print the "O RLY" owl
 -y        : print the "YA RLY" owl
 -n        : print the "NO WAI!" owl
 -s        : Print "SRSLY" as a question, statement or 
 	     exclamation, respectively for the above.
 -i        : take MESSAGE from STDIN

EOF
	exit;
}

sub printorly() {
	$deftext = "O RLY?";
	print << "EOO"
 ___
{o,o}
|)__)
-"-"-
EOO
}

sub printyarly() {
	$deftext = "YA RLY";
	print << "EOO"
 ___ 
{o.o}
|)_(|
-"-"-
EOO
}

sub printnowai() {
	$deftext = "NO WAI!";
	print << "EOO"
  ___
 {o,o}
 (__(|
 -"-"-
EOO
}

$givenstatement = "";
for ($i=0; $i<($#ARGV + 1); $i++)
{
	if (substr($ARGV[$i],0,1) ne "-")
	{
		$up = uc($ARGV[$i]);
		$givenstatement = "$givenstatement$up ";
	}
}

init();

if ($opt{i}) {
	while (<STDIN>) {
		$givenstatement = $givenstatement.uc($_);
	}
	chomp($givenstatement);
}
if ($opt{y}) {
	printyarly();
	$deftext = "SRSLY" if ($opt{s});
}
elsif ($opt{n}) {
	printnowai();
	$deftext = "SRSLY!" if ($opt{s});
}
elsif ($opt{d} || $opt {o}) {
	printorly();
	$deftext = "SRSLY?" if ($opt{s});
}
elsif ($opt{s}) {
	printyarly();
	$deftext = "SRSLY";
}
else {
	printorly();
}

if ($givenstatement)
{
	print "$givenstatement\n";
}
else
{
	print "$deftext\n";
}

exit;
