#!/usr/bin/perl
my
${ dt_start } = [ gettimeofday ] ;
END{ $0 =~ s/.*\///;
say
STDERR DARK BOLD ITALIC YELLOW
sprintf
"\t--- %0.6f sec calculation ($0)."
, tv_interval ${ dt_start } } ;
use
Getopt::Std ; getopts
'1cC:f:i:lrs:uv=!^*:@'
, \
my
%o
;
use
Encode
qw[ decode_utf8 encode_utf8 ]
;
eval
'use Text::VisualWidth::UTF8 qw[ width ] ; 1 '
or
die
'Installing Text::VisualWidth::UTF8 is necessary.'
if
$o
{v} ;
no
warnings ;
* charlen =
$o
{v} ? * Text::VisualWidth::UTF8::width :
sub
{
length
$_
[0] } ;
sub
mainproc ;
$| = 1
if
$o
{
'!'
} ;
my
$i
=
do
{
$o
{i} //=
"\t"
;
eval
qq[qq[$o{i}]
] } ;
my
$o
=
defined
$o
{f} ?
do
{
$o
{f} =~ m/^(\d*)(.*)$/ ;
eval
qq[qq[$2]
] } :
$i
;
mainproc ;
exit
0 ;
sub
mainproc {
* preProcN =
$o
{l}//
''
eq
'0'
?
sub
{
chomp
} :
sub
{ } ;
* preProcU =
$o
{u} ?
sub
{
$_
= decode_utf8
$_
} :
sub
{ } ;
* sptr =
defined
$o
{s} ?
$o
{s} eq
'0'
?
sub
{ s/\s//gr } :
sub
{ s/\S//gr } :
sub
{
$_
} ;
* mainTreat =
defined
$o
{l} ?
sub
{ & charlen ( & sptr (
$_
) ) } :
sub
{
chomp
;
map
{ & charlen(
$_
) }
map
{ & sptr }
split
/
$i
/,
$_
,-1 } ;
$o
{C} .=
'1'
if
$o
{c} ;
* colcnt =
defined
$o
{C} ?
$o
{C} eq
'0'
?
sub
{
@_
=
scalar
grep
{
$_
eq
'0'
}
@_
} :
$o
{C} =~/^(0-|-0)$/ ?
sub
{
@_
=
scalar
grep
{
$_
ne
'0'
}
@_
} :
$o
{C} =~ /^0be$/i ?
sub
{
@_
= ( ( 1 + firstidx {
$_
eq
'0'
}
@_
) , (1 + lastidx {
$_
eq
'0'
}
@_
) )} :
$o
{C} =~ /^0[b]$/i ?
sub
{
@_
= 1 + firstidx {
$_
eq
'0'
}
@_
} :
$o
{C} =~ /^0[e]$/i ?
sub
{
@_
= 1 + lastidx {
$_
eq
'0'
}
@_
} :
$o
{C} =~ /^-0be$/i ?
sub
{
@_
= ( ( 1 + firstidx {
$_
ne
'0'
}
@_
) , (1 + lastidx {
$_
ne
'0'
}
@_
) )} :
$o
{C} =~ /^-0[b]$/i ?
sub
{
@_
= 1 + firstidx {
$_
ne
'0'
}
@_
} :
$o
{C} =~ /^-0[e]$/i ?
sub
{
@_
= 1 + lastidx {
$_
ne
'0'
}
@_
} :
sub
{
@_
= (
scalar
@_
) } :
sub
{ } ;
* incOrg =
$o
{1} ?
$o
{u} ?
sub
{
chomp
;
$_
= encode_utf8
$_
;
push
@_
,
"|$_"
} :
sub
{
chomp
;
push
@_
,
"|$_"
} :
sub
{ } ;
* incFNa =
$o
{
'@'
} ?
sub
{
push
@_
,
$ARGV
} :
sub
{ } ;
* fmtwdt =
defined
$o
{f} &&
$o
{f}=~/^(\d+)/ ?
do
{
my
$d
= $1 ;
sub
{
grep
{
$_
=
sprintf
"%$d"
.
'd'
,
$_
;
$_
=
"*"
x
$d
if
length
$_
>
$d
}
@_
} } :
sub
{ } ;
print
do
{
my
$t
= <> }
if
$o
{
'='
} ;
while
( <> ) {
& preProcN ;
& preProcU ;
@_
= & mainTreat ;
& colcnt ;
& incFNa ;
& fmtwdt ;
& incOrg ;
say
join
$o
,
@_
;
say
"^\t$ARGV"
if
eof
&&
$o
{
'^'
} ;
}
} ;
sub
VERSION_MESSAGE {}
sub
HELP_MESSAGE {
$ARGV
[1] //=
''
;
open
my
$FH
,
'<'
, $0 ;
while
(<
$FH
>){
s/\$0/
$Script
/g ;
print
$_
if
s/^=head1// .. s/^=cut// and
$ARGV
[1] =~ /^o(p(t(i(o(ns?)?)?)?)?)?$/i ? m/^\s+\-/ : 1;
}
close
$FH
;
exit
0 ;
}