#!/usr/bin/perl
use cPanelUserConfig;
#
# English to Pirate Translator in honor of Talk Like a Pirate Day 19 Sept
#-----------------------------------------------------------------------------
#
#              Copyright 2003-5 J.R.(Sydd)Souza - syddware.com
#                             All Rights Reserved
#
# This script, and all others so marked, are the property of 
# SyddWare and may be copied/modified to meet your site specific
# needs.
#
# Use of this script implies acceptance of the following:
#
# THE PRODUCTS SUPPLIED HERE UNDER ARE FURNISHED "AS IS".  SYDDWARE
# DISCLAIMS WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF FITNESS.  
# IN NO EVENT WILL SYDDWARE BE LIABLE FOR DAMAGES TO PROPERTY OR
# ANY DAMAGES RESULTING FROM LOSS OF DATA, PROFITS OR USE OF
# PRODUCTS, OR FOR ANY INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.  THIS LIMITATION OF SYDDWARE
# LIABILITY WILL APPLY REGARDLESS OF THE FORM OF ACTION, WHETHER
# IN CONTRACT OR TORT INCLUDING NEGLIGENCE.  THE RECIPIENT AGREES TO HOLD
# SYDDWARE HARMLESS AGAINST ANY CLAIMS INCLUDING COURT
# COSTS AND LEGAL EXPENSES RELATING TO THE PRODUCTS FURNISHED BY SYDDWARE.
#
#----------------------------------------------------------------------------- 
require 5.004;

#
use FindBin;
use lib "$FindBin::Bin";

############################################################################
#                                                                          #
# parse_form()                      Version 1.5                            #
# Written by Matthew Wright         mattw@worldwidemart.com                #
# Created 9/30/96                   Last Modified 3/28/97                  #
#                                                                          #
# Copyright 1997 Craig Patchett & Matthew Wright.  All Rights Reserved.    #
# This subroutine is part of The CGI/Perl Cookbook from John Wiley & Sons. #
# License to use this program or install it on a server (in original or    #
# modified form) is granted only to those who have purchased a copy of The #
# CGI/Perl Cookbook. (This notice must remain as part of the source code.) #
#                                                                          #
# Function:      Takes form field data from a POST or GET request and      #
#                converts it to name/value pairs in the %FORM array or,    #
#                if a corresponding entry in the %CONFIG array is defined, #
#                in %CONFIG.                                               #
#                                                                          #
# Usage:         &parse_form;                                              #
#                                                                          #
# Variables:     None                                                      #
#                                                                          #
# Returns:       0 if invalid request method                               #
#                1 if successful                                           #
#                                                                          #
# Uses Globals:  Sets %CONFIG with name/value pairs if corresponding entry #
#                  in %CONFIG is defined                                   #
#                Otherwise sets entries in %FORM                           # 
#                $Error_Message for descriptive error messages             #
#                                                                          #
# Files Created: None                                                      #
#                                                                          #
############################################################################

sub parse_form {
    local($name, $value, $pair, $buffer, @pairs);
    
    # Check for request method and handle appropriately
    
    if ($ENV{'REQUEST_METHOD'} eq 'GET') {
        @pairs = split(/&/, $ENV{'QUERY_STRING'});
    }
    elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
        @pairs = split(/&/, $buffer);
    }
    else {
        $Error_Message = "Bad request method ($ENV{'REQUEST_METHOD'}).  Use POST or GET";
        return(0);
    }

    # Convert the data to its original format
    
    foreach $pair (@pairs) {
        ($name, $value) = split(/=/, $pair);

        $name =~ tr/+/ /;
        $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
        $name =~ s/\n//g;
        $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	#$value =~ s/\n/ /g;
	#$value =~ s/\r//g;
        $value =~ s/'/`/g;

        # If they try to include server side includes, erase them, so they
        # arent a security risk if the HTML gets returned.  Another
        # security hole plugged up.
        
        $value =~ s/<!--(.|\n)*-->//g;

        # Store name/value pair in %CONFIG if the corresponding entry is
        # defined
        
        if ($CONFIG{$name}) {
            $CONFIG{$name} .= ",$value";
        }
        elsif (defined($CONFIG{$name})) {
            $CONFIG{$name} = $value;
        }
        
        # Otherwise store in %FORM
        
        elsif ($FORM{$name}) {
            $FORM{$name} .= ",$value";
        }
        else {
            $FORM{$name} = $value;
        }
    }
    return(1);
}

