1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

Use PHP implementation of Cowsay for cowsay rule

Summary:
Ref T7785. Convert the Cowsay Remarkup rule to use a PHP implementation so we don't have to execute an external `cowsay` binary.

I removed some of the default ".cow" files that come with Cowsay because they:

  - include Perl code which we can not interpret; or
  - are primarily in-jokes or standalone visual puns or artwork rather than usable actors on the grand stage of cowsay; or
  - offended my delicate sensibilities.

Users can add new cows to `resources/cows/custom/` if they want to make new cows available.

I have included a majestic original artwork depicting the "Companion Cube" character from //Portal//.

Test Plan: {F802535}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9408, T7785

Differential Revision: https://secure.phabricator.com/D14100
This commit is contained in:
epriestley 2015-09-13 12:27:30 -07:00
parent c02f750267
commit c705c8011e
41 changed files with 1105 additions and 32 deletions

31
externals/cowsay/ChangeLog vendored Normal file
View file

@ -0,0 +1,31 @@
3.03 28 May 1999
- Added cows/tux.cow, as suggested by xmanoel@i.am
- Compatibility with 5.6.0, due to a change in qw().
- Renamed devil.cow to daemon.cow, since I know better. :-)
3.02 04 November 1999
- Fixed boneheaded code placement so that cowsay -l actually works.
3.01 01 November 1999
- Fixed compatibility issues between the Text::Wrap module
that changed between 5.005_02 and 5.005_03.
- Fixed tab expansion issues with Text::Tabs.
3.0 13 April 1999, released 14 August 1999
- Rewritten into Perl 5 and presented to the world.
-- Not present in CVS from here on down --
2.x Date?
- Arbitrary messages.
- Figlet support (-n).
- Line wrap length (-w).
- Multiple pre-set expressions.
- Better arg parsing loop.
- Message from stdin or command line.
1.0 Date?
- SUBJECT is VERB OBJECT
$Id: ChangeLog,v 1.4 2000/05/29 17:55:24 tony Exp $
This file is part of cowsay. (c) 1999-2000 Tony Monroe.

15
externals/cowsay/INSTALL vendored Normal file
View file

@ -0,0 +1,15 @@
=================
Installing cowsay
=================
If you really want to get things installed a nice and pretty way,
sh install.sh
It will ask approximately one question. If you can't answer it,
you need serious help.
If the install goes well, you can start cowing immediately! Just
be sure to read the manual page first...
$Id: INSTALL,v 1.1 1999/08/14 08:03:17 tony Exp $

36
externals/cowsay/LICENSE vendored Normal file
View file

@ -0,0 +1,36 @@
==============
cowsay License
==============
cowsay is distributed under the same licensing terms as Perl: the
Artistic License or the GNU General Public License. If you don't
want to track down these licenses and read them for yourself, use
the parts that I'd prefer:
(0) I wrote it and you didn't.
(1) Give credit where credit is due if you borrow the code for some
other purpose.
(2) If you have any bugfixes or suggestions, please notify me so
that I may incorporate them.
(3) If you try to make money off of cowsay, you suck.
===============
cowsay Legalese
===============
(0) Copyright (c) 1999 Tony Monroe. All rights reserved. All
lefts may or may not be reversed at my discretion.
(1) This software package can be freely redistributed or modified
under the terms described above in the "cowsay License" section
of this file.
(2) cowsay is provided "as is," with no warranties whatsoever,
expressed or implied. If you want some implied warranty about
merchantability and/or fitness for a particular purpose, you will
not find it here, because there is no such thing here.
(3) I hate legalese.

11
externals/cowsay/MANIFEST vendored Normal file
View file

