sub
usage {
print
STDERR
"Usage: slice [options] [file]\n"
;
print
STDERR
" where options are\n"
;
print
STDERR
" -o [sliceterm:]file[\@chmodopt] create output file\n"
;
print
STDERR
" -x verbose/debug mode\n"
;
print
STDERR
" -v version string\n"
;
exit
(1);
}
sub
hello {
print
STDERR
"$Vers::SLICE_Hello\n"
;
exit
(0);
}
sub
setup {
my
(
$CFG
) =
@_
;
$Getopt::Long::bundling
= 1;
$opt_x
= 0;
$opt_v
= 0;
@opt_o
= ();
if
(not Getopt::Long::GetOptions(
"x|debug"
,
"v|version"
,
"o|outputfile=s@"
)) {
&usage
;
}
if
(
$opt_v
) {
&hello
;
}
if
((
$#ARGV
== 0 and
$ARGV
[0] eq
'-'
) or
$#ARGV
== -1) {
$fp
= new IO::Handle;
$fp
->fdopen(
fileno
(STDIN),
"r"
);
local
($/) =
undef
;
$INPUT
= <
$fp
>;
$fp
->
close
;
}
elsif
(
$#ARGV
== 0) {
$fp
= new IO::File;
$fp
->
open
(
$ARGV
[0]);
local
($/) =
undef
;
$INPUT
= <
$fp
>;
$fp
->
close
;
}
else
{
&usage
;
}
while
(
$INPUT
=~ s|^%!slice\s+([^\n]+)\n||im) {
@ARGV
=
split
(/\s+/, $1);
if
(not Getopt::Long::GetOptions(
"x|debug"
,
"v|version"
,
"o|outputfile=s@"
)) {
&usage
;
}
}
if
(
$#opt_o
== -1) {
@opt_o
= (
"ALL:-"
);
}
$CFG
->{INPUT} = {};
$CFG
->{INPUT}->{SRC} =
$INPUT
;
$CFG
->{INPUT}->{PLAIN} =
''
;
$CFG
->{OPT} = {};
$CFG
->{OPT}->{X} =
$opt_x
;
$CFG
->{OPT}->{O} = [
@opt_o
];
$CFG
->{SLICE} = {};
$CFG
->{SLICE}->{SET} = {};
$CFG
->{SLICE}->{SET}->{ASC} = {};
$CFG
->{SLICE}->{SET}->{OBJ} = {};
$CFG
->{SLICE}->{MINLEVELS} = {};
$CFG
->{SLICE}->{MAXLEVEL} = 0;
}
1;