#
# SimpleGet.pl  -- standalone replacement for LWP::Simple
#
# This is a fairly minimal implementation of the HTTP GET protocol in
# Perl. It only does the 'GET' method via http (not https), and handles
# proxies and redirects but nothing more complicated. It is designed to
# be a simple replacement for the LWP library for scripts that only
# use the get(), getprint() and/or getstore() routines.
#
# It should be noted that web client Perl scripts fall into two general
# categories: Simple scripts that just get a page and grab one small
# bit of information from it, and complex tools like browsers, robots,
# site-shadowing utilities, custom search engines, etc. For the simple
# category, the LWP library and the other libraries it depends on
# (over 1.5 megabytes) is overkill.
#
# To use this code, put it in a file called "SimpleGet.pl" somewhere
# in your Perl @INC searchpath, such as /usr/lib/perl5/site_perl
# then add this line to your Perl script:
#
#   require "SimpleGet.pl";
#
# Each of the following is equivalent (except that the last creates
# a file "temp.html" in the current directory):
#
#   print get("http://www.mrob.com"); $err = $http_get_result;
#
#   $_ = get("http://www.mrob.com"); print $_; $err = $http_get_result;
#
#   $err = getprint("http://www.mrob.com");
#
#   $err = getstore("http://www.mrob.com", "temp.html");
#     system("cat temp.html");
#
# get() reads the data via HTTP and returns it. getprint() sends the
# data to STDOUT with relatively low memory overhead (useful if the
# data is large)
#
# This library also invites one-liner shell commands such as:
#
#   perl -e "require 'SimpleGet.pl'; getprint('http://www.mrob.com')"
#
# If you want to do anything more than loading simple pages and
# parsing their contents yourself, you should use LWP and the
# associated libraries. These libraries include such functions as MIME
# support, HTML parsing, handling of other transfer protocols like
# HTTPS and FTP, and much more. To learn more, see
# http://www.linpro.no/lwp/
#
# Existing web-client scripts that contain 'use LWP::Simple;' and only
# call the get() and/or getprint() functions can be converted to use
# SimpleGet by replacing the 'use LWP::Simple;' line with
# 'require "SimpleGet.pl";'
#
# Two extensions have been added to the functionality provided by the
# LWP get() and getprint() routines:
#   - Set $http_no_cache to 1 to force proxies to reload, or to 0 for
#     a normal GET.
#   - The variable $http_get_result is set to the result code (e.g. 200
#     or 404). (It is also returned by getprint() and getstore())
#
# Copyright, Usage, Feedback, etc:
#
#   This library is free software; you can redistribute it and/or
#   modify it under the same terms as Perl itself.
#
# The minimal adaptation of LWP::Simple was created by Robert Munafo
# (www.mrob.com) from the LWP code. If you have problems, suggestions,
# or feedback regarding this file, please send them to "mrob at mrob
# dot com". Please don't bother Gisle Aas (the primary author of LWP)
# about it because it isn't his creation.
#
# 20000114 Initial version, derived from LWP::Simple, with minor additions
#   to handle http_proxy
# 20000117 Add $http_get_result and get_to_stdout().
# 20000118 Add $http_no_cache. Rename get_to_stdout() to getprint,
#   because that's what it's called in LWP.
# 20000119 Add getstore(), is_success() and "1;" at end; make it work
#   under "use strict;"

my ($http_stream_out, %http_loop_check);

