Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

327 lines
8.4 KiB

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!perl
  14. #line 15
  15. eval 'exec C:\Perl\bin\perl.exe -S $0 ${1+"$@"}'
  16. if $running_under_some_shell;
  17. # pod2latex conversion program
  18. use Pod::LaTeX;
  19. use Pod::Find qw/ pod_find /;
  20. use Pod::Usage;
  21. use Getopt::Long;
  22. use File::Basename;
  23. # Read command line arguments
  24. my %options = (
  25. "help" => 0,
  26. "man" => 0,
  27. "sections" => [],
  28. "full" => 0,
  29. "out" => undef,
  30. "verbose" => 0,
  31. "modify" => 0,
  32. );
  33. GetOptions(\%options,
  34. "help",
  35. "man",
  36. "verbose",
  37. "full",
  38. "sections=s@",
  39. "out=s",
  40. "modify",
  41. ) || pod2usage(2);
  42. pod2usage(1) if ($options{help});
  43. pod2usage(-verbose => 2) if ($options{man});
  44. # Read all the files from the command line
  45. my @files = @ARGV;
  46. # Now find which ones are real pods and convert
  47. # directories to their contents.
  48. # Extract the pods from each arg since some of them might
  49. # be directories
  50. # This is not as efficient as using pod_find to search through
  51. # everything at once but it allows us to preserve the order
  52. # supplied by the user
  53. my @pods;
  54. foreach my $arg (@files) {
  55. my %pods = pod_find($arg);
  56. push(@pods, sort keys %pods);
  57. }
  58. # Abort if nothing to do
  59. if ($#pods == -1) {
  60. warn "None of the supplied Pod files actually exist\n";
  61. exit;
  62. }
  63. # If $options{'out'} is set we are processing to a single output file
  64. my $multi_documents;
  65. if (exists $options{'out'} && defined $options{'out'}) {
  66. $multi_documents = 0;
  67. } else {
  68. $multi_documents = 1;
  69. }
  70. # If the output file is not specified it is assumed that
  71. # a single output file is required per input file using
  72. # a .tex extension rather than any exisiting extension
  73. if ($multi_documents) {
  74. # Case where we just generate one input per output
  75. foreach my $pod (@pods) {
  76. if (-f $pod) {
  77. my $output = $pod;
  78. $output = basename($output, '.pm', '.pod','.pl') . '.tex';
  79. # Create a new parser object
  80. my $parser = new Pod::LaTeX(
  81. AddPreamble => $options{'full'},
  82. AddPostamble => $options{'full'},
  83. MakeIndex => $options{'full'},
  84. TableOfContents => $options{'full'},
  85. ReplaceNAMEwithSection => $options{'modify'},
  86. UniqueLabels => $options{'modify'},
  87. );
  88. # Select sections if supplied
  89. $parser->select(@{ $options{'sections'}})
  90. if @{$options{'sections'}};
  91. # Derive the input file from the output file
  92. $parser->parse_from_file($pod, $output);
  93. print "Written output to $output\n" if $options{'verbose'};
  94. } else {
  95. warn "File $pod not found\n";
  96. }
  97. }
  98. } else {
  99. # Case where we want everything to be in a single document
  100. # Need to open the output file ourselves
  101. my $output = $options{'out'};
  102. $output .= '.tex' unless $output =~ /\.tex$/;
  103. # Use auto-vivified file handle in perl 5.6
  104. use Symbol;
  105. my $outfh = gensym;
  106. open ($outfh, ">$output") || die "Could not open output file: $!\n";
  107. # Flag to indicate whether we have converted at least one file
  108. # indicates how many files have been converted
  109. my $converted = 0;
  110. # Loop over the input files
  111. foreach my $pod (@pods) {
  112. if (-f $pod) {
  113. warn "Converting $pod\n" if $options{'verbose'};
  114. # Open the file (need the handle)
  115. # Use auto-vivified handle in perl 5.6
  116. my $podfh = gensym;
  117. open ($podfh, "<$pod") || die "Could not open pod file $pod: $!\n";
  118. # if this is the first file to be converted we may want to add
  119. # a preamble (controlled by command line option)
  120. if ($converted == 0 && $options{'full'}) {
  121. $preamble = 1;
  122. } else {
  123. $preamble = 0;
  124. }
  125. # if this is the last file to be converted may want to add
  126. # a postamble (controlled by command line option)
  127. # relies on a previous pass to check existence of all pods we
  128. # are converting.
  129. my $postamble = ( ($converted == $#pods && $options{'full'}) ? 1 : 0 );
  130. # Open parser object
  131. # May want to start with a preamble for the first one and
  132. # end with an index for the last
  133. my $parser = new Pod::LaTeX(
  134. MakeIndex => $options{'full'},
  135. TableOfContents => $preamble,
  136. ReplaceNAMEwithSection => $options{'modify'},
  137. UniqueLabels => $options{'modify'},
  138. StartWithNewPage => $options{'full'},
  139. AddPreamble => $preamble,
  140. AddPostamble => $postamble,
  141. );
  142. # Store the file name for error messages
  143. # This is a kluge that breaks the data hiding of the object
  144. $parser->{_INFILE} = $pod;
  145. # Select sections if supplied
  146. $parser->select(@{ $options{'sections'}})
  147. if @{$options{'sections'}};
  148. # Parse it
  149. $parser->parse_from_filehandle($podfh, $outfh);
  150. # We have converted at least one file
  151. $converted++;
  152. } else {
  153. warn "File $pod not found\n";
  154. }
  155. }
  156. # Should unlink the file if we didn't convert anything!
  157. # dont check for return status of unlink
  158. # since there is not a lot to be done if the unlink failed
  159. # and the program does not rely upon it.
  160. unlink "$output" unless $converted;
  161. # If verbose
  162. warn "Converted $converted files\n" if $options{'verbose'};
  163. }
  164. exit;
  165. __END__
  166. =head1 NAME
  167. pod2latex - convert pod documentation to latex format
  168. =head1 SYNOPSIS
  169. pod2latex *.pm
  170. pod2latex -out mytex.tex *.pod
  171. pod2latex -full -sections 'DESCRIPTION|NAME' SomeDir
  172. =head1 DESCRIPTION
  173. C<pod2latex> is a program to convert POD format documentation
  174. (L<perlpod>) into latex. It can process multiple input documents at a
  175. time and either generate a latex file per input document or a single
  176. combined output file.
  177. =head1 OPTIONS AND ARGUMENTS
  178. This section describes the supported command line options. Minium
  179. matching is supported.
  180. =over 4
  181. =item B<-out>
  182. Name of the output file to be used. If there are multiple input pods
  183. it is assumed that the intention is to write all translated output
  184. into a single file. C<.tex> is appended if not present. If the
  185. argument is not supplied, a single document will be created for each
  186. input file.
  187. =item B<-full>
  188. Creates a complete C<latex> file that can be processed immediately
  189. (unless C<=for/=begin> directives are used that rely on extra packages).
  190. Table of contents and index generation commands are included in the
  191. wrapper C<latex> code.
  192. =item B<-sections>
  193. Specify pod sections to include (or remove if negated) in the
  194. translation. See L<Pod::Select/"SECTION SPECIFICATIONS"> for the
  195. format to use for I<section-spec>. This option may be given multiple
  196. times on the command line.This is identical to the similar option in
  197. the C<podselect()> command.
  198. =item B<-modify>
  199. This option causes the output C<latex> to be slightly
  200. modified from the input pod such that when a C<=head1 NAME>
  201. is encountered a section is created containing the actual
  202. pod name (rather than B<NAME>) and all subsequent C<=head1>
  203. directives are treated as subsections. This has the advantage
  204. that the description of a module will be in its own section
  205. which is helpful for including module descriptions in documentation.
  206. Also forces C<latex> label and index entries to be prefixed by the
  207. name of the module.
  208. =item B<-help>
  209. Print a brief help message and exit.
  210. =item B<-man>
  211. Print the manual page and exit.
  212. =item B<-verbose>
  213. Print information messages as each document is processed.
  214. =back
  215. =head1 BUGS
  216. Known bugs are:
  217. =over 4
  218. =item *
  219. Cross references between documents are not resolved when multiple
  220. pod documents are converted into a single output C<latex> file.
  221. =item *
  222. Functions and variables are not automatically recognized
  223. and they will therefore not be marked up in any special way
  224. unless instructed by an explicit pod command.
  225. =back
  226. =head1 SEE ALSO
  227. L<Pod::LaTeX>
  228. =head1 AUTHOR
  229. Tim Jenness E<lt>[email protected]<gt>
  230. This program is free software; you can redistribute it
  231. and/or modify it under the same terms as Perl itself.
  232. Copyright (C) 2000 Tim Jenness.
  233. =cut
  234. __END__
  235. :endofperl