@ -0,0 +1,11 @@
ChangeLog Changes to recent versions.
INSTALL Instructions for installing cowsay.
LICENSE The license for use and redistribution of cowsay.
MANIFEST This file.
README Read this first. Really.
Wrap.pm.diff Diff for Text/Wrap.pm.
cows/* Support files used by cowsay.
cowsay Main cowsay executable.
cowsay.1 Main cowsay manual page.
install.sh cowsay installation script.
pgp_public_key.txt Verify the signature file with this key.

38
externals/cowsay/README vendored Normal file
View file

@ -0,0 +1,38 @@
===========
cowsay 3.03
===========
cowsay is a configurable talking cow, written in Perl. It operates
much as the figlet program does, and it written in the same spirit
of silliness.
cowsay is actually a pretty old program. It has not really been
released before, and I am releasing it in the hope that someone
other than myself will be amused by it.
The first major version of cowsay had one cow and one message
template: $foo is $verb $bar. Not very flexible, but people managed
to do pretty interesting things with it. The second major version
scrapped many of the limitations of the first, by allowing arbitrary
messages, multiple cowfiles, and even support for cows talking in
figlet. The third version was a rewrite of the second into Perl
5, whereupon the code got a lot smaller and more manageable. :-)
If you are using Perl 5.004, you may have problems with Text::Wrap.
(Yeesh, this module changes more than it should...) I've included
a diff for the Text::Wrap (version 97.011701) that is shipped with
5.004_04; the concept is simple enough that even older Perls can
take advantage of this silly little patch; if there is a "sub fill"
in the documentation for the module, copy it to a more useful
section of that file. If not, just take "sub fill" wholesale from
the patch. Oh, and consider upgrading to 5.005_03 or later.
Please. You'll like it, I promise.
To install cowsay, consult the INSTALL file in this directory.
For the terms and conditions of use, consult the LICENSE file in
this directory.
-- Tony Monroe (tony@nog.net)
$Id: README,v 1.3 2000/05/28 06:24:46 tony Exp $

47
externals/cowsay/Wrap.pm.diff vendored Normal file
View file

@ -0,0 +1,47 @@
*** Wrap.pm.in Thu May 22 00:21:42 1997
--- Wrap.pm Fri Nov 12 10:00:15 1999
***************
*** 3,9 ****
require Exporter;
@ISA = (Exporter);
! @EXPORT = qw(wrap);
@EXPORT_OK = qw($columns);
$VERSION = 97.011701;
--- 3,9 ----
require Exporter;
@ISA = (Exporter);
! @EXPORT = qw(wrap fill);
@EXPORT_OK = qw($columns);
$VERSION = 97.011701;
***************
*** 66,71 ****
--- 66,90 ----
print "-----------$r---------\n" if $debug;;
return $r;
+ }
+
+ ## Copied up from below.
+ sub fill
+ {
+ my ($ip, $xp, @raw) = @_;
+ my @para;
+ my $pp;
+
+ for $pp (split(/\n\s+/, join("\n",@raw))) {
+ $pp =~ s/\s+/ /g;
+ my $x = wrap($ip, $xp, $pp);
+ push(@para, $x);
+ }
+
+ # if paragraph_indent is the same as line_indent,
+ # separate paragraphs with blank lines
+
+ return join ($ip eq $xp ? "\n\n" : "\n", @para);
}
1;

10
externals/cowsay/cows/bunny.cow vendored Normal file
View file

@ -0,0 +1,10 @@
##
## A cute little wabbit
##
$the_cow = <<EOC;
$thoughts
$thoughts \\
\\ /\\
( )
.( o ).
EOC

14
externals/cowsay/cows/cower.cow vendored Normal file
View file

@ -0,0 +1,14 @@
##
## A cowering cow
##
$the_cow = <<EOC;
$thoughts
$thoughts
,__, | |
(oo)\\| |___
(__)\\| | )\\_
| |_w | \\
| | || *
Cower....
EOC

24
externals/cowsay/cows/daemon.cow vendored Normal file
View file

@ -0,0 +1,24 @@
##
## 4.4 >> 5.4
##
$the_cow = <<EOC;
$thoughts , ,
$thoughts /( )`
$thoughts \\ \\___ / |
/- _ `-/ '
(/\\/ \\ \\ /\\
/ / | ` \\
O O ) / |
`-^--'`< '
(_.) _ ) /
`.___/` /
`-----' /
<----. __ / __ \\
<----|====O)))==) \\) /====
<----' `--' `.__,' \\
| |
\\ /
______( (_ / \\______
,' ,-----' | \\
`--{__________) \\/
EOC

7
externals/cowsay/cows/default.cow vendored Normal file
View file

@ -0,0 +1,7 @@
$the_cow = <<"EOC";
$thoughts ^__^
$thoughts ($eyes)\\_______
(__)\\ )\\/\\
$tongue ||----w |
|| ||
EOC

View file

@ -0,0 +1,21 @@
##
## A dragon smiting a cow, possible credit to kube@csua.berkeley.edu
##
$the_cow = <<EOC;
$thoughts ^ /^
$thoughts / \\ // \\
$thoughts |\\___/| / \\// .\\
$thoughts /O O \\__ / // | \\ \\ *----*
/ / \\/_/ // | \\ \\ \\ |
\@___\@` \\/_ // | \\ \\ \\/\\ \\
0/0/| \\/_ // | \\ \\ \\ \\
0/0/0/0/| \\/// | \\ \\ | |
0/0/0/0/0/_|_ / ( // | \\ _\\ | /
0/0/0/0/0/0/`/,_ _ _/ ) ; -. | _ _\\.-~ / /
,-} _ *-.|.-~-. .~ ~
\\ \\__/ `/\\ / ~-. _ .-~ /
\\____($eyes) *. } { /
( (--) .----~-.\\ \\-` .~
//__\\\\ \\__ Ack! ///.----..< \\ _ -~
// \\\\ ///-._ _ _ _ _ _ _{^ - - - - ~
EOC

21
externals/cowsay/cows/dragon.cow vendored Normal file
View file

@ -0,0 +1,21 @@
##
## The Whitespace Dragon
##
$the_cow = <<EOC;
$thoughts / \\ //\\
$thoughts |\\___/| / \\// \\\\
/0 0 \\__ / // | \\ \\
/ / \\/_/ // | \\ \\
\@_^_\@'/ \\/_ // | \\ \\
//_^_/ \\/_ // | \\ \\
( //) | \\/// | \\ \\
( / /) _|_ / ) // | \\ _\\
( // /) '/,_ _ _/ ( ; -. | _ _\\.-~ .-~~~^-.
(( / / )) ,-{ _ `-.|.-~-. .~ `.
(( // / )) '/\\ / ~-. _ .-~ .-~^-. \\
(( /// )) `. { } / \\ \\
(( / )) .----~-.\\ \\-' .~ \\ `. \\^-.
///.----..> \\ _ -~ `. ^-` ^-_
///-._ _ _ _ _ _ _}^ - - - - ~ ~-- ,.-~
/.-~
EOC

15
externals/cowsay/cows/elephant.cow vendored Normal file
View file

@ -0,0 +1,15 @@
##
## An elephant out and about
##
$the_cow = <<EOC;
$thoughts /\\ ___ /\\
$thoughts // \\/ \\/ \\\\
(( O O ))
\\\\ / \\ //
\\/ | | \\/
| | | |
| | | |
| o |
| | | |
|m| |m|
EOC

16
externals/cowsay/cows/eyes.cow vendored Normal file
View file

@ -0,0 +1,16 @@
##
## Evil-looking eyes
##
$the_cow = <<EOC;
$thoughts
$thoughts
.::!!!!!!!:.
.!!!!!:. .:!!!!!!!!!!!!
~~~~!!!!!!. .:!!!!!!!!!UWWW\$\$\$
:\$\$NWX!!: .:!!!!!!XUWW\$\$\$\$\$\$\$\$\$P
\$\$\$\$\$##WX!: .<!!!!UW\$\$\$\$" \$\$\$\$\$\$\$\$#
\$\$\$\$\$ \$\$\$UX :!!UW\$\$\$\$\$\$\$\$\$ 4\$\$\$\$\$*
^\$\$\$B \$\$\$\$\\ \$\$\$\$\$\$\$\$\$\$\$\$ d\$\$R"
"*\$bd\$\$\$\$ '*\$\$\$\$\$\$\$\$\$\$\$o+#"
"""" """""""
EOC

15
externals/cowsay/cows/flaming-sheep.cow vendored Normal file
View file

@ -0,0 +1,15 @@
##
## The flaming sheep, contributed by Geordan Rosario (geordan@csua.berkeley.edu)
##
$the_cow = <<EOC;
$thoughts . . .
$thoughts . . . ` ,
$thoughts .; . : .' : : : .
$thoughts i..`: i` i.i.,i i .
$thoughts `,--.|i |i|ii|ii|i:
U${eyes}U\\.'\@\@\@\@\@\@`.||'
\\__/(\@\@\@\@\@\@\@\@\@\@)'
(\@\@\@\@\@\@\@\@)
`YY~~~~YY'
|| ||
EOC

12
externals/cowsay/cows/head-in.cow vendored Normal file
View file

@ -0,0 +1,12 @@
##
## Go stick yer head in a cow.
##
$the_cow = <<EOC;
$thoughts
$thoughts
^__^ /
($eyes)\\_______/ _________
(__)\\ )=( ____|_ \\_____
$tongue ||----w | \\ \\ \\_____ |
|| || || ||
EOC

12
externals/cowsay/cows/kitty.cow vendored Normal file
View file

@ -0,0 +1,12 @@
##
## A kitten of sorts, I think
##
$the_cow = <<EOC;
$thoughts
$thoughts
("`-' '-/") .___..--' ' "`-._
` *_ * ) `-. ( ) .`-.__. `)
(_Y_.) ' ._ ) `._` ; `` -. .-'
_.. `--'_..-_/ /--' _ .' ,4
( i l ),-'' ( l i),' ( ( ! .-'
EOC

12
externals/cowsay/cows/koala.cow vendored Normal file
View file

@ -0,0 +1,12 @@
##
## From the canonical koala collection
##
$the_cow = <<EOC;
$thoughts
$thoughts
___
{~._.~}
( Y )
()~*~()
(_)-(_)
EOC

15
externals/cowsay/cows/meow.cow vendored Normal file
View file

@ -0,0 +1,15 @@
##
## A meowing tiger?
##
$the_cow = <<EOC;
$thoughts
$thoughts , _ ___.--'''`--''//-,-_--_.
\\`"' ` || \\\\ \\ \\\\/ / // / ,-\\\\`,_
/'` \\ \\ || Y | \\|/ / // / - |__ `-,
/\@"\\ ` \\ `\\ | | ||/ // | \\/ \\ `-._`-,_.,
/ _.-. `.-\\,___/\\ _/|_/_\\_\\/|_/ | `-._._)
`-'``/ / | // \\__/\\__ / \\__/ \\
`-' /-\\/ | -| \\__ \\ |-' |
__/\\ / _/ \\/ __,-' ) ,' _|'
(((__/(((_.' ((___..-'((__,'
EOC

14
externals/cowsay/cows/moofasa.cow vendored Normal file
View file

@ -0,0 +1,14 @@
##
## MOOfasa.
##
$the_cow = <<EOC;
$thoughts ____
$thoughts / \\
| ^__^ |
| ($eyes) |______
| (__) | )\\/\\
\\____/|----w |
|| ||
Moofasa
EOC

9
externals/cowsay/cows/moose.cow vendored Normal file
View file

@ -0,0 +1,9 @@
$the_cow = <<EOC;
$thoughts
$thoughts \\_\\_ _/_/
$thoughts \\__/
($eyes)\\_______
(__)\\ )\\/\\
$tongue ||----w |
|| ||
EOC

10
externals/cowsay/cows/mutilated.cow vendored Normal file
View file

@ -0,0 +1,10 @@
##
## A mutilated cow, from aspolito@csua.berkeley.edu
##
$the_cow = <<EOC;
$thoughts \\_______
v__v $thoughts \\ O )
($eyes) ||----w |
(__) || || \\/\\
$tongue
EOC

12
externals/cowsay/cows/satanic.cow vendored Normal file
View file

@ -0,0 +1,12 @@
##
## Satanic cow, source unknown.
##
$the_cow = <<EOC;
$thoughts
$thoughts (__)
(\\/)
/-------\\/
/ | 666 ||
* ||----||
~~ ~~
EOC

13
externals/cowsay/cows/sheep.cow vendored Normal file
View file

@ -0,0 +1,13 @@
##
## The non-flaming sheep.
##
$the_cow = <<EOC
$thoughts
$thoughts
__
U${eyes}U\\.'\@\@\@\@\@\@`.
\\__/(\@\@\@\@\@\@\@\@\@\@)
(\@\@\@\@\@\@\@\@)
`YY~~~~YY'
|| ||
EOC

15
externals/cowsay/cows/skeleton.cow vendored Normal file
View file

@ -0,0 +1,15 @@
##
## This 'Scowleton' brought to you by one of
## {appel,kube,rowe}@csua.berkeley.edu
##
$the_cow = <<EOC;
$thoughts (__)
$thoughts /$eyes|
$thoughts (_"_)*+++++++++*
//I#\\\\\\\\\\\\\\\\I\\
I[I|I|||||I I `
I`I'///'' I I
I I I I
~ ~ ~ ~
Scowleton
EOC

10
externals/cowsay/cows/small.cow vendored Normal file
View file

@ -0,0 +1,10 @@
##
## A small cow, artist unknown
##
$eyes = ".." unless ($eyes);
$the_cow = <<EOC;
$thoughts ,__,
$thoughts ($eyes)____
(__) )\\
$tongue||--|| *
EOC

13
externals/cowsay/cows/squirrel.cow vendored Normal file
View file

@ -0,0 +1,13 @@
$the_cow = <<EOC;
$thoughts
$thoughts
_ _
| \__/| .~ ~.
/$eyes `./ .'
{o__, \ {
/ . . ) \
`-` '-' \ }
.( _( )_.'
'---.~_ _ _|
EOC

19
externals/cowsay/cows/stegosaurus.cow vendored Normal file
View file

@ -0,0 +1,19 @@
##
## A stegosaur with a top hat?
##
$the_cow = <<EOC;
$thoughts . .
$thoughts / `. .' "
$thoughts .---. < > < > .---.
$thoughts | \\ \\ - ~ ~ - / / |
_____ ..-~ ~-..-~
| | \\~~~\\.' `./~~~/
--------- \\__/ \\__/
.' O \\ / / \\ "
(_____, `._.' | } \\/~~~/
`----. / } | / \\__/
`-. | / | / `. ,~~|
~-.__| /_ - ~ ^| /- _ `..-'
| / | / ~-. `-. _ _ _
|_____| |_____| ~ - . _ _ _ _ _>
EOC

10
externals/cowsay/cows/supermilker.cow vendored Normal file
View file

@ -0,0 +1,10 @@
##
## A cow being milked, probably from Lars Smith (lars@csua.berkeley.edu)
##
$the_cow = <<EOC;
$thoughts ^__^
$thoughts ($eyes)\\_______ ________
(__)\\ )\\/\\ |Super |
$tongue ||----W | |Milker|
|| UDDDDDDDDD|______|
EOC

24
externals/cowsay/cows/surgery.cow vendored Normal file
View file

@ -0,0 +1,24 @@
##
## A cow operation, artist unknown
##
$the_cow = <<EOC;
$thoughts \\ /
$thoughts \\/
(__) /\\
($eyes) O O
_\\/_ //
* ( ) //
\\ (\\\\ //
\\( \\\\ )
( \\\\ ) /\\
___[\\______/^^^^^^^\\__/) o-)__
|\\__[=======______//________)__\\
\\|_______________//____________|
||| || //|| |||
||| || @.|| |||
|| \\/ .\\/ ||
. .
'.'.`
COW-OPERATION
EOC

26
externals/cowsay/cows/turkey.cow vendored Normal file
View file

@ -0,0 +1,26 @@
##
## Turkey!
##
$the_cow = <<EOC;
$thoughts ,+*^^*+___+++_
$thoughts ,*^^^^ )
$thoughts _+* ^**+_
$thoughts +^ _ _++*+_+++_, )
_+^^*+_ ( ,+*^ ^ \\+_ )
{ ) ( ,( ,_+--+--, ^) ^\\
{ (\@) } f ,( ,+-^ __*_*_ ^^\\_ ^\\ )
{:;-/ (_+*-+^^^^^+*+*<_ _++_)_ ) ) /
( / ( ( ,___ ^*+_+* ) < < \\
U _/ ) *--< ) ^\\-----++__) ) ) )
( ) _(^)^^)) ) )\\^^^^^))^*+/ / /
( / (_))_^)) ) ) ))^^^^^))^^^)__/ +^^
( ,/ (^))^)) ) ) ))^^^^^^^))^^) _)
*+__+* (_))^) ) ) ))^^^^^^))^^^^^)____*^
\\ \\_)^)_)) ))^^^^^^^^^^))^^^^)
(_ ^\\__^^^^^^^^^^^^))^^^^^^^)
^\\___ ^\\__^^^^^^))^^^^^^^^)\\\\
^^^^^\\uuu/^^\\uuu/^^^^\\^\\^\\^\\^\\^\\^\\^\\
___) >____) >___ ^\\_\\_\\_\\_\\_\\_\\)
^^^//\\\\_^^//\\\\_^ ^(\\_\\_\\_\\)
^^^ ^^ ^^^ ^
EOC

20
externals/cowsay/cows/turtle.cow vendored Normal file
View file

@ -0,0 +1,20 @@
##
## A mysterious turtle...
##
$the_cow = <<EOC;
$thoughts ___-------___
$thoughts _-~~ ~~-_
$thoughts _-~ /~-_
/^\\__/^\\ /~ \\ / \\
/| O|| O| / \\_______________/ \\
| |___||__| / / \\ \\
| \\ / / \\ \\
| (_______) /______/ \\_________ \\
| / / \\ / \\
\\ \\^\\\\ \\ / \\ /
\\ || \\______________/ _-_ //\\__//
\\ ||------_-~~-_ ------------- \\ --/~ ~\\ || __/
~-----||====/~ |==================| |/~~~~~
(_(__/ ./ / \\_\\ \\.
(_(___/ \\_____)_)
EOC

16
externals/cowsay/cows/tux.cow vendored Normal file
View file

@ -0,0 +1,16 @@
##
## TuX
## (c) pborys@p-soft.silesia.linux.org.pl
##
$the_cow = <<EOC;
$thoughts
$thoughts
.--.
|o_o |
|:_/ |
// \\ \\
(| | )
/'\\_ _/`\\
\\___)=(___/
EOC

10
externals/cowsay/cows/www.cow vendored Normal file
View file

@ -0,0 +1,10 @@
##
## A cow wadvertising the World Wide Web, from lim@csua.berkeley.edu
##
$the_cow = <<EOC;
$thoughts ^__^
$thoughts ($eyes)\\_______
(__)\\ )\\/\\
$tongue ||--WWW |
|| ||
EOC

187
externals/cowsay/cowsay vendored Executable file
View file

@ -0,0 +1,187 @@
#%BANGPERL%
##
## Cowsay 3.03
##
## This file is part of cowsay. (c) 1999-2000 Tony Monroe.
##
use Text::Tabs qw(expand);
use Text::Wrap qw(wrap fill $columns);
use File::Basename;
use Getopt::Std;
use Cwd;
$version = "3.03";
$progname = basename($0);
$eyes = "oo";
$tongue = " ";
$cowpath = $ENV{'COWPATH'} || '%PREFIX%/share/cows';
@message = ();
$thoughts = "";
## Yeah, this is rude, I know. But hopefully it gets around a nasty
## little version dependency.
$Text::Wrap::initial_tab = 8;
$Text::Wrap::subsequent_tab = 8;
$Text::Wrap::tabstop = 8;
## One of these days, we'll get it ported to Windows. Yeah, right.
if (($^O eq "MSWin32") or ($^O eq "Windows_NT")) { ## Many perls, eek!
$pathsep = ';';
} else {
$pathsep = ':';
}
%opts = (
'e' => 'oo',
'f' => 'default.cow',
'n' => 0,
'T' => ' ',
'W' => 40,
);
getopts('bde:f:ghlLnNpstT:wW:y', \%opts);
&display_usage if $opts{'h'};
&list_cowfiles if $opts{'l'};
$borg = $opts{'b'};
$dead = $opts{'d'};
$greedy = $opts{'g'};
$paranoid = $opts{'p'};
$stoned = $opts{'s'};
$tired = $opts{'t'};
$wired = $opts{'w'};
$young = $opts{'y'};
$eyes = substr($opts{'e'}, 0, 2);
$tongue = substr($opts{'T'}, 0, 2);
$the_cow = "";
&slurp_input;
$Text::Wrap::columns = $opts{'W'};
@message = ($opts{'n'} ? expand(@message) :
split("\n", fill("", "", @message)));
&construct_balloon;
&construct_face;
&get_cow;
print @balloon_lines;
print $the_cow;
sub list_cowfiles {
my $basedir;
my @dirfiles;
chop($basedir = cwd);
for my $d (split(/$pathsep/, $cowpath)) {
print "Cow files in $d:\n";
opendir(COWDIR, $d) || die "$0: Cannot open $d\n";
for my $file (readdir COWDIR) {
if ($file =~ s/\.cow$//) {
push(@dirfiles, $file);
}
}
closedir(COWDIR);
print wrap("", "", sort @dirfiles), "\n";
@dirfiles = ();
chdir($basedir);
}
exit(0);
}
sub slurp_input {
unless ($ARGV[0]) {
chomp(@message = <STDIN>);
} else {
&display_usage if $opts{'n'};
@message = join(' ', @ARGV);
}
}
sub maxlength {
my ($l, $m);
$m = -1;
for my $i (@_) {
$l = length $i;
$m = $l if ($l > $m);
}
return $m;
}
sub construct_balloon {
my $max = &maxlength(@message);
my $max2 = $max + 2; ## border space fudge.
my $format = "%s %-${max}s %s\n";
my @border; ## up-left, up-right, down-left, down-right, left, right
if ($0 =~ /think/i) {
$thoughts = 'o';
@border = qw[ ( ) ( ) ( ) ];
} elsif (@message < 2) {
$thoughts = '\\';
@border = qw[ < > ];
} else {
$thoughts = '\\';
if ($V and $V gt v5.6.0) { # Thanks, perldelta.
@border = qw[ / \\ \\ / | | ];
} else {
@border = qw[ / \ \ / | | ];
}
}
push(@balloon_lines,
" " . ("_" x $max2) . " \n" ,
sprintf($format, $border[0], $message[0], $border[1]),
(@message < 2 ? "" :
map { sprintf($format, $border[4], $_, $border[5]) }
@message[1 .. $#message - 1]),
(@message < 2 ? "" :
sprintf($format, $border[2], $message[$#message], $border[3])),
" " . ("-" x $max2) . " \n"
);
}
sub construct_face {
if ($borg) { $eyes = "=="; }
if ($dead) { $eyes = "xx"; $tongue = "U "; }
if ($greedy) { $eyes = "\$\$"; }
if ($paranoid) { $eyes = "@@"; }
if ($stoned) { $eyes = "**"; $tongue = "U "; }
if ($tired) { $eyes = "--"; }
if ($wired) { $eyes = "OO"; }
if ($young) { $eyes = ".."; }
}
sub get_cow {
##
## Get a cow from the specified cowfile; otherwise use the default cow
## which was defined above in $the_cow.
##
my $f = $opts{'f'};
my $full = "";
if ($opts{'f'} =~ m,/,) {
$full = $opts{'f'};
} else {
for my $d (split(/:/, $cowpath)) {
if (-f "$d/$f") {
$full = "$d/$f";
last;
} elsif (-f "$d/$f.cow") {
$full = "$d/$f.cow";
last;
}
}
if ($full eq "") {
die "$progname: Could not find $f cowfile!\n";
}
}
do $full;
die "$progname: $@\n" if $@;
}
sub display_usage {
die <<EOF;
cow{say,think} version $version, (c) 1999 Tony Monroe
Usage: $progname [-bdgpstwy] [-h] [-e eyes] [-f cowfile]
[-l] [-n] [-T tongue] [-W wrapcolumn] [message]
EOF
}

168
externals/cowsay/cowsay.1 vendored Normal file
View file

@ -0,0 +1,168 @@
.\"
.\" cowsay.1
.\"
.\" $Id: cowsay.1,v 1.4 1999/11/04 19:50:40 tony Exp $
.\"
.\" This file is part of cowsay. (c) 1999 Tony Monroe.
.\"
.ds Nm Cowsay
.ds nm cowsay
.ds Vn 3.02
.TH \*(nm 1 "$Date: 1999/11/04 19:50:40 $"
.SH NAME
\*(nm/cowthink \- configurable speaking/thinking cow (and a bit more)
.SH SYNOPSIS
cowsay
.RB [ \-e
.IR eye_string ]
.RB [ \-f
.IR cowfile ]
.RB [ \-h ]
.RB [ \-l ]
.RB [ \-n ]
.RB [ \-T
.IR tongue_string ]
.RB [ \-W
.IR column ]
.RB [ \-bdgpstwy ]
.SH DESCRIPTION
.I Cowsay
generates an ASCII picture of a cow saying something provided by the
user. If run with no arguments, it accepts standard input, word-wraps
the message given at about 40 columns, and prints the cow saying the
given message on standard output.
.PP
To aid in the use of arbitrary messages with arbitrary whitespace,
use the
.B \-n
option. If it is specified, the given message will not be
word-wrapped. This is possibly useful if you want to make the cow
think or speak in figlet(6). If
.B \-n
is specified, there must not be any command-line arguments left
after all the switches have been processed.
.PP
The
.B \-W
specifies roughly (where the message should be wrapped. The default
is equivalent to
.B \-W 40
i.e. wrap words at or before the 40th column.
.PP
If any command-line arguments are left over after all switches have
been processed, they become the cow's message. The program will not
accept standard input for a message in this case.
.PP
There are several provided modes which change the appearance of the
cow depending on its particular emotional/physical state. The
.B \-b
option initiates Borg mode;
.B \-d
causes the cow to appear dead;
.B \-g
invokes greedy mode;
.B \-p
causes a state of paranoia to come over the cow;
.B \-s
makes the cow appear thoroughly stoned;
.B \-t
yields a tired cow;
.B \-w
is somewhat the opposite of
.BR \-t ,
and initiates wired mode;
.B \-y
brings on the cow's youthful appearance.
.PP
The user may specify the
.B \-e
option to select the appearance of the cow's eyes, in which case
the first two characters of the argument string
.I eye_string
will be used. The default eyes are 'oo'. The tongue is similarly
configurable through
.B \-T
and
.IR tongue_string ;
it must be two characters and does not appear by default. However,
it does appear in the 'dead' and 'stoned' modes. Any configuration
done by
.B \-e
and
.B \-T
will be lost if one of the provided modes is used.
.PP
The
.B \-f
option specifies a particular cow picture file (``cowfile'') to
use. If the cowfile spec contains '/' then it will be interpreted
as a path relative to the current directory. Otherwise, cowsay
will search the path specified in the
.B COWPATH
environment variable.
To list all cowfiles on the current
.BR COWPATH ,
invoke
.B \*(nm
with the
.B \-l
switch.
.PP
If the program is invoked as
.B cowthink
then the cow will think its message instead of saying it.
.PP
.SH COWFILE FORMAT
A cowfile is made up of a simple block of
.BR perl (1)
code, which assigns a picture of a cow to the variable
.BR $the_cow .
Should you wish to customize the eyes or the tongue of the cow,
then the variables
.B $eyes
and
.B $tongue
may be used. The trail leading up to the cow's message balloon is
composed of the character(s) in the
.B $thoughts
variable. Any backslashes must be reduplicated to prevent
interpolation. The name of a cowfile should end with
.BR .cow ,
otherwise it is assumed not to be a cowfile. Also, at-signs (``@'')
must be backslashed because that is what Perl 5 expects.
.PP
.SH COMPATIBILITY WITH OLDER VERSIONS
.PP
What older versions? :-)
.PP
Version 3.x is fully backward-compatible with 2.x versions. If
you're still using a 1.x version, consider upgrading. And tell me
where you got the older versions, since I didn't exactly put them
up for world-wide access.
.PP
Oh, just so you know, this manual page documents version \*(Vn of
cowsay.
.SH ENVIRONMENT
The COWPATH environment variable, if present, will be used to search
for cowfiles. It contains a colon-separated list of directories,
much like
.B PATH or
.BR MANPATH .
It should always contain the
.B /usr/local/share/cows
directory, or at least a directory with a file called
.B default.cow
in it.
.SH FILES
.B %PREFIX%/share/cows
holds a sample set of cowfiles. If your
.B COWPATH
is not explicitly set, it automatically contains this directory.
.SH BUGS
If there are any, please notify the author at the address below.
.SH AUTHOR
Tony Monroe (tony@nog.net), with suggestions from Shannon
Appel (appel@CSUA.Berkeley.EDU) and contributions from Anthony Polito
(aspolito@CSUA.Berkeley.EDU).
.SH SEE ALSO
perl(1), wall(1), nwrite(1), figlet(6)

92
externals/cowsay/install.sh vendored Executable file
View file

@ -0,0 +1,92 @@
#!/bin/sh
##
## install.sh
##
## Installation script for cowsay.
##
## $Id: install.sh,v 1.5 1999/11/01 20:19:21 tony Exp $
##
## This file is part of cowsay. (c) 1999 Tony Monroe.
##
rcs_id='$Id: install.sh,v 1.5 1999/11/01 20:19:21 tony Exp $'
filelist='cows'
cat <<DOG
===================
cowsay Installation
===================
Searching for useful perl executables...
DOG
backdoor=$1
pathdirs=`echo $PATH | tr : " "`
for p in $pathdirs; do
set $p/perl $p/perl5*
while [ ! -z "$1" ]; do
if [ -x "$1" ]; then
echo Found perl in $1
perls="$perls $1"
fi
shift
done
done
for perl in $perls; do
if $perl -MText::Wrap -e0 >/dev/null 2>&1; then
echo Found a good perl in $perl
goodperls="$goodperls $perl"
fi
done
echo The following perl executables will run cowsay:
echo $goodperls
echo I recommend the latest stable perl you can find.
set $goodperls
if [ -z "$1" ]; then
echo Ack! You do not have Perl 5 installed correctly!
echo Get thee to CPAN!
exit 1
fi
usethisperl=$1
echo I will be using $1 because I know it will work.
echo Now I need an installation prefix. I will use /usr/local unless
printf "you give me a better idea here: "
if [ -n "$backdoor" ]; then
prefix=$backdoor
printf "%s (specified on command line)\n" $prefix
else
read prefix
fi
PREFIX=${prefix:-/usr/local}
echo Okay, time to install this puppy.
echo s,%BANGPERL%,!$usethisperl,\; > install.pl
echo s,%PREFIX%,$PREFIX,\; >> install.pl
set -x
mkdir -p $PREFIX/bin || (mkdir $PREFIX; mkdir $PREFIX/bin)
$usethisperl -p install.pl cowsay > $PREFIX/bin/cowsay
chmod a+x $PREFIX/bin/cowsay
ln -s cowsay $PREFIX/bin/cowthink
mkdir -p $PREFIX/man/man1 || ($mkdir $PREFIX; mkdir $PREFIX/man; mkdir $PREFIX/man/man1)
$usethisperl -p install.pl cowsay.1 > $PREFIX/man/man1/cowsay.1
chmod a+r $PREFIX/man/man1/cowsay.1
ln -s cowsay.1 $PREFIX/man/man1/cowthink.1
mkdir -p $PREFIX/share/cows || (mkdir $PREFIX; mkdir $PREFIX/share; mkdir $PREFIX/share/cows)
tar -cf - $filelist | (cd $PREFIX/share && tar -xvf -)
set +x
echo Okay, let us see if the install actually worked.
if [ ! -f $PREFIX/share/cows/default.cow ]; then
echo The default cow file did not make it across!
echo Ooops, it failed...sorry!
exit 1
fi
echo Installation complete! Enjoy the cows!

14
externals/cowsay/pgp_public_key.txt vendored Normal file
View file

@ -0,0 +1,14 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2
mQCNAzNS+H4AAAEEAMilCcxLMIqMNXhZoeHjbeJGnHoKP0JpKDejz66qBlDwP+du
FvVBHkyNIuU3orKe7l/aXIR8TcpjrxdcmrjjzwuB1aV48V4swT7v9UXvv9YP41Pd
1pXYXNelXHmE0eKSfcnkkFmYTJBXPaPNTJ3rpZpZOEW3SfgrrheqQm6w/6IJAAUR
tBpUb255IE1vbnJvZSA8dG9ueUBub2cubmV0PrQdVG9ueSBNb25yb2UgPHRtb25y
b2VAbm9nLm5ldD6JAJUDBRA2bDA5F6pCbrD/ogkBASOZA/9XtYSpcPjpi62MTEZl
l+wV1svtlUlPvKkDE7FB9bwnMbF1FgGhTe/H4/8qDu20m5eGxMX58Ri7HPXWjjJ/
CrUWMzGVbg1JBkgh+d9QvEywmR0j4WezaifW1nCbxk0GrW1PjJyGb3kx7vrIF1Km
xt6VwxTgfJzjIioBJFb4EiDyaLQnVG9ueSBNb25yb2UgPHRtb25yb2VAQ1NVQS5C
ZXJrZWxleS5FRFU+
=WpM4
-----END PGP PUBLIC KEY BLOCK-----

View file

@ -0,0 +1,9 @@
$thoughts
$thoughts
/---\__/---\\
| / .... \ ||
\ ..--.. //
|..($eyes). ||
/ ..--.. \\
| \ .... / ||
\---/--\---//

View file

@ -0,0 +1,2 @@
You can add custom ".cow" files here to make them available to the "cowsay"
interpreter in Remarkup.

View file

@ -8,45 +8,28 @@ final class PhabricatorRemarkupCowsayBlockInterpreter
} }
public function markupContent($content, array $argv) { public function markupContent($content, array $argv) {
if (!Filesystem::binaryExists('cowsay')) { $action = idx($argv, 'think') ? 'think' : 'say';
return $this->markupError(
pht(
'Unable to locate the `%s` binary. Install cowsay.',
'cowsay'));
}
$bin = idx($argv, 'think') ? 'cowthink' : 'cowsay';
$eyes = idx($argv, 'eyes', 'oo'); $eyes = idx($argv, 'eyes', 'oo');
$tongue = idx($argv, 'tongue', ' '); $tongue = idx($argv, 'tongue', ' ');
$cow = idx($argv, 'cow', 'default');
// NOTE: Strip this aggressively to prevent nonsense like $map = self::getCowMap();
// `cow=/etc/passwd`. We could build a whiltelist with `cowsay -l`.
$cow = preg_replace('/[^a-z.-]+/', '', $cow);
$future = new ExecFuture( $cow = idx($argv, 'cow');
'%s -e %s -T %s -f %s ', $cow = phutil_utf8_strtolower($cow);
$bin, if (empty($map[$cow])) {
$eyes, $cow = 'default';
$tongue,
$cow);
$future->setTimeout(15);
$future->write($content);
list($err, $stdout, $stderr) = $future->resolve();
if ($err) {
return $this->markupError(
pht(
'Execution of `%s` failed: %s',
'cowsay',
$stderr));
} }
$result = id(new PhutilCowsay())
->setTemplate($map[$cow])
->setAction($action)
->setEyes($eyes)
->setTongue($tongue)
->setText($content)
->renderCow();
if ($this->getEngine()->isTextMode()) { if ($this->getEngine()->isTextMode()) {
return $stdout; return $result;
} }
return phutil_tag( return phutil_tag(
@ -54,7 +37,32 @@ final class PhabricatorRemarkupCowsayBlockInterpreter
array( array(
'class' => 'PhabricatorMonospaced remarkup-cowsay', 'class' => 'PhabricatorMonospaced remarkup-cowsay',
), ),
$stdout); $result);
}
private static function getCowMap() {
$root = dirname(phutil_get_library_root('phabricator'));
$directories = array(
$root.'/externals/cowsay/cows/',
$root.'/resources/cows/builtin/',
$root.'/resources/cows/custom/',
);
$map = array();
foreach ($directories as $directory) {
foreach (Filesystem::listDirectory($directory, false) as $cow_file) {
$matches = null;
if (!preg_match('/^(.*)\.cow\z/', $cow_file, $matches)) {
continue;
}
$cow_name = $matches[1];
$cow_name = phutil_utf8_strtolower($cow_name);
$map[$cow_name] = Filesystem::readFile($directory.$cow_file);
}
}
return $map;
} }
} }