sub _trivial_http_get
{
  my($host, $port, $path) = @_;
  my($AGENT, $VERSION, $p);
  #print "HOST=$host, PORT=$port, PATH=$path\n";

  $AGENT = "get-minimal";
  $VERSION = "20000118";

  $path =~ s/ /%20/g;

  require IO::Socket;
  local($^W) = 0;
  my $sock = IO::Socket::INET->new(PeerAddr => $host,
                                   PeerPort => $port,
                                   Proto   => 'tcp',
                                   Timeout  => 60) || return;
  $sock->autoflush;
  my $netloc = $host;
  $netloc .= ":$port" if $port != 80;
  my $request = "GET $path HTTP/1.0\015\012"
              . "Host: $netloc\015\012"
              . "User-Agent: $AGENT/$VERSION/u\015\012";
  $request .= "Pragma: no-cache\015\012" if ($main::http_no_cache);
  $request .= "\015\012";
  print $sock $request;

  my $buf = "";
  my $n;
  my $b1 = "";
  while ($n = sysread($sock, $buf, 8*1024, length($buf))) {
    if ($b1 eq "") { # first block?
      $b1 = $buf;         # Save this for errorcode parsing
      $buf =~ s/.+?\015?\012\015?\012//s;      # zap header
    }
    if ($http_stream_out) { print GET_OUTFILE $buf; $buf = ""; }
  }
  return undef unless defined($n);

  $main::http_get_result = 200;
  if ($b1 =~ m,^HTTP/\d+\.\d+\s+(\d+)[^\012]*\012,) {
    $main::http_get_result = $1;
    # print "CODE=$main::http_get_result\n$b1\n";
    if ($main::http_get_result =~ /^30[1237]/ && $b1 =~ /\012Location:\s*(\S+)/
) {
      # redirect
      my $url = $1;
      return undef if $http_loop_check{$url}++;
      return _get($url);
    }
    return undef unless $main::http_get_result =~ /^2/;
  }

  return $buf;
}

sub _get
{
  my $url = shift;
  my $proxy = "";
  grep {(lc($_) eq "http_proxy") && ($proxy = $ENV{$_})} keys %ENV;
  if (($proxy eq "") && $url =~ m,^http://([^/:]+)(?::(\d+))?(/\S*)?$,) {
    my $host = $1;
    my $port = $2 || 80;
    my $path = $3;
    $path = "/" unless defined($path);
    return _trivial_http_get($host, $port, $path);
  } elsif ($proxy =~ m,^http://([^/:]+):(\d+)(/\S*)?$,) {
    my $host = $1;
    my $port = $2;
    my $path = $url;
    return _trivial_http_get($host, $port, $path);
  } else {
    return undef;
  }
}

sub get ($)
{
  $http_stream_out = 0;

  %http_loop_check = ();
  goto \&_get;
}

sub getprint ($)
{
  my $url = shift;

  $http_stream_out = 1;
  open(GET_OUTFILE, ">&STDOUT");
  %http_loop_check = ();
  _get($url);
  close GET_OUTFILE;
  return $main::http_get_result;
}

sub getstore ($$)
{
  my $url = shift;
  my $file = shift;

  $http_stream_out = 1;
  open(GET_OUTFILE, "> $file");
  %http_loop_check = ();
  _get($url);
  close GET_OUTFILE;
  return $main::http_get_result;
}

sub is_success ($)
{
  my $code = shift;

  return ($code =~ /^2/);
}

# end of SimpleGet.pl  013

############################################################################
################################# MAIN #####################################
############################################################################

&parse_form;
if (!defined($ENV{"HTTP_USER_AGENT"})) { # command line not web
  if ($ARGV[0] =~ /^http:/i) {
    $FORM{url} = $ARGV[0];
  } else {
    while (<>) {
      $FORM{text} .= $_;
    }
  }
}

if (defined $FORM{url} && $FORM{url} ne "") {
  $FORM{text} = get($FORM{url}); 
  if (($err = $http_get_result) > 200) {
    $FORM{text} = "Stop wasting my time with URLs like $FORM{url} returning error code $err and put something in the box!";
    $FORM{url} = "";
  } else {
    print "Content-type: text/html\n\n";
    print &translate($FORM{text},$FORM{url});
    exit;
  }
} elsif (! defined $FORM{text} || ! $FORM{text}) { 
  $FORM{text} = "Stop wasting my time and put something in the box!"; 
}

