sub
pass3 {
my
(
$CFG
) =
@_
;
my
(
$slice
,
$outfile
,
$chmod
,
$out
);
my
(
$set
,
$cmds
,
$var
);
my
(
$start
,
$min
,
$max
);
my
(
$entry
);
&verbose
(
"\nPass 3: Output generation\n\n"
);
foreach
$entry
(@{
$CFG
->{OPT}->{O}}) {
if
(
$entry
=~ m|^([A-Z0-9~!+u
*n
\-\\^x()@]+):(.+)@(.+)$|) {
(
$slice
,
$outfile
,
$chmod
) = ($1, $2, $3);
}
elsif
(
$entry
=~ m|^([_A-Z0-9~!+u
*n
\-\\^x()@]+):(.+)$|) {
(
$slice
,
$outfile
,
$chmod
) = ($1, $2,
""
);
}
elsif
(
$entry
=~ m|^([^@]+)@(.+)$|) {
(
$slice
,
$outfile
,
$chmod
) = (
"ALL"
, $1, $2);
}
else
{
(
$slice
,
$outfile
,
$chmod
) = (
"ALL"
,
$entry
,
""
);
}
&verbose
(
" file `$outfile': sliceterm='$slice', chmodopts='$chmod'\n"
);
if
(
$outfile
eq
'-'
) {
$out
= new IO::Handle;
$out
->fdopen(
fileno
(STDOUT),
"w"
);
}
else
{
$out
= new IO::File;
$out
->
open
(
">$outfile"
);
}
if
(
length
(
$CFG
->{INPUT}->{PLAIN}) > 0) {
(
$cmds
,
$var
) = SliceTerm::Parse(
$slice
);
if
(
$CFG
->{OPT}->{X}) {
&verbose
(
" calculated Perl 5 set term:\n"
);
&verbose
(
" ----\n"
);
my
$x
=
$cmds
;
$x
=~ s|\n|\n |g;
&verbose
(
" $x"
);
&verbose
(
"----\n"
);
}
eval
"$cmds; \$set = $var"
;
$start
= 0;
while
((
$start
<
$set
->Size()) &&
((
$min
,
$max
) =
$set
->Interval_Scan_inc(
$start
))) {
$out
->
print
(
substr
(
$CFG
->{INPUT}->{PLAIN},
$min
, (
$max
-
$min
+1)));
$start
=
$max
+ 2;
}
}
$out
->
close
;
if
(
$outfile
ne
'-'
and
$chmod
ne
''
and -f
$outfile
) {
system
(
"chmod $chmod $outfile"
);
}
}
}
1;