1#!/usr/bin/perl 2# 3# Special wrapper script to generate the actual pod2man script. This is 4# required for proper start-up code on non-UNIX platforms, and is used inside 5# Perl core. 6 7use 5.006; 8use strict; 9use warnings; 10 11use Config qw(%Config); 12use Cwd qw(cwd); 13use File::Basename qw(basename dirname); 14 15# List explicitly here the variables you want Configure to generate. 16# Metaconfig only looks for shell variables, so you have to mention them as if 17# they were shell variables, not %Config entries. Thus you write 18# $startperl 19# to ensure Configure will look for $Config{startperl}. 20 21# This forces PL files to create target in same directory as PL file. 22# This is so that make depend always knows where to find PL derivatives. 23chdir(dirname($0)) or die "Cannot change directories: $!\n"; 24my $file = basename($0, '.PL'); 25if ($^O eq 'VMS') { 26 $file .= '.com'; 27} 28 29# Create the generated script. 30## no critic (InputOutput::RequireBriefOpen) 31## no critic (InputOutput::RequireCheckedSyscalls) 32open(my $out, '>', $file) or die "Cannot create $file: $!\n"; 33print "Extracting $file (with variable substitutions)\n"; 34## use critic 35 36# In this section, Perl variables will be expanded during extraction. You can 37# use $Config{...} to use Configure variables. 38print {$out} <<"PREAMBLE" or die "Cannot write to $file: $!\n"; 39$Config{startperl} 40 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}' 41 if \$running_under_some_shell; 42PREAMBLE 43 44# In the following, Perl variables are not expanded during extraction. 45print {$out} <<'SCRIPT_BODY' or die "Cannot write to $file: $!\n"; 46 47# pod2man -- Convert POD data to formatted *roff input. 48# 49# Copyright 1999, 2000, 2001, 2004, 2006, 2008, 2010, 2012, 2013, 2014, 2015, 50# 2016, 2017 Russ Allbery <rra@cpan.org> 51# 52# This program is free software; you may redistribute it and/or modify it 53# under the same terms as Perl itself. 54 55use 5.006; 56use strict; 57use warnings; 58 59use Getopt::Long qw(GetOptions); 60use Pod::Man (); 61use Pod::Usage qw(pod2usage); 62 63use strict; 64 65# Clean up $0 for error reporting. 66$0 =~ s%.*/%%; 67 68# Insert -- into @ARGV before any single dash argument to hide it from 69# Getopt::Long; we want to interpret it as meaning stdin. 70my $stdin; 71@ARGV = map { $_ eq '-' && !$stdin++ ? ('--', $_) : $_ } @ARGV; 72 73# Parse our options, trying to retain backward compatibility with pod2man but 74# allowing short forms as well. --lax is currently ignored. 75my %options; 76$options{utf8} = 1; 77Getopt::Long::config ('bundling_override'); 78GetOptions (\%options, 'center|c=s', 'date|d=s', 'errors=s', 'fixed=s', 79 'fixedbold=s', 'fixeditalic=s', 'fixedbolditalic=s', 'help|h', 80 'lax|l', 'lquote=s', 'name|n=s', 'nourls', 'official|o', 81 'quotes|q=s', 'release|r=s', 'rquote=s', 'section|s=s', 'stderr', 82 'verbose|v', 'utf8|u!') 83 or exit 1; 84pod2usage (0) if $options{help}; 85 86# Official sets --center, but don't override things explicitly set. 87if ($options{official} && !defined $options{center}) { 88 $options{center} = 'Perl Programmers Reference Guide'; 89} 90 91# Verbose is only our flag, not a Pod::Man flag. 92my $verbose = $options{verbose}; 93delete $options{verbose}; 94 95# This isn't a valid Pod::Man option and is only accepted for backward 96# compatibility. 97delete $options{lax}; 98 99# If neither stderr nor errors is set, default to errors = die. 100if (!defined $options{stderr} && !defined $options{errors}) { 101 $options{errors} = 'die'; 102} 103 104# Initialize and run the formatter, pulling a pair of input and output off at 105# a time. For each file, we check whether the document was completely empty 106# and, if so, will remove the created file and exit with a non-zero exit 107# status. 108my $parser = Pod::Man->new (%options); 109my $status = 0; 110my @files; 111do { 112 @files = splice (@ARGV, 0, 2); 113 print " $files[1]\n" if $verbose; 114 $parser->parse_from_file (@files); 115 if ($parser->{CONTENTLESS}) { 116 $status = 1; 117 if (defined $files[0]) { 118 warn "$0: unable to format $files[0]\n"; 119 } else { 120 warn "$0: unable to format standard input\n"; 121 } 122 if (defined ($files[1]) and $files[1] ne '-') { 123 unlink $files[1] unless (-s $files[1]); 124 } 125 } 126} while (@ARGV); 127exit $status; 128 129__END__ 130 131=for stopwords 132en em --stderr stderr --no-utf8 UTF-8 overdo markup MT-LEVEL Allbery Solaris 133URL troff troff-specific formatters uppercased Christiansen --nourls UTC 134prepend lquote rquote 135 136=head1 NAME 137 138pod2man - Convert POD data to formatted *roff input 139 140=head1 SYNOPSIS 141 142pod2man [B<--center>=I<string>] [B<--date>=I<string>] [B<--errors>=I<style>] 143 [B<--fixed>=I<font>] [B<--fixedbold>=I<font>] [B<--fixeditalic>=I<font>] 144 [B<--fixedbolditalic>=I<font>] [B<--name>=I<name>] [B<--nourls>] 145 [B<--official>] [B<--release>=I<version>] [B<--section>=I<manext>] 146 [B<--quotes>=I<quotes>] [B<--lquote>=I<quote>] [B<--rquote>=I<quote>] 147 [B<--stderr>] [B<--no-utf8>] [B<--verbose>] [I<input> [I<output>] ...] 148 149pod2man B<--help> 150 151=head1 DESCRIPTION 152 153B<pod2man> is a front-end for Pod::Man, using it to generate *roff input 154from POD source. The resulting *roff code is suitable for display on a 155terminal using nroff(1), normally via man(1), or printing using troff(1). 156 157I<input> is the file to read for POD source (the POD can be embedded in 158code). If I<input> isn't given, it defaults to C<STDIN>. I<output>, if 159given, is the file to which to write the formatted output. If I<output> 160isn't given, the formatted output is written to C<STDOUT>. Several POD 161files can be processed in the same B<pod2man> invocation (saving module 162load and compile times) by providing multiple pairs of I<input> and 163I<output> files on the command line. 164 165B<--section>, B<--release>, B<--center>, B<--date>, and B<--official> can 166be used to set the headers and footers to use; if not given, Pod::Man will 167assume various defaults. See below or L<Pod::Man> for details. 168 169B<pod2man> assumes that your *roff formatters have a fixed-width font 170named C<CW>. If yours is called something else (like C<CR>), use 171B<--fixed> to specify it. This generally only matters for troff output 172for printing. Similarly, you can set the fonts used for bold, italic, and 173bold italic fixed-width output. 174 175Besides the obvious pod conversions, Pod::Man, and therefore pod2man also 176takes care of formatting func(), func(n), and simple variable references 177like $foo or @bar so you don't have to use code escapes for them; complex 178expressions like C<$fred{'stuff'}> will still need to be escaped, though. 179It also translates dashes that aren't used as hyphens into en dashes, makes 180long dashes--like this--into proper em dashes, fixes "paired quotes," and 181takes care of several other troff-specific tweaks. See L<Pod::Man> for 182complete information. 183 184=head1 OPTIONS 185 186=over 4 187 188=item B<-c> I<string>, B<--center>=I<string> 189 190Sets the centered page header for the C<.TH> macro to I<string>. The 191default is "User Contributed Perl Documentation", but also see 192B<--official> below. 193 194=item B<-d> I<string>, B<--date>=I<string> 195 196Set the left-hand footer string for the C<.TH> macro to I<string>. By 197default, the modification date of the input file will be used, or the 198current date if input comes from C<STDIN>, and will be based on UTC (so 199that the output will be reproducible regardless of local time zone). 200 201=item B<--errors>=I<style> 202 203Set the error handling style. C<die> says to throw an exception on any 204POD formatting error. C<stderr> says to report errors on standard error, 205but not to throw an exception. C<pod> says to include a POD ERRORS 206section in the resulting documentation summarizing the errors. C<none> 207ignores POD errors entirely, as much as possible. 208 209The default is C<die>. 210 211=item B<--fixed>=I<font> 212 213The fixed-width font to use for verbatim text and code. Defaults to 214C<CW>. Some systems may want C<CR> instead. Only matters for troff(1) 215output. 216 217=item B<--fixedbold>=I<font> 218 219Bold version of the fixed-width font. Defaults to C<CB>. Only matters 220for troff(1) output. 221 222=item B<--fixeditalic>=I<font> 223 224Italic version of the fixed-width font (actually, something of a misnomer, 225since most fixed-width fonts only have an oblique version, not an italic 226version). Defaults to C<CI>. Only matters for troff(1) output. 227 228=item B<--fixedbolditalic>=I<font> 229 230Bold italic (probably actually oblique) version of the fixed-width font. 231Pod::Man doesn't assume you have this, and defaults to C<CB>. Some 232systems (such as Solaris) have this font available as C<CX>. Only matters 233for troff(1) output. 234 235=item B<-h>, B<--help> 236 237Print out usage information. 238 239=item B<-l>, B<--lax> 240 241No longer used. B<pod2man> used to check its input for validity as a 242manual page, but this should now be done by L<podchecker(1)> instead. 243Accepted for backward compatibility; this option no longer does anything. 244 245=item B<--lquote>=I<quote> 246 247=item B<--rquote>=I<quote> 248 249Sets the quote marks used to surround CE<lt>> text. B<--lquote> sets the 250left quote mark and B<--rquote> sets the right quote mark. Either may also 251be set to the special value C<none>, in which case no quote mark is added 252on that side of CE<lt>> text (but the font is still changed for troff 253output). 254 255Also see the B<--quotes> option, which can be used to set both quotes at once. 256If both B<--quotes> and one of the other options is set, B<--lquote> or 257B<--rquote> overrides B<--quotes>. 258 259=item B<-n> I<name>, B<--name>=I<name> 260 261Set the name of the manual page for the C<.TH> macro to I<name>. Without 262this option, the manual name is set to the uppercased base name of the 263file being converted unless the manual section is 3, in which case the 264path is parsed to see if it is a Perl module path. If it is, a path like 265C<.../lib/Pod/Man.pm> is converted into a name like C<Pod::Man>. This 266option, if given, overrides any automatic determination of the name. 267 268Although one does not have to follow this convention, be aware that the 269convention for UNIX man pages for commands is for the man page title to be 270in all-uppercase, even if the command isn't. 271 272This option is probably not useful when converting multiple POD files at 273once. 274 275When converting POD source from standard input, the name will be set to 276C<STDIN> if this option is not provided. Providing this option is strongly 277recommended to set a meaningful manual page name. 278 279=item B<--nourls> 280 281Normally, LZ<><> formatting codes with a URL but anchor text are formatted 282to show both the anchor text and the URL. In other words: 283 284 L<foo|http://example.com/> 285 286is formatted as: 287 288 foo <http://example.com/> 289 290This flag, if given, suppresses the URL when anchor text is given, so this 291example would be formatted as just C<foo>. This can produce less 292cluttered output in cases where the URLs are not particularly important. 293 294=item B<-o>, B<--official> 295 296Set the default header to indicate that this page is part of the standard 297Perl release, if B<--center> is not also given. 298 299=item B<-q> I<quotes>, B<--quotes>=I<quotes> 300 301Sets the quote marks used to surround CE<lt>> text to I<quotes>. If 302I<quotes> is a single character, it is used as both the left and right 303quote. Otherwise, it is split in half, and the first half of the string 304is used as the left quote and the second is used as the right quote. 305 306I<quotes> may also be set to the special value C<none>, in which case no 307quote marks are added around CE<lt>> text (but the font is still changed for 308troff output). 309 310Also see the B<--lquote> and B<--rquote> options, which can be used to set the 311left and right quotes independently. If both B<--quotes> and one of the other 312options is set, B<--lquote> or B<--rquote> overrides B<--quotes>. 313 314=item B<-r> I<version>, B<--release>=I<version> 315 316Set the centered footer for the C<.TH> macro to I<version>. By default, 317this is set to the version of Perl you run B<pod2man> under. Setting this 318to the empty string will cause some *roff implementations to use the 319system default value. 320 321Note that some system C<an> macro sets assume that the centered footer 322will be a modification date and will prepend something like "Last 323modified: ". If this is the case for your target system, you may want to 324set B<--release> to the last modified date and B<--date> to the version 325number. 326 327=item B<-s> I<string>, B<--section>=I<string> 328 329Set the section for the C<.TH> macro. The standard section numbering 330convention is to use 1 for user commands, 2 for system calls, 3 for 331functions, 4 for devices, 5 for file formats, 6 for games, 7 for 332miscellaneous information, and 8 for administrator commands. There is a lot 333of variation here, however; some systems (like Solaris) use 4 for file 334formats, 5 for miscellaneous information, and 7 for devices. Still others 335use 1m instead of 8, or some mix of both. About the only section numbers 336that are reliably consistent are 1, 2, and 3. 337 338By default, section 1 will be used unless the file ends in C<.pm>, in 339which case section 3 will be selected. 340 341=item B<--stderr> 342 343By default, B<pod2man> dies if any errors are detected in the POD input. 344If B<--stderr> is given and no B<--errors> flag is present, errors are 345sent to standard error, but B<pod2man> does not abort. This is equivalent 346to C<--errors=stderr> and is supported for backward compatibility. 347 348=item B<-u>, B<--utf8> 349 350This option allows B<pod2man> to output literal UTF-8 characters. 351On OpenBSD, it is enabled by default and can be disabled with 352B<--no-utf8>, in which case non-ASCII characters are converted 353either to *roff escape sequences or to C<X>. 354 355Be aware that, when using this option, the input encoding of your POD 356source should be properly declared unless it's US-ASCII. Pod::Simple will 357attempt to guess the encoding and may be successful if it's Latin-1 or 358UTF-8, but it will warn, which by default results in a B<pod2man> failure. 359Use the C<=encoding> command to declare the encoding. See L<perlpod(1)> 360for more information. 361 362=item B<-v>, B<--verbose> 363 364Print out the name of each output file as it is being generated. 365 366=back 367 368=head1 EXIT STATUS 369 370As long as all documents processed result in some output, even if that 371output includes errata (a C<POD ERRORS> section generated with 372C<--errors=pod>), B<pod2man> will exit with status 0. If any of the 373documents being processed do not result in an output document, B<pod2man> 374will exit with status 1. If there are syntax errors in a POD document 375being processed and the error handling style is set to the default of 376C<die>, B<pod2man> will abort immediately with exit status 255. 377 378=head1 DIAGNOSTICS 379 380If B<pod2man> fails with errors, see L<Pod::Man> and L<Pod::Simple> for 381information about what those errors might mean. 382 383=head1 EXAMPLES 384 385 pod2man program > program.1 386 pod2man SomeModule.pm /usr/perl/man/man3/SomeModule.3 387 pod2man --section=7 note.pod > note.7 388 389If you would like to print out a lot of man page continuously, you probably 390want to set the C and D registers to set contiguous page numbering and 391even/odd paging, at least on some versions of man(7). 392 393 troff -man -rC1 -rD1 perl.1 perldata.1 perlsyn.1 ... 394 395To get index entries on C<STDERR>, turn on the F register, as in: 396 397 troff -man -rF1 perl.1 398 399The indexing merely outputs messages via C<.tm> for each major page, 400section, subsection, item, and any C<XE<lt>E<gt>> directives. See 401L<Pod::Man> for more details. 402 403=head1 BUGS 404 405Lots of this documentation is duplicated from L<Pod::Man>. 406 407=head1 SEE ALSO 408 409L<Pod::Man>, L<Pod::Simple>, L<man(1)>, L<nroff(1)>, L<perlpod(1)>, 410L<podchecker(1)>, L<perlpodstyle(1)>, L<troff(1)>, L<man(7)> 411 412The man page documenting the an macro set may be L<man(5)> instead of 413L<man(7)> on your system. 414 415The current version of this script is always available from its web site at 416L<http://www.eyrie.org/~eagle/software/podlators/>. It is also part of the 417Perl core distribution as of 5.6.0. 418 419=head1 AUTHOR 420 421Russ Allbery <rra@cpan.org>, based I<very> heavily on the original 422B<pod2man> by Larry Wall and Tom Christiansen. 423 424=head1 COPYRIGHT AND LICENSE 425 426Copyright 1999, 2000, 2001, 2004, 2006, 2008, 2010, 2012, 2013, 2014, 4272015, 2016, 2017 Russ Allbery <rra@cpan.org> 428 429This program is free software; you may redistribute it and/or modify it 430under the same terms as Perl itself. 431 432=cut 433SCRIPT_BODY 434 435# Finish the generation of the script. 436close($out) or die "Cannot close $file: $!\n"; 437chmod(0755, $file) or die "Cannot reset permissions for $file: $!\n"; 438if ($Config{'eunicefix'} ne q{:}) { 439 exec("$Config{'eunicefix'} $file"); 440} 441