Skip to content

Commit

Permalink
use File::Spec and File::Basename for platform-independent manipulati…
Browse files Browse the repository at this point in the history
…on of files and directories

darcs-hash:20070817000140-0f649-8f28c57ace093ceb01ddf01f5a856e17d4d7cb49.gz
  • Loading branch information
jgm committed Aug 17, 2007
1 parent fee5a00 commit daabc5c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions sep-offprint
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# #
# Version history: # Version history:
# #
# sep-offprint 1.11 - John MacFarlane - August 16, 2007
# + use File::Spec and File::Basename for platform-independent
# manipulation of files and directories.
# sep-offprint 1.1 - John MacFarlane - August 16, 2007 # sep-offprint 1.1 - John MacFarlane - August 16, 2007
# + added --output|o option to specify output filename # + added --output|o option to specify output filename
# sep-offprint 1.0 - John MacFarlane - July 19, 2007 # sep-offprint 1.0 - John MacFarlane - July 19, 2007
Expand Down Expand Up @@ -59,7 +62,8 @@ my $version_number = '1.0';
use Getopt::Long; use Getopt::Long;
use File::Temp qw/ tempdir /; use File::Temp qw/ tempdir /;
use File::Copy; use File::Copy;
use Cwd; use File::Basename;
use File::Spec;


# printhelp - returns a usage message # printhelp - returns a usage message


Expand Down Expand Up @@ -230,19 +234,25 @@ else {
} }
$footer = $source; $footer = $source;


$current = File::Spec->curdir; # working directory from which sep-offprint is run

if ($help) {&printhelp;}; if ($help) {&printhelp;};
if (not ($pdf or $ps)) {$pdf=1}; if (not ($pdf or $ps)) {$pdf=1};
if ($oneup) {$twoup = 0} else {$twoup = 1}; if ($oneup) {$twoup = 0} else {$twoup = 1};
if (not $fontsize) {$fontsize = "14pt"}; if (not $fontsize) {$fontsize = "14pt"};
if (not $outfile) {$outfile = $entryname} else {$outfile =~ s/\.[^.]*$//}; if (not $outfile) { $outfile = $entryname; }
if (not $fontfamily) {$fontfamily = "Times"}; if (not $fontfamily) {$fontfamily = "Times"};
if (not $textalign) {$textalign = "justify"}; if (not $textalign) {$textalign = "justify"};
if (not $papersize) {$papersize = "letter"}; if (not $papersize) {$papersize = "letter"};
if (not $linkcolor) {$linkcolor = "black"}; if (not $linkcolor) {$linkcolor = "black"};


# strip .pdf or .ps extension from outfile name, and add path:
my($filename, $directories, $suffix) = fileparse($outfile,qr/\.pdf|\.ps/);
if (not $directories) { $directories = $current };
my $outpath = File::Spec->rel2abs(File::Spec->catfile($directories,$filename));

# create temporary directory # create temporary directory
$temp = tempdir ( CLEANUP => 1 ); $temp = tempdir ( CLEANUP => 1 );
$current = getcwd; # working directory from which sep-offprint is run


# get all the source files and put them in temp directory, # get all the source files and put them in temp directory,
# then change to temp directory # then change to temp directory
Expand Down Expand Up @@ -345,9 +355,9 @@ print STDERR "Creating offprint...\n";
system("html2ps -D -U -f $html2psrc -o $pstemp index.html " . $orderedHtmlFiles . " $notes $blank"); system("html2ps -D -U -f $html2psrc -o $pstemp index.html " . $orderedHtmlFiles . " $notes $blank");


# create pdf if requested # create pdf if requested
if ($pdf) {system("ps2pdf -sPAPERSIZE=$papersize $pstemp $current/$outfile.pdf") || print "Created $outfile.pdf\n";}; if ($pdf) {system("ps2pdf -sPAPERSIZE=$papersize $pstemp $outpath.pdf") || print "Created $outpath.pdf\n";};


# copy ps file if requested # copy ps file if requested
if ($ps) {copy($pstemp, "$current/$outfile.ps") && print "Created $outfile.ps\n";}; if ($ps) {copy($pstemp, "$outpath.ps") && print "Created $outpath.ps\n";};


# note: temporary directory will be deleted automatically on exit # note: temporary directory will be deleted automatically on exit

0 comments on commit daabc5c

Please sign in to comment.