if (defined($ENV{"HTTP_USER_AGENT"})) { # command line not web
  print <<_ENDHED;
Content-type: text/html

<html>
<head>
<title>Pirate Speak</title>
</head>
<body background="http://www.syddware.com/images/Sailcloth_Shore600.jpg">
<table border="0" align="center" width="75%">
<tr>
<td align="center"> 
<table width="100%"><tr><td align="left"><tr><td><img src="http://www.syddware.com/images/sncb_face.png" alt="Animated Jolly Roger from uselessgraphics.com - Thanks mateys!" width="149" height="108">
</td><td align="center"><img src="http://www.syddware.com/images/jolly_roger2.gif" alt="Animated Jolly Roger from uselessgraphics.com - Thanks mateys!" width="64" height="50">
</td><td align="right"><img src="http://www.syddware.com/images/sncb_profile.png" alt="Animated Jolly Roger from uselessgraphics.com - Thanks mateys!" width="149" height="110">
</td></tr></table>
</td>
</tr>
<tr>
<td> 
<h3>Arrr, so ye be wantin' t' go to sea an' ye don't be wantin' t' end up in
Davy Jones' Locker. Then ye best be learnin' t' be talkin' like a buccaneer.
</h3>
</td>
</tr>
<tr>
<td> 
<p><b> 
_ENDHED
}
my $piresult = &translate($FORM{text},"text");
print $piresult;
if (defined($ENV{"HTTP_USER_AGENT"})) { # command line not web
  print <<_ENDTAIL;
</b></p>
<p></p>
<p>What else ye got? An' be quick about it, I be shippin' out soon!</p>
<form method="POST" ACTION="/cgi-bin/pirate.pl">
<h2>See How A Pirate Would Say It</h2>
<textarea name="text" rows="5" cols="80"></textarea>
<p></p>
<p><h2><font color="red">New!</font> Translate Yer Own Website!</h2>If ye'd like t' hear how'd 't soun' if a pirate read yer <b>web page</b>
ter ye, enter the ARRRRRL (URL) below decks. And be quick about it, I ain't got all voyage:</p>
<input name="url" type="text" id="url" size="100">
<p align="CENTER"><b><input type="submit" value="What say ye, ya scurvy dog?">
<input type="reset" value="Belay that"></b>
<br></p>
</form>
</td>
</tr>
</table>
<table border="0" width="75%" align="center" valign="middle">
<tr>
<td valign="bottom" align="center">
<h6>Provided in support of <a href="http://www.talklikeapirate.com"
onmouseover="window.status='Visit talklikeapirate.com';return true"
onmouseout="window.status='';return true">
Talk Like a Pirate Day, September 19</h6>
</td>
</tr>
</table>
<table border="0" width="75%" align="center" nowrap="nowrap" valign="middle">
<tr>
<td valign="bottom" align="center" nowrap="nowrap"> <h6><a
href="http://www.syddware.com/"
onmouseover="window.status='Webpage by SyddWare - Visit Us';return true"
onmouseout="window.status='';return true">
<img src="http://www.syddware.com/sydduck3.gif" alt="SyddWare"
align="bottom" border="1" width="35" height="35"></a>
<a href="http://www.syddware.com/copyrite.html"
 onmouseover="window.status='See what our loving caring lawyers have to say.';return true"
 onmouseout="window.status='';return true">Page &copy; SyddWare</A>, Jeffrey R.
(Sydd) Souza&nbsp;
<img src="http://www.syddware.com/sw.png" width="103" height="10" align="bottom" alt="*"></H6>
</td>
</tr>
</table>
</html>
_ENDTAIL
}
# end main
#
sub translate($$) {
  my ($lines,$mode) = @_;
  # while (<STDIN>) {
  #   $lines .= $_;
  # }

  use locale;
  %partials = (
   "disable" => "scuttle",
   "sailor" => "jack",
   "flag" => "jolly roger",
   "recruit" => "sprog",
   "lean" => "list",
   "tilt" => "list",
   "scoundrel" => "scallywag",
   "front" => "fore",
   "back" => "aft",
   "left" => "port",
   "right" => "starboard",
   "bstarboard" => "bright",
   "wstarboard" => "wright",
   "fstarboard" => "fright",
   "curse" => "wannion",
   "vengeance" => "wannion",
   "group" => "squadron",
   "fellow" => "swabbie",
   "individual" => "swabbie",
   "person" => "swabbie",
   "people" => "swabbies",
   "concept" => "idee",
   "year" => "voyage",
   "mouth" => "bung hole",
   "fuck" => "hork",
   "daughter" => "lass",
   "month" => "moon",
   "entrance" => "gangplank",
   "couches" => "bunks",
   "couch" => "bunk",
   "sofa" => "bunk",
   "argue" => "duel",
   "hashish" => "cigars",
   "hash" => "cigar",
   "aftup" => "backup arrr",
  );
  %phrases = (
   "lip\\s+" => "bung hole ",
   "a\\s+back" => "an aft",
   "a\\s+aft" => "an aft",
   "I\\s+am" => "I be",
   "I\\s+take" => "me takes",
   "my\\s+friend" => "me hearty",
   "will\\s+be" => "be",
   "has\\s+been" => "be",
   "could\\s+not" => "couldna",
   "would\\s+not" => "wouldna",
   "should\\s+not" => "ortin't",
   "can\\s+not" => "canna",
   "does\\s+not" => "dasn't",
   "bad\\s+person" => "scoundrel",
   "bottom\\s+of\\s+the\\s+sea" => "Davy Jones' Locker",
   "carrying\\s+on" => "swashbucklin'",
   "now\\s+and\\s+then" => "now an' ag'in",
   "a\\s+concept" => "an idee",
   "en\\s+route" => "underway",
   "magnifying\\s+glass" => "lookin' glass",
   "hundred\\s+" => "bucketfull o' ",
   "thousand\\s+" => "chestfull o' ",
   "million\\s+" => "cargo holds o' ",
   "hundreds\\s+of" => "buckets o'",
   "thousands\\s+of" => "chestfulls o'",
   "millions\\s+of" => "cargo holds o'",
   "it\\s+is" => "'tis",
   "It\\s+is" => "'Tis",
   "it's" => "'tis",
   "It's" => "'Tis",
   "it`s" => "'tis",
   "It`s" => "`Tis",
   "I'm" => "I be",
   "I`m" => "I be",
   "row\\s+boat" => "skiff",
   "life\\s+boat" => "skiff",
   "have\\s+been" => "ben",
   "crack\\s+pipe" => "good cuban",
   "sleeping\\s+bag" => "bunk",
   "sleeping\\s+" => "bunkin' ",
   "ass\\s+hole" => "bilge rat",
   "ever\\s+" => "ere",
   "had\\s+taken" => "tookst",
   "took\\s+" => "tookst ",
   "older\\s+than" => "older'n",
   "younger\\s+than" => "younger'n",
   "week\\s+" => "tides ",
   "wild\\s+ride" => "rough voyage",
   "dung\\s+heap" => "bucket o' bilge water",
   "looked\\s+at" => "eyeballed",
   "look\\s+at" => "eyeball",
   "in\\s+the\\s+middle" => "on the yardarm",
   "twelve\\s+o'clock\\s+at\\s+night" => "low tide",
   "twelve\\s+o`clock\\s+at\\s+night" => "low tide",
   "twelve\\s+o'clock\\s+noon" => "high tide",
   "twelve\\s+o`clock\\s+noon" => "high tide",
   "these\\s+pages" => "this here log",
   "this\\s+book" => "this here log",
   );
  %words = (
   "boating" => "sailin'",
   "cry" => "bawl",
   "weep" => "bawl",
   "monday" => "mondee",
   "tuesday" => "toosdee",
   "wednesday" => "wensdee",
   "thurday" => "tursdee",
   "friday" => "fridee",
   "saturday" => "satterdee",
   "sunday" => "sundee",
   "january" => "janree",
   "february" => "febree",
   "august" => "augst",
   "september" => "septembree",
   "october" => "octobree",
   "november" => "novembree",
   "december" => "decembree",
   "believe" => "b'lieve",
   "anybody" => "ere",
   "anyone" => "ere",
   "noon" => "high tide",
   "midnight" => "low tide",
   "guitar" => "squeezebox",
   "flute" => "fife",
   "naked" => "nekked",
   "nude" => "nekked",
   "butt" => "aft",
   "ok" => "arrr",
   "okay" => "arrr",
   "kitchen" => "galley",
   "sick" => "sea sick",
   "said" => "spake",
   "travel" => "set sail",
   "forward" => "fore",
   "forth" => "fore",
   "asshole" => "bilge rat",
   "slept" => "bunked",
   "sleepingbag" => "bunk",
   "outside" => "abroadside",
   "authority" => "captainliness",
   "cruise" => "cruise arrr",
   "Cruise" => "Cruise arrr",
   "day" => "tide",
   "weeks" => "tides",
   "her" => "the lass'",
   "him" => "the lad's",
   "brother" => "laddie",
   "sister" => "lassie",
   "himself" => "hisself",
   "yesterday" => "last high tide'",
   "tomorrow" => "next high tide'",
   "went" => "sailed'",
   "goddamned" => "scallywaggin'",
   "goddamn" => "scallywaggin'",
   "damned" => "scallywaggin'",
   "rowboat" => "skiff",
   "loser" => "scurvy cur",
   "throne" => "keel",
   "runabout" => "skiff",
   "sufficiently" => "a wee bit",
   "sufficient" => "a wee bit o'",
   "bottle" => "keg",
   "sheet" => "sail",
   "walked" => "keel hauled",
   "walk" => "keel haul",
   "cowards" => "yeller bellies",
   "coward" => "yeller belly",
   "cowardice" => "yellerbelly'dness",
   "shit" => "bilge water",
   "bullshit" => "bilge water",
   "shitty" => "bilge watery",
   "dung" => "bilge water",
   "dungheap" => "bucket o' bilge water",
   "crap" => "bilge water",
   "crappy" => "bilge watery",
   "feces" => "bilge water",
   "eyes" => "one good eye",
   "management" => "captainship",
   "son" => "lad",
   "home" => "homeport",
   "sunburned" => "sunburnt",
   "die" => "sink t'Davy Jones' locker",
   "died" => "sank t'Davy Jones' locker",
   "death" => "Davy Jones' locker",
   "pretend" => "make like",
   "just" => "jus'",
   "woman" => "lass",
   "women" => "lasses",
   "girls" => "lasses",
   "girlfriend" => "beauty",
   "girlfriends" => "beauties",
   "wife" => "buxom beauty",
   "wives" => "buxom beauties",
   "hello" => "arrrr",
   "goodbye" => "arrrr",
   "good-bye" => "arrrr",
   "goodbyes" => "arrrrs",
   "good-byes" => "arrrrs",
   "bye" => "arrrr",
   "byes" => "arrrrs",
   "hi" => "ahoy",
   "ok" => "arrr",
   "floor" => "deck",
   "ground" => "poop deck",
   "basement" => "bilge",
   "hey" => "ahoy",
   "stop" => "avast",
   "yes" => "aye",
   "yay" => "aye",
   "yeah" => "aye",
   "milk" => "grog",
   "koolaid" => "grog",
   "kool-aid" => "grog",
   "friend" => "matey",
   "friends" => "shipmates",
   "adolescence" => "laddie days",
   "drunk" => "loaded to the gunwhales",
   "drunken" => "loaded to the gunwhales",
   "my" => "me",
   "buffoon" => "squiffy",
   "buffoons" => "squiffies",
   "bastard" => "son of a biscuit eater",
   "bastards" => "sons of a biscuit eater",
   "treasure" => "booty",
   "treasures" => "bountiful booty",
   "waitress" => "servin' wench",
   "stewardess" => "servin' wench",
   "waitresses" => "servin' wenches",
   "stewardesses" => "servin' wenches",
   "there" => "thar",
   "they've" => "they's",
   "they`ve" => "they's",
   "they're" => "they's",
   "they`re" => "they's",
   "they " => "they's ",
   "apparently" => "arr",
   "see" => "be seein'",
   "with" => "wi'",
   "the" => "th'",
   "of" => "o'",
   "to" => "t'",
   "it" => "'t",
   "except" => "'ceptin'",
   "for" => "fer",
   "no" => "nay",
   "you" => "ye",
   "your" => "yer",
   "yourself" => "yersef",
   "those" => "them",
   "should","ortin' ta",
   "ought","ortin'",
   "am" => "be",
   "ass" => "arse",
   "assed" => "arsed",
   "are" => "be",
   "is" => "be",
   "was" => "be",
   "have" => "be havin'",
   "laugh" => "yo ho ho",
   "laughter" => "yo ho ho",
   "fight" => "swashbuckle",
   "fighter" => "swashbuckler",
   "carouse" => "swashbuckle",
   "carouser" => "swashbuckler",
   "carousing" => "swashbucklin'",
   "gold" => "dubloon",
   "beer" => "grog",
   "beers" => "more grog",
   "ale" => "grog",
   "ales" => "more grog",
   "tea" => "grog",
   "teas" => "more grog",
   "coffee" => "grog",
   "coffies" => "more grog",
   "didn't" => "didna",
   "didn`t" => "didna",
   "can't" => "canna",
   "can`t" => "canna",
   "shouldn't" => "ortin't",
   "shouldn`t" => "ortin't",
   "wouldn't" => "wouldna",
   "wouldn`t" => "wouldna",
   "couldn't" => "couldna",
   "couldn`t" => "couldna",
   "isn't" => "t'ain't",
   "isn`t" => "t'ain't",
   "don't" => "dasn't",
   "don`t" => "dasn't",
   "doesn't" => "dasn't",
   "doesn`t" => "dasn't",
   "piracy" => "sweet trade",
   "shack" => "sea shanty",
   "whip" => "cat o' nine tails",
   "scared" => "lily livered",
   "afraid" => "lily livered",
   "stupid" => "lily livered",
   "foolish" => "lily livered",
   "punish" => "keel haul",
   "quickly" => "smartly",
   "immediate" => "smart-like",
   "whatever" => "whatere",
   "forever" => "ere",
   "every" => "ever'",
   "and" => "an'",
   "idea" => "idee",
   "not" => "nay",
   "everybody" => "sea dogs an' land lubbers",
   "everyone" => "sea dogs an' land lubbers",
   "their" => "the'r",
   "recognize" => "reckon",
   "realize" => "reckon",
   "recognized" => "reckoned",
   "realized" => "reckoned",
   "because" => "on accoun' o'",
   "savings" => "booty",
   "symphony" => "sea yarn",
   "symphonies" => "sea yarns",
   "money" => "treasure",
   "human" => "crewmate",
   "humans" => "crewmaties",
   "themselves" => "they's self",
   "few" => "wee",
   "small" => "wee",
   "miniscule" => "wee",
   "tiny" => "wee",
   "little" => "wee",
   "out" => "ou'",
   "Island" => "Isle, arrr",
   "Islands" => "Isles, arrr",
   "island" => "isle, arrr",
   "islands" => "isles, arrr",
   "jeans" => "britches",
   "pants" => "britches",
   "shorts" => "britches",
   "underpants" => "underbritches",
   "underwear" => "underbritches",
   "bed" => "bunk",
   "bedroom" => "below decks",
   "mission" => "voyage",
   "guns" => "cannons",
   "dollar" => "piece o' eight",
   "dollars" => "pieces o' eight",
   "though" => "tho",
   "remember" => "reckon",
   "were" => "was",
   "where" => "'ere",
   "magnifier" => "looking glass",
   "crackpipe" => "good cuban",
   "bathroom" => "head",
   "toilet" => "head",
   "embedded" => "bunked",
   "embed" => "bunk",
   "bed" => "bunk",
   "employees" => "crewmen",
   "employee" => "crewman",
   "simultaneously" => "ary the same time",
  );
  %http = (
   "head" => "hade",
   "window" => "port hole",
  );
  @insults = (
   "scurvy cur",
   "scurvy cur whut deserves the black spot",
   "scurvy cur who ortin' t' be keel hauled",
   "lily livered scurvy cur",
   "horn swogglin' scurvy cur",
   "scurvy dog",
   "scurvy dog whut deserves the black spot",
   "scurvy dog who ortin' t' be keel hauled",
   "lily livered scurvy dog",
   "horn swogglin' scurvy dog",
   "swabbie",
   "swabbie whut deserves the black spot",
   "swabbie who ortin' t' be keel hauled",
   "lily livered swabbie",
   "horn swollgin' swabbie",
   "scallywag",
   "scallywag whut deserves the black spot",
   "scallywag who ortin' t' be keel hauled",
   "lily livered scallywag",
   "horn swollgin' scallywag",
   "landlubber",
   "landlubber whut deserves the black spot",
   "landlubber who ortin' t' be keel hauled",
   "lily livered lanlubber",
   "horn swogglin' landlubber",
   "bilge rat",
   "bilge rat whut deserves the black spot",
   "bilge rat who ortin' t' be keel hauled",
   "lily livered bilge rat",
   "horn swogglin' bilge rat",
  );
  @compliments = (
   "buccanneer",
   "swashbuckler",
   "gentleman o' fortune",
   "shipmate",
   "sea dog",
   "seafarin' hearty",
  );
  $value = time() ^ ($$ + ($$ << 15));
  #print STDERR $value."\n";
  srand($value);
  rand($value);
  #require 'debug_log.pl';
  #&debug_log("[".$lines."]\n");
  chomp($lines);
  foreach $phrase (keys %phrases) {
    $lines =~ s/$phrase/$phrases{$phrase}/g;
    $capphrase = "\u$phrase";
    $capreplace = "\u$phrases{$phrase}";
    $lines =~ s/$capphrase/$capreplace/g;
    $capphrase = "\U$phrase";
    $capreplace = "\U$phrases{$phrase}";
    $lines =~ s/$capphrase/$capreplace/g;
    #print STDERR "phrase $phrase $phrases{$phrase} cap $capphrase $capreplace\n";
  }
  foreach $partial (keys %partials) {
    $lines =~ s/$partial/$partials{$partial}/g;
    $capphrase = "\u$partial";
    $capreplace = "\u$partials{$partial}";
    $lines =~ s/$capphrase/$capreplace/g;
    $capphrase = "\U$partial";
    $capreplace = "\U$partials{$partial}";
    $lines =~ s/$capphrase/$capreplace/g;
    #print STDERR "partial $partial $partials{$partial} cap $capphrase $capreplace\n";
  }
  $lines =~ s/pirate/$compliments[rand(@compliments)]/g;
  $capphrase = "Pirate";
  $capreplace = "\u$compliments[rand(@compliments)]";
  $lines =~ s/$capphrase/$capreplace/g;
  $capphrase = "PIRATE";
  $capreplace = "\U$compliments[rand(@compliments)]";
  $lines =~ s/$capphrase/$capreplace/g;
  foreach $word (keys %words) {
    $lines =~ s/([\s\W])$word([\s\W])/$1$words{$word}$2/g;
    $capphrase = "\u$word";
    $capreplace = "\u$words{$word}";
    $lines =~ s/([\s\W])$capphrase([\s\W])/$1$capreplace$2/g;
    $capphrase = "\U$word";
    $capreplace = "\U$words{$word}";
    $lines =~ s/([\s\W])$capphrase([\s\W])/$1$capreplace$2/g;
    #print STDERR "word $word $words{$word} cap $capphrase $capreplace\n";
  }
  if ($mode eq "text") {
    foreach $word (keys %http) {
      $lines =~ s/([\s\W])$word([\s\W])/$1$http{$word}$2/g;
      $capphrase = "\u$word";
      $capreplace = "\u$http{$word}";
      $lines =~ s/([\s\W])$capphrase([\s\W])/$1$capreplace$2/g;
      $capphrase = "\U$word";
      $capreplace = "\U$http{$word}";
      $lines =~ s/([\s\W])$capphrase([\s\W])/$1$capreplace$2/g;
      #print STDERR "word $word $http{$word} cap $capphrase $capreplace\n";
    }
  }
  # Replace ver$ with 'er
  $lines =~ s/ven\s/'en /g;
  # Replace ver$ with 'er
  $lines =~ s/ver\s/'er /g;
  # Replace ing$ with in'
  $lines =~ s/ing\s/in' /g;
  $lines =~ s/ing,/in',/g;
  $lines =~ s/ing\./in'./g;
  $lines =~ s/ing\?/in'?/g;
  $lines =~ s/ing!/in'!/g;
  $lines =~ s/ing_/in'_/g;
  if (defined($ENV{"HTTP_USER_AGENT"}) && $mode eq "text") { # command line not web
    $lines = "<font color=\"red\" size=\"-1\">A sea dog says 't this way: </font><br>".$lines;
    $lines =~ s/\n/<br>\n/g;
  }
  # add trailing insult
  if (defined($ENV{"HTTP_USER_AGENT"}) && $mode eq "text") { # command line not web
    $lines .= "<br><font color=\"red\" size=\"-1\">Ya ".$insults[rand(@insults)]."!</font>";
  } else {
    $lines =~ s/<\/head>/<base href="$mode"><\/head>/i;
  }
  return $lines;
} # end translate
# End pirate.pl
