1*0Sstevel@tonic-gate#!/usr/local/bin/perl 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateuse Config; 4*0Sstevel@tonic-gateuse File::Basename qw(&basename &dirname); 5*0Sstevel@tonic-gateuse Cwd; 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gate# List explicitly here the variables you want Configure to 8*0Sstevel@tonic-gate# generate. Metaconfig only looks for shell variables, so you 9*0Sstevel@tonic-gate# have to mention them as if they were shell variables, not 10*0Sstevel@tonic-gate# %Config entries. Thus you write 11*0Sstevel@tonic-gate# $startperl 12*0Sstevel@tonic-gate# to ensure Configure will look for $Config{startperl}. 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gate# This forces PL files to create target in same directory as PL file. 15*0Sstevel@tonic-gate# This is so that make depend always knows where to find PL derivatives. 16*0Sstevel@tonic-gate$origdir = cwd; 17*0Sstevel@tonic-gatechdir dirname($0); 18*0Sstevel@tonic-gate$file = basename($0, '.PL'); 19*0Sstevel@tonic-gate$file .= '.com' if $^O eq 'VMS'; 20*0Sstevel@tonic-gate 21*0Sstevel@tonic-gateopen OUT,">$file" or die "Can't create $file: $!"; 22*0Sstevel@tonic-gate 23*0Sstevel@tonic-gateprint "Extracting $file (with variable substitutions)\n"; 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate# In this section, perl variables will be expanded during extraction. 26*0Sstevel@tonic-gate# You can use $Config{...} to use Configure variables. 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gateprint OUT <<"!GROK!THIS!"; 29*0Sstevel@tonic-gate$Config{startperl} 30*0Sstevel@tonic-gate eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}' 31*0Sstevel@tonic-gate if \$running_under_some_shell; 32*0Sstevel@tonic-gate!GROK!THIS! 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate# In the following, perl variables are not expanded during extraction. 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gateprint OUT <<'!NO!SUBS!'; 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate# pod2latex conversion program 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gateuse strict; 41*0Sstevel@tonic-gateuse Pod::LaTeX; 42*0Sstevel@tonic-gateuse Pod::Find qw/ pod_find /; 43*0Sstevel@tonic-gateuse Pod::Usage; 44*0Sstevel@tonic-gateuse Getopt::Long; 45*0Sstevel@tonic-gateuse File::Basename; 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gatemy $VERSION = "1.00"; 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate# Read command line arguments 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gatemy %options = ( 52*0Sstevel@tonic-gate "help" => 0, 53*0Sstevel@tonic-gate "man" => 0, 54*0Sstevel@tonic-gate "sections" => [], 55*0Sstevel@tonic-gate "full" => 0, 56*0Sstevel@tonic-gate "out" => undef, 57*0Sstevel@tonic-gate "verbose" => 0, 58*0Sstevel@tonic-gate "modify" => 0, 59*0Sstevel@tonic-gate "h1level" => 1, # section is equivalent to H1 60*0Sstevel@tonic-gate ); 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gateGetOptions(\%options, 63*0Sstevel@tonic-gate "help", 64*0Sstevel@tonic-gate "man", 65*0Sstevel@tonic-gate "verbose", 66*0Sstevel@tonic-gate "full", 67*0Sstevel@tonic-gate "sections=s@", 68*0Sstevel@tonic-gate "out=s", 69*0Sstevel@tonic-gate "modify", 70*0Sstevel@tonic-gate "h1level=i", 71*0Sstevel@tonic-gate ) || pod2usage(2); 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gatepod2usage(1) if ($options{help}); 74*0Sstevel@tonic-gatepod2usage(-verbose => 2) if ($options{man}); 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate# Read all the files from the command line 78*0Sstevel@tonic-gatemy @files = @ARGV; 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate# Now find which ones are real pods and convert 81*0Sstevel@tonic-gate# directories to their contents. 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate# Extract the pods from each arg since some of them might 84*0Sstevel@tonic-gate# be directories 85*0Sstevel@tonic-gate# This is not as efficient as using pod_find to search through 86*0Sstevel@tonic-gate# everything at once but it allows us to preserve the order 87*0Sstevel@tonic-gate# supplied by the user 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gatemy @pods; 90*0Sstevel@tonic-gateforeach my $arg (@files) { 91*0Sstevel@tonic-gate my %pods = pod_find($arg); 92*0Sstevel@tonic-gate push(@pods, sort keys %pods); 93*0Sstevel@tonic-gate} 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate# Abort if nothing to do 96*0Sstevel@tonic-gateif ($#pods == -1) { 97*0Sstevel@tonic-gate warn "None of the supplied Pod files actually exist\n"; 98*0Sstevel@tonic-gate exit; 99*0Sstevel@tonic-gate} 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate# If $options{'out'} is set we are processing to a single output file 104*0Sstevel@tonic-gatemy $multi_documents; 105*0Sstevel@tonic-gateif (exists $options{'out'} && defined $options{'out'}) { 106*0Sstevel@tonic-gate $multi_documents = 0; 107*0Sstevel@tonic-gate} else { 108*0Sstevel@tonic-gate $multi_documents = 1; 109*0Sstevel@tonic-gate} 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate# If the output file is not specified it is assumed that 112*0Sstevel@tonic-gate# a single output file is required per input file using 113*0Sstevel@tonic-gate# a .tex extension rather than any exisiting extension 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gateif ($multi_documents) { 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gate # Case where we just generate one input per output 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate foreach my $pod (@pods) { 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate if (-f $pod) { 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate my $output = $pod; 124*0Sstevel@tonic-gate $output = basename($output, '.pm', '.pod','.pl') . '.tex'; 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate # Create a new parser object 127*0Sstevel@tonic-gate my $parser = new Pod::LaTeX( 128*0Sstevel@tonic-gate AddPreamble => $options{'full'}, 129*0Sstevel@tonic-gate AddPostamble => $options{'full'}, 130*0Sstevel@tonic-gate MakeIndex => $options{'full'}, 131*0Sstevel@tonic-gate TableOfContents => $options{'full'}, 132*0Sstevel@tonic-gate ReplaceNAMEwithSection => $options{'modify'}, 133*0Sstevel@tonic-gate UniqueLabels => $options{'modify'}, 134*0Sstevel@tonic-gate Head1Level => $options{'h1level'}, 135*0Sstevel@tonic-gate LevelNoNum => $options{'h1level'} + 1, 136*0Sstevel@tonic-gate ); 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate # Select sections if supplied 139*0Sstevel@tonic-gate $parser->select(@{ $options{'sections'}}) 140*0Sstevel@tonic-gate if @{$options{'sections'}}; 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gate # Derive the input file from the output file 143*0Sstevel@tonic-gate $parser->parse_from_file($pod, $output); 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate print "Written output to $output\n" if $options{'verbose'}; 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate } else { 148*0Sstevel@tonic-gate warn "File $pod not found\n"; 149*0Sstevel@tonic-gate } 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate} else { 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate # Case where we want everything to be in a single document 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gate # Need to open the output file ourselves 157*0Sstevel@tonic-gate my $output = $options{'out'}; 158*0Sstevel@tonic-gate $output .= '.tex' unless $output =~ /\.tex$/; 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate # Use auto-vivified file handle in perl 5.6 161*0Sstevel@tonic-gate use Symbol; 162*0Sstevel@tonic-gate my $outfh = gensym; 163*0Sstevel@tonic-gate open ($outfh, ">$output") || die "Could not open output file: $!\n"; 164*0Sstevel@tonic-gate 165*0Sstevel@tonic-gate # Flag to indicate whether we have converted at least one file 166*0Sstevel@tonic-gate # indicates how many files have been converted 167*0Sstevel@tonic-gate my $converted = 0; 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate # Loop over the input files 170*0Sstevel@tonic-gate foreach my $pod (@pods) { 171*0Sstevel@tonic-gate 172*0Sstevel@tonic-gate if (-f $pod) { 173*0Sstevel@tonic-gate 174*0Sstevel@tonic-gate warn "Converting $pod\n" if $options{'verbose'}; 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate # Open the file (need the handle) 177*0Sstevel@tonic-gate # Use auto-vivified handle in perl 5.6 178*0Sstevel@tonic-gate my $podfh = gensym; 179*0Sstevel@tonic-gate open ($podfh, "<$pod") || die "Could not open pod file $pod: $!\n"; 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate # if this is the first file to be converted we may want to add 182*0Sstevel@tonic-gate # a preamble (controlled by command line option) 183*0Sstevel@tonic-gate my $preamble = 0; 184*0Sstevel@tonic-gate $preamble = 1 if ($converted == 0 && $options{'full'}); 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate # if this is the last file to be converted may want to add 187*0Sstevel@tonic-gate # a postamble (controlled by command line option) 188*0Sstevel@tonic-gate # relies on a previous pass to check existence of all pods we 189*0Sstevel@tonic-gate # are converting. 190*0Sstevel@tonic-gate my $postamble = ( ($converted == $#pods && $options{'full'}) ? 1 : 0 ); 191*0Sstevel@tonic-gate 192*0Sstevel@tonic-gate # Open parser object 193*0Sstevel@tonic-gate # May want to start with a preamble for the first one and 194*0Sstevel@tonic-gate # end with an index for the last 195*0Sstevel@tonic-gate my $parser = new Pod::LaTeX( 196*0Sstevel@tonic-gate MakeIndex => $options{'full'}, 197*0Sstevel@tonic-gate TableOfContents => $preamble, 198*0Sstevel@tonic-gate ReplaceNAMEwithSection => $options{'modify'}, 199*0Sstevel@tonic-gate UniqueLabels => $options{'modify'}, 200*0Sstevel@tonic-gate StartWithNewPage => $options{'full'}, 201*0Sstevel@tonic-gate AddPreamble => $preamble, 202*0Sstevel@tonic-gate AddPostamble => $postamble, 203*0Sstevel@tonic-gate Head1Level => $options{'h1level'}, 204*0Sstevel@tonic-gate LevelNoNum => $options{'h1level'} + 1, 205*0Sstevel@tonic-gate ); 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gate # Store the file name for error messages 208*0Sstevel@tonic-gate # This is a kluge that breaks the data hiding of the object 209*0Sstevel@tonic-gate $parser->{_INFILE} = $pod; 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate # Select sections if supplied 212*0Sstevel@tonic-gate $parser->select(@{ $options{'sections'}}) 213*0Sstevel@tonic-gate if @{$options{'sections'}}; 214*0Sstevel@tonic-gate 215*0Sstevel@tonic-gate # Parse it 216*0Sstevel@tonic-gate $parser->parse_from_filehandle($podfh, $outfh); 217*0Sstevel@tonic-gate 218*0Sstevel@tonic-gate # We have converted at least one file 219*0Sstevel@tonic-gate $converted++; 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gate } else { 222*0Sstevel@tonic-gate warn "File $pod not found\n"; 223*0Sstevel@tonic-gate } 224*0Sstevel@tonic-gate 225*0Sstevel@tonic-gate } 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate # Should unlink the file if we didn't convert anything! 228*0Sstevel@tonic-gate # dont check for return status of unlink 229*0Sstevel@tonic-gate # since there is not a lot to be done if the unlink failed 230*0Sstevel@tonic-gate # and the program does not rely upon it. 231*0Sstevel@tonic-gate unlink "$output" unless $converted; 232*0Sstevel@tonic-gate 233*0Sstevel@tonic-gate # If verbose 234*0Sstevel@tonic-gate warn "Converted $converted files\n" if $options{'verbose'}; 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gate} 237*0Sstevel@tonic-gate 238*0Sstevel@tonic-gateexit; 239*0Sstevel@tonic-gate 240*0Sstevel@tonic-gate__END__ 241*0Sstevel@tonic-gate 242*0Sstevel@tonic-gate=head1 NAME 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gatepod2latex - convert pod documentation to latex format 245*0Sstevel@tonic-gate 246*0Sstevel@tonic-gate=head1 SYNOPSIS 247*0Sstevel@tonic-gate 248*0Sstevel@tonic-gate pod2latex *.pm 249*0Sstevel@tonic-gate 250*0Sstevel@tonic-gate pod2latex -out mytex.tex *.pod 251*0Sstevel@tonic-gate 252*0Sstevel@tonic-gate pod2latex -full -sections 'DESCRIPTION|NAME' SomeDir 253*0Sstevel@tonic-gate 254*0Sstevel@tonic-gate=head1 DESCRIPTION 255*0Sstevel@tonic-gate 256*0Sstevel@tonic-gateC<pod2latex> is a program to convert POD format documentation 257*0Sstevel@tonic-gate(L<perlpod>) into latex. It can process multiple input documents at a 258*0Sstevel@tonic-gatetime and either generate a latex file per input document or a single 259*0Sstevel@tonic-gatecombined output file. 260*0Sstevel@tonic-gate 261*0Sstevel@tonic-gate=head1 OPTIONS AND ARGUMENTS 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gateThis section describes the supported command line options. Minimum 264*0Sstevel@tonic-gatematching is supported. 265*0Sstevel@tonic-gate 266*0Sstevel@tonic-gate=over 4 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gate=item B<-out> 269*0Sstevel@tonic-gate 270*0Sstevel@tonic-gateName of the output file to be used. If there are multiple input pods 271*0Sstevel@tonic-gateit is assumed that the intention is to write all translated output 272*0Sstevel@tonic-gateinto a single file. C<.tex> is appended if not present. If the 273*0Sstevel@tonic-gateargument is not supplied, a single document will be created for each 274*0Sstevel@tonic-gateinput file. 275*0Sstevel@tonic-gate 276*0Sstevel@tonic-gate=item B<-full> 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gateCreates a complete C<latex> file that can be processed immediately 279*0Sstevel@tonic-gate(unless C<=for/=begin> directives are used that rely on extra packages). 280*0Sstevel@tonic-gateTable of contents and index generation commands are included in the 281*0Sstevel@tonic-gatewrapper C<latex> code. 282*0Sstevel@tonic-gate 283*0Sstevel@tonic-gate=item B<-sections> 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gateSpecify pod sections to include (or remove if negated) in the 286*0Sstevel@tonic-gatetranslation. See L<Pod::Select/"SECTION SPECIFICATIONS"> for the 287*0Sstevel@tonic-gateformat to use for I<section-spec>. This option may be given multiple 288*0Sstevel@tonic-gatetimes on the command line.This is identical to the similar option in 289*0Sstevel@tonic-gatethe C<podselect()> command. 290*0Sstevel@tonic-gate 291*0Sstevel@tonic-gate=item B<-modify> 292*0Sstevel@tonic-gate 293*0Sstevel@tonic-gateThis option causes the output C<latex> to be slightly 294*0Sstevel@tonic-gatemodified from the input pod such that when a C<=head1 NAME> 295*0Sstevel@tonic-gateis encountered a section is created containing the actual 296*0Sstevel@tonic-gatepod name (rather than B<NAME>) and all subsequent C<=head1> 297*0Sstevel@tonic-gatedirectives are treated as subsections. This has the advantage 298*0Sstevel@tonic-gatethat the description of a module will be in its own section 299*0Sstevel@tonic-gatewhich is helpful for including module descriptions in documentation. 300*0Sstevel@tonic-gateAlso forces C<latex> label and index entries to be prefixed by the 301*0Sstevel@tonic-gatename of the module. 302*0Sstevel@tonic-gate 303*0Sstevel@tonic-gate=item B<-h1level> 304*0Sstevel@tonic-gate 305*0Sstevel@tonic-gateSpecifies the C<latex> section that is equivalent to a C<H1> pod 306*0Sstevel@tonic-gatedirective. This is an integer between 0 and 5 with 0 equivalent to a 307*0Sstevel@tonic-gateC<latex> chapter, 1 equivalent to a C<latex> section etc. The default 308*0Sstevel@tonic-gateis 1 (C<H1> equivalent to a latex section). 309*0Sstevel@tonic-gate 310*0Sstevel@tonic-gate=item B<-help> 311*0Sstevel@tonic-gate 312*0Sstevel@tonic-gatePrint a brief help message and exit. 313*0Sstevel@tonic-gate 314*0Sstevel@tonic-gate=item B<-man> 315*0Sstevel@tonic-gate 316*0Sstevel@tonic-gatePrint the manual page and exit. 317*0Sstevel@tonic-gate 318*0Sstevel@tonic-gate=item B<-verbose> 319*0Sstevel@tonic-gate 320*0Sstevel@tonic-gatePrint information messages as each document is processed. 321*0Sstevel@tonic-gate 322*0Sstevel@tonic-gate=back 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gate=head1 BUGS 325*0Sstevel@tonic-gate 326*0Sstevel@tonic-gateKnown bugs are: 327*0Sstevel@tonic-gate 328*0Sstevel@tonic-gate=over 4 329*0Sstevel@tonic-gate 330*0Sstevel@tonic-gate=item * 331*0Sstevel@tonic-gate 332*0Sstevel@tonic-gateCross references between documents are not resolved when multiple 333*0Sstevel@tonic-gatepod documents are converted into a single output C<latex> file. 334*0Sstevel@tonic-gate 335*0Sstevel@tonic-gate=item * 336*0Sstevel@tonic-gate 337*0Sstevel@tonic-gateFunctions and variables are not automatically recognized 338*0Sstevel@tonic-gateand they will therefore not be marked up in any special way 339*0Sstevel@tonic-gateunless instructed by an explicit pod command. 340*0Sstevel@tonic-gate 341*0Sstevel@tonic-gate=back 342*0Sstevel@tonic-gate 343*0Sstevel@tonic-gate=head1 SEE ALSO 344*0Sstevel@tonic-gate 345*0Sstevel@tonic-gateL<Pod::LaTeX> 346*0Sstevel@tonic-gate 347*0Sstevel@tonic-gate=head1 AUTHOR 348*0Sstevel@tonic-gate 349*0Sstevel@tonic-gateTim Jenness E<lt>t.jenness@jach.hawaii.eduE<gt> 350*0Sstevel@tonic-gate 351*0Sstevel@tonic-gateThis program is free software; you can redistribute it 352*0Sstevel@tonic-gateand/or modify it under the same terms as Perl itself. 353*0Sstevel@tonic-gate 354*0Sstevel@tonic-gateCopyright (C) 2000, 2003 Tim Jenness. All Rights Reserved. 355*0Sstevel@tonic-gate 356*0Sstevel@tonic-gate=cut 357*0Sstevel@tonic-gate 358*0Sstevel@tonic-gate!NO!SUBS! 359*0Sstevel@tonic-gate 360*0Sstevel@tonic-gateclose OUT or die "Can't close $file: $!"; 361*0Sstevel@tonic-gatechmod 0755, $file or die "Can't reset permissions for $file: $!\n"; 362*0Sstevel@tonic-gateexec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':'; 363*0Sstevel@tonic-gatechdir $origdir; 364