Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[dc3ae5]: make_chapters.pl Maximize Restore History

Download this file

make_chapters.pl    133 lines (85 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl
use strict;
use warnings;
=pod
=head1 make_chapters.pl
Reads a user defined list of POD chapters and produces a PDF file in the
root directory.
This program converts "=for html <img sec="xxx">" tags
to C<< O <xxx> >> tags for the C<pod2pdf> converter and
adjusts the relative paths so that you can run C<pod2pdf> in the root
directory.
=head1 USAGE
Run from the command prompt and edit your paths and the C<pod2pdf>
command line options in the USER SELECTABLE OPTIONS area of this
program.
=head2 AUTHOR
Matthew Kenworthy <matthew.kenworthy@gmail.com>, 2012 Jan 30
=cut
##################################################
# USER SELECTABLE OPTIONS
my $book_dir = "PDL/Book/"; # relative path to the PDL Book files
my $book_chapters = "FirstSteps Creating NiceSlice Functions Threading PGPLOT PLplot graphics_3d Transform Complex Pthreads PP Credits"; # an ordered list of POD files to process
my $tmp = "book_pdf.pod.tmp"; # temporary filename for POD processing
##################################################
# END OF USER SELECTABLE OPTIONS
my $exec_intro = "pod2pdf PDL/Book/Genesis.pod --icon-scale 0.25 --title 'Forward' --icon ".$book_dir."logo2.png --output-file Chapter00.pdf";
print "Generating the Foreword for the Book from Genesis.pod, writing it to Chapter 00.pdf\n";
`$exec_intro`;
# loop through all the book chapters in their order
my $chap_num = 1;
foreach (split " ",$book_chapters) {
my $chapter = $book_dir . $_ .".pod";
# check for its existence
unless (-e $chapter) {
print "$chapter doesn't exist - skipping\n";
next;
}
### $chapter = "test_book.tmp";
# filter on each chapter to put in O<image.png> tags
print "Found $chapter...";
open(FIN,$chapter) or die "Cannot open $chapter for reading\n";
my @chapter_text = <FIN>;
close(FIN);
# take the header from the FIRST =head1
my $title = "Chapter";
foreach (@chapter_text) {
if (/^=head1/)
{
$title = $_;
chomp $title;
$title =~ s/=head1\W*//;
last;
}
}
my $header = "Chapter $chap_num: $title";
print "$header from $chapter\n";
open(FOUT, ">$tmp") or die "Cannot create temporary file $tmp\n";
while ($_ = shift @chapter_text) {
my $whole_line = "";
if (/^=for html/) { # now push on non-empty lines until finished
chomp;
$whole_line = $_;
# ugly, but it works
while(1) {
$_ = shift @chapter_text;
last if ($_ =~ /^$/); # match blank lines
$whole_line = $whole_line . $_;
}
$whole_line =~ /.*src=\"(.*)\">/; # search for quoted image filename
print FOUT "O<" . $book_dir . "$1>\n\n";
} else {print FOUT $_;}
}
close(FOUT);
# FOUT now has the text ready for PDF
my $chapter_file = sprintf("Chapter%02d.pdf", $chap_num);
print "Writing out $header to $chapter_file\n";
my $exec_string = "pod2pdf $tmp --icon-scale 0.25 --title '$header' --icon ".$book_dir."logo2.png --output-file ". $chapter_file;
print "Execing $exec_string\n";
# go ahead and make the call
`$exec_string`;
$chap_num += 1;
}
# delete the temporary file
unlink($tmp);
print "\n$0 finished.\n\n";