6 ## This file is part of cowsay. (c) 1999-2000 Tony Monroe.
9 use Text::Tabs qw(expand);
10 use Text::Wrap qw(wrap fill $columns);
16 $progname = basename($0);
19 $cowpath = $ENV{'COWPATH'} || '%PREFIX%/share/cows';
23 ## Yeah, this is rude, I know. But hopefully it gets around a nasty
24 ## little version dependency.
26 $Text::Wrap::initial_tab = 8;
27 $Text::Wrap::subsequent_tab = 8;
28 $Text::Wrap::tabstop = 8;
30 ## One of these days, we'll get it ported to Windows. Yeah, right.
32 if (($^O eq "MSWin32") or ($^O eq "Windows_NT")) { ## Many perls, eek!
46 getopts('bde:f:ghlLnNpstT:wW:y', \%opts);
48 &display_usage if $opts{'h'};
49 &list_cowfiles if $opts{'l'};
54 $paranoid = $opts{'p'};
59 $eyes = substr($opts{'e'}, 0, 2);
60 $tongue = substr($opts{'T'}, 0, 2);
64 $Text::Wrap::columns = $opts{'W'};
65 @message = ($opts{'n'} ? expand(@message) :
66 split("\n", fill("", "", @message)));
77 for my $d (split(/$pathsep/, $cowpath)) {
78 print "Cow files in $d:\n";
79 opendir(COWDIR, $d) || die "$0: Cannot open $d\n";
80 for my $file (readdir COWDIR) {
81 if ($file =~ s/\.cow$//) {
82 push(@dirfiles, $file);
86 print wrap("", "", sort @dirfiles), "\n";
95 chomp(@message = <STDIN>);
97 &display_usage if $opts{'n'};
98 @message = join(' ', @ARGV);
107 $m = $l if ($l > $m);
112 sub construct_balloon {
113 my $max = &maxlength(@message);
114 my $max2 = $max + 2; ## border space fudge.
115 my $format = "%s %-${max}s %s\n";
116 my @border; ## up-left, up-right, down-left, down-right, left, right
117 if ($0 =~ /think/i) {
119 @border = qw[ ( ) ( ) ( ) ];
120 } elsif (@message < 2) {
125 if ($V and $V gt v5.6.0) { # Thanks, perldelta.
126 @border = qw[ / \\ \\ / | | ];
128 @border = qw[ / \ \ / | | ];
132 " " . ("_" x $max2) . " \n" ,
133 sprintf($format, $border[0], $message[0], $border[1]),
135 map { sprintf($format, $border[4], $_, $border[5]) }
136 @message[1 .. $#message - 1]),
138 sprintf($format, $border[2], $message[$#message], $border[3])),
139 " " . ("-" x $max2) . " \n"
144 if ($borg) { $eyes = "=="; }
145 if ($dead) { $eyes = "xx"; $tongue = "U "; }
146 if ($greedy) { $eyes = "\$\$"; }
147 if ($paranoid) { $eyes = "@@"; }
148 if ($stoned) { $eyes = "**"; $tongue = "U "; }
149 if ($tired) { $eyes = "--"; }
150 if ($wired) { $eyes = "OO"; }
151 if ($young) { $eyes = ".."; }
156 ## Get a cow from the specified cowfile; otherwise use the default cow
157 ## which was defined above in $the_cow.
161 if ($opts{'f'} =~ m,/,) {
164 for my $d (split(/:/, $cowpath)) {
168 } elsif (-f "$d/$f.cow") {
174 die "$progname: Could not find $f cowfile!\n";
178 die "$progname: $@\n" if $@;
183 cow{say,think} version $version, (c) 1999 Tony Monroe
184 Usage: $progname [-bdgpstwy] [-h] [-e eyes] [-f cowfile]
185 [-l] [-n] [-T tongue] [-W wrapcolumn] [message]