#!/usr/bin/perl
use strict;
use Getopt::Std;
my %opts;
getopts 'aAbeEnstTuv', \%opts; # 'u' is ignored
my $showline = $opts{b} || $opts{n};
my $reline = $opts{b
}? qr/^(?=.)/m: qr/^/m; my $quotectrl = $opts{v} || $opts{e} || $opts{t} || $opts{A};
my $quotetab = $opts{t} || $opts{T} || $opts{A};
my $showeol = $opts{e} || $opts{E} || $opts{A};
my $singlespace = $opts{s};
while (<>) {
s/\n\n+/\n\n/g if $singlespace;
if ($showline) {
my $n = 0;
s/$reline/sprintf '%6d ', ++$n/ge;
}
s/$/\$/mg if $showeol;
s/\t/^I/g if $quotetab;
# skip \11 (tab) and \12 (newline)
s/[\0-\10\13-\37\177]/sprintf '^%c', (ord($&)+64)&0177/ge if $quotectrl;
}
IyEvdXNyL2Jpbi9wZXJsCnVzZSBzdHJpY3Q7CnVzZSBHZXRvcHQ6OlN0ZDsKCm15ICVvcHRzOwpnZXRvcHRzICdhQWJlRW5zdFR1dicsIFwlb3B0czsgICMgJ3UnIGlzIGlnbm9yZWQKCm15ICRzaG93bGluZSA9ICRvcHRze2J9IHx8ICRvcHRze259OwpteSAkcmVsaW5lID0gJG9wdHN7Yn0/IHFyL14oPz0uKS9tOiBxci9eL207Cm15ICRxdW90ZWN0cmwgPSAkb3B0c3t2fSB8fCAkb3B0c3tlfSB8fCAkb3B0c3t0fSB8fCAkb3B0c3tBfTsKbXkgJHF1b3RldGFiID0gJG9wdHN7dH0gfHwgJG9wdHN7VH0gfHwgJG9wdHN7QX07Cm15ICRzaG93ZW9sID0gJG9wdHN7ZX0gfHwgJG9wdHN7RX0gfHwgJG9wdHN7QX07Cm15ICRzaW5nbGVzcGFjZSA9ICRvcHRze3N9OwoKdW5kZWYgJC87Cgp3aGlsZSAoPD4pIHsKICAgIHMvXG5cbisvXG5cbi9nIGlmICRzaW5nbGVzcGFjZTsKICAgIGlmICgkc2hvd2xpbmUpIHsKICAgICAgICBteSAkbiA9IDA7CiAgICAgICAgcy8kcmVsaW5lL3NwcmludGYgJyU2ZCAnLCArKyRuL2dlOwogICAgfQogICAgcy8kL1wkL21nIGlmICRzaG93ZW9sOwogICAgcy9cdC9eSS9nIGlmICRxdW90ZXRhYjsKICAgICMgc2tpcCBcMTEgKHRhYikgYW5kIFwxMiAobmV3bGluZSkKICAgIHMvW1wwLVwxMFwxMy1cMzdcMTc3XS9zcHJpbnRmICdeJWMnLCAob3JkKCQmKSs2NCkmMDE3Ny9nZSBpZiAkcXVvdGVjdHJsOwogICAgcHJpbnQ7Cn0K