Skip to content

Commit

Permalink
Merge pull request #369 from mknos/pig-sync
Browse files Browse the repository at this point in the history
pig: NetBSD compat
  • Loading branch information
briandfoy authored Dec 7, 2023
2 parents 3cce6f8 + a9de472 commit 7bda5d0
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions bin/pig
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,26 @@ License: perl

# pig - eformatray inputway asway Igpay Atinlay
use strict;

use File::Basename qw(basename);
use Getopt::Std qw(getopts);

use constant EX_SUCCESS => 0;
use constant EX_FAILURE => 1;

$|++;

my $VERSION = '1.0';
my $Program = basename($0);

END {
close STDOUT || die "$0: can't close stdout: $!\n";
$? = 1 if $? == 255; # from die
sub version {
warn "$Program (Erlpay Owerpay Oolstay) $VERSION\n";
exit EX_SUCCESS;
}

sub help {
print "$0\n";
exit 0;
}

sub version { print "$0 (Erlpay Owerpay Oolstay) $VERSION\n"; exit 0; }

# options
while (@ARGV && $ARGV[0] =~ /^[-+]/) {
local $_ = shift;
/^-[h?]$/ && help(); # terminates
/^-v$/ && version(); # terminates
die "$0: invalid option -- $_\n";
warn "usage: $Program [-v]\n";
exit EX_FAILURE;
}

# Dr. Bronner's top secret pig-latin algorithm!
Expand All @@ -51,18 +49,25 @@ sub igpay {
else {
/([^aieou]+)(.*)/i;
$ordway = ($2 || '') . lcfirst $1 . 'ay';
$ordway = ucfirst $ordway if $initcaps;
$ordway = uc $ordway if $allcaps;
if ($allcaps) {
$ordway = uc $ordway;
} elsif ($initcaps) {
$ordway = ucfirst $ordway;
}
}
return $ordway;
}

my %opt;
getopts('v', \%opt) or help();
version() if $opt{'v'};
@ARGV = (); # stdin only

while (<>) {
s/([A-Z]+)/igpay($1)/gexi;
print;
}

exit 0;
exit EX_SUCCESS;

__END__
Expand Down

0 comments on commit 7bda5d0

Please sign in to comment.