The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/local/bin/perl -wT

#
# $Id: cat.abigail,v 1.1 2004/07/23 20:10:01 cwest Exp $
#
# $Log: cat.abigail,v $
# Revision 1.1  2004/07/23 20:10:01  cwest
# initial import
#
# Revision 1.1  1999/02/26 03:21:14  abigail
# Initial revision
#
#

use strict;
use Getopt::Std;

my ($VERSION) = '$Revision: 1.1 $' =~ /([.\d]+)/;

# Get the options.

# Print a usuage message on a unknown option.
# Requires my patch to Getopt::Std of 25 Feb 1999.
$SIG {__WARN__} = sub {
    if (substr ($_ [0], 0, 14) eq "Unknown option") {
        $0 =~ s{.*/}{};
        print <<EOF;
$0 (Perl bin utils) $VERSION
$0 [-benstuv] [files ...]
EOF
        exit;
    }
};

getopts ('benstuv?', \my %options);

$SIG {__WARN__} = 'DEFAULT';

my ($tabs, $ends, $nonprinting);

if (exists $options {e}) {$ends = $nonprinting = 1;}
if (exists $options {t}) {$tabs = $nonprinting = 1;}
if (exists $options {v}) {        $nonprinting = 1;}

my $squeeze_empty     = exists $options {s};
my $number_lines      = exists $options {n};
my $number_non_blanks = exists $options {b};

# Unbuffer output for -u.

$| = exists $options {u};

my $was_empty = 0;
my $count     = 0;

while (<>) {

    if ($squeeze_empty) {
        my $is_empty = /^$/;
        if ($is_empty && $was_empty) {
            next;
        }
        $was_empty = $is_empty;
    }

    $_ = sprintf "%6d  $_", ++ $count if $number_lines ||
                                         $number_non_blanks && /\S/;

    $_ =~ s/$/\$/   if $ends;
    if ($nonprinting) {
        $_ =~ s/([\x80-\xFF])/"M-" . ("\x7F" & $1)/ge;
        $_ =~ s/([\x00-\x08\x0B-\x1F])/"^" . chr (0100 + ord $1)/ge;
        $_ =~ s/\x7F/^?/g;
    }
    if ($tabs) {
        $_ =~ s/\x09/^I/g;
    }

    print;
}

__END__

=pod

=head1 NAME

cat -- concatenate and print files.

=head1 SYNOPSIS

cat [-benstuv] [file ...]

=head1 DESCRIPTION

I<cat> reads and prints the files in order they are given. If no files
are given, I<standard input> is processed. A lone dash represents 
I<standard input> as well.

=head2 OPTIONS

I<cat> accepts the following options:

=over 4

=item -b

Number all the non blank lines, starting at 1.

=item -e

Print a dollar sign (B<$>) at the end of each lines. Implies I<-v>.

=item -n

Number all the lines, starting at 1.

=item -s

The I<squeeze> option. Sequential empty lines are squeezed into a 
single empty line.

=item -t

Display tabs as I<^I>. Implies I<-v>.

=item -u

Unbuffer output.

=item -v

Display non-printable characters in a printable way. Characters in the
range I<\000> - I<\037>, with the exception of tabs and linefeeds, are
printed as I<^X>, where I<X> is the symbol I<\0100> higher. I<DEL> is
printed as I<^?>. Characters whose highest bit is set are printed as
I<M->, followed by the representation of the character with the high
bit stripped.

=back

=head1 ENVIRONMENT

The working of I<cat> is not influenced by any environment variables.

=head1 BUGS

I<cat> has no known bugs.

=head1 STANDARDS

This I<cat> implementation is compliant with the B<IEEE Std1003.2-1992>
specification, also known as B<POSIX.2>.

This I<cat> implementation is compatible with the B<OpenBSD> implementation.

=head1 REVISION HISTORY

    $Log: cat.abigail,v $
    Revision 1.1  2004/07/23 20:10:01  cwest
    initial import

    Revision 1.1  1999/02/26 03:21:14  abigail
    Initial revision

=head1 AUTHOR

The Perl implementation of I<cat> was written by Abigail, I<abigail@fnx.com>.

=head1 COPYRIGHT and LICENSE

This program is copyright by Abigail 1999.

This program is free and open software. You may use, copy, modify, distribute
and sell this program (and any modified variants) in any way you wish,
provided you do not restrict others to do the same.

=cut