#!/usr/bin/env perl
my
(
$fix_links
,
$fix_typography
,
$fix_nbsp
,
$remove_nbsp
,
$show_nbsp
,
$fix_footnotes
,
$inplace
,
$help
);
GetOptions (
links
=> \
$fix_links
,
typography
=> \
$fix_typography
,
nbsp
=> \
$fix_nbsp
,
'remove-nbsp'
=> \
$remove_nbsp
,
'show-nbsp'
=> \
$show_nbsp
,
footnotes
=> \
$fix_footnotes
,
inplace
=> \
$inplace
,
help
=> \
$help
,
) or
die
;
if
(
$help
or !
@ARGV
) {
pod2usage(
"Using Text::Amuse::Preprocessor version "
.
$Text::Amuse::Preprocessor::VERSION
.
"\n"
);
exit
;
}
my
(
$infile
,
$outfile
) =
@ARGV
;
die
"$infile is not a file\n"
unless
-f
$infile
;
my
$wd
;
if
(
$inplace
) {
die
"--inplace and a second argument are mutually exclusive"
if
$outfile
;
$wd
= File::Temp->newdir;
$outfile
= File::Spec->catfile(
$wd
,
'out.muse'
);
}
elsif
(!
$outfile
) {
die
"Missing outfile and --inplace was not specified!\n"
;
}
my
$pp
= Text::Amuse::Preprocessor->new(
fix_links
=>
$fix_links
,
fix_nbsp
=>
$fix_nbsp
,
remove_nbsp
=>
$remove_nbsp
,
show_nbsp
=>
$show_nbsp
,
fix_footnotes
=>
$fix_footnotes
,
fix_typography
=>
$fix_typography
,
input
=>
$infile
,
output
=>
$outfile
,
);
if
(
$pp
->process) {
if
(
$inplace
) {
my
$backup
=
$infile
.
'.'
.
time
() .
'~'
;
copy(
$infile
,
$backup
) or
die
"Cannot copy $infile to $backup $!"
;
print
"Saved backup of $infile in $backup\n"
;
move(
$outfile
,
$infile
) or
die
"Cannot move $outfile to $infile $!"
;
}
}
else
{
die
Dumper(
$pp
->error);
}