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.008; 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 0; # ^ Run only under a 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# Convert POD data to formatted *roff input. 48# 49# The driver script for Pod::Man. 50# 51# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl 52 53use 5.006; 54use strict; 55use warnings; 56 57use Getopt::Long qw(GetOptions); 58use Pod::Man (); 59use Pod::Usage qw(pod2usage); 60 61use strict; 62 63# Clean up $0 for error reporting. 64$0 =~ s%.*/%%; 65 66# Insert -- into @ARGV before any single dash argument to hide it from 67# Getopt::Long; we want to interpret it as meaning stdin. 68my $stdin; 69@ARGV = map { $_ eq '-' && !$stdin++ ? ('--', $_) : $_ } @ARGV; 70 71# Parse our options, trying to retain backward compatibility with pod2man but 72# allowing short forms as well. --lax is currently ignored. 73my %options; 74Getopt::Long::config ('bundling_override'); 75GetOptions (\%options, 'center|c=s', 'date|d=s', 'encoding|e=s', 'errors=s', 76 'fixed=s', 'fixedbold=s', 'fixeditalic=s', 'fixedbolditalic=s', 77 'guesswork=s', 'help|h', 'lax|l', 'language=s', 'lquote=s', 78 'name|n=s', 'nourls', 'official|o', 'quotes|q=s', 'release|r=s', 79 'rquote=s', 'section|s=s', 'stderr', 'verbose|v', 'utf8|u') 80 or exit 1; 81pod2usage (0) if $options{help}; 82 83# Official sets --center, but don't override things explicitly set. 84if ($options{official} && !defined $options{center}) { 85 $options{center} = 'Perl Programmers Reference Guide'; 86} 87 88# Verbose is only our flag, not a Pod::Man flag. 89my $verbose = $options{verbose}; 90delete $options{verbose}; 91 92# This isn't a valid Pod::Man option and is only accepted for backward 93# compatibility. 94delete $options{lax}; 95 96# If neither stderr nor errors is set, default to errors = die. 97if (!defined $options{stderr} && !defined $options{errors}) { 98 $options{errors} = 'die'; 99} 100 101# Initialize and run the formatter, pulling a pair of input and output off at 102# a time. For each file, we check whether the document was completely empty 103# and, if so, will remove the created file and exit with a non-zero exit 104# status. 105my $parser = Pod::Man->new (%options); 106my $status = 0; 107my @files; 108do { 109 @files = splice (@ARGV, 0, 2); 110 print " $files[1]\n" if $verbose; 111 $parser->parse_from_file (@files); 112 if ($parser->{CONTENTLESS}) { 113 $status = 1; 114 if (defined $files[0]) { 115 warn "$0: unable to format $files[0]\n"; 116 } else { 117 warn "$0: unable to format standard input\n"; 118 } 119 if (defined ($files[1]) and $files[1] ne '-') { 120 unlink $files[1] unless (-s $files[1]); 121 } 122 } 123} while (@ARGV); 124exit $status; 125 126__END__ 127 128=for stopwords 129en em --stderr stderr --utf8 UTF-8 overdo markup MT-LEVEL Allbery Solaris URL 130troff troff-specific formatters uppercased Christiansen --nourls UTC prepend 131lquote rquote unrepresentable mandoc manref EBCDIC 132 133=head1 NAME 134 135pod2man - Convert POD data to formatted *roff input 136 137=head1 SYNOPSIS 138 139pod2man [B<--center>=I<string>] [B<--date>=I<string>] 140 [B<--encoding>=I<encoding>] [B<--errors>=I<style>] [B<--fixed>=I<font>] 141 [B<--fixedbold>=I<font>] [B<--fixeditalic>=I<font>] 142 [B<--fixedbolditalic>=I<font>] [B<--guesswork>=I<rule>[,I<rule>...]] 143 [B<--name>=I<name>] [B<--nourls>] [B<--official>] 144 [B<--release>=I<version>] [B<--section>=I<manext>] 145 [B<--quotes>=I<quotes>] [B<--lquote>=I<quote>] [B<--rquote>=I<quote>] 146 [B<--stderr>] [B<--utf8>] [B<--verbose>] [I<input> [I<output>] ...] 147 148pod2man B<--help> 149 150=head1 DESCRIPTION 151 152B<pod2man> is a wrapper script around the L<Pod::Man> module, using it to 153generate *roff input from POD source. The resulting *roff code is suitable 154for display on a terminal using L<nroff(1)>, normally via L<man(1)>, or 155printing using L<troff(1)>. 156 157By default (on non-EBCDIC systems), B<pod2man> outputs UTF-8 manual pages. 158Its output should work with the B<man> program on systems that use B<groff> 159(most Linux distributions) or B<mandoc> (most BSD variants), but may result in 160mangled output on older UNIX systems. To choose a different, possibly more 161backward-compatible output mangling on such systems, use C<--encoding=roff> 162(the default in earlier Pod::Man versions). See the B<--encoding> option and 163L<Pod::Man/ENCODING> for more details. 164 165I<input> is the file to read for POD source (the POD can be embedded in code). 166If I<input> isn't given, it defaults to C<STDIN>. I<output>, if given, is the 167file to which to write the formatted output. If I<output> isn't given, the 168formatted output is written to C<STDOUT>. Several POD files can be processed 169in the same B<pod2man> invocation (saving module load and compile times) by 170providing multiple pairs of I<input> and I<output> files on the command line. 171 172B<--section>, B<--release>, B<--center>, B<--date>, and B<--official> can be 173used to set the headers and footers to use. If not given, Pod::Man will 174assume various defaults. See below for details. 175 176=head1 OPTIONS 177 178Each option is annotated with the version of podlators in which that option 179was added with its current meaning. 180 181=over 4 182 183=item B<-c> I<string>, B<--center>=I<string> 184 185[1.00] Sets the centered page header for the C<.TH> macro to I<string>. The 186default is C<User Contributed Perl Documentation>, but also see B<--official> 187below. 188 189=item B<-d> I<string>, B<--date>=I<string> 190 191[4.00] Set the left-hand footer string for the C<.TH> macro to I<string>. By 192default, the first of POD_MAN_DATE, SOURCE_DATE_EPOCH, the modification date 193of the input file, or the current date (if input comes from C<STDIN>) will be 194used, and the date will be in UTC. See L<Pod::Man/CLASS METHODS> for more 195details. 196 197=item B<-e> I<encoding>, B<--encoding>=I<encoding> 198 199[5.00] Specifies the encoding of the output. I<encoding> must be an encoding 200recognized by the L<Encode> module (see L<Encode::Supported>). The default on 201non-EBCDIC systems is UTF-8. 202 203If the output contains characters that cannot be represented in this encoding, 204that is an error that will be reported as configured by the B<--errors> 205option. If error handling is other than C<die>, the unrepresentable character 206will be replaced with the Encode substitution character (normally C<?>). 207 208If the C<encoding> option is set to the special value C<groff> (the default on 209EBCDIC systems), or if the Encode module is not available and the encoding is 210set to anything other than C<roff> (see below), Pod::Man will translate all 211non-ASCII characters to C<\[uNNNN]> Unicode escapes. These are not 212traditionally part of the *roff language, but are supported by B<groff> and 213B<mandoc> and thus by the majority of manual page processors in use today. 214 215If I<encoding> is set to the special value C<roff>, B<pod2man> will do its 216historic transformation of (some) ISO 8859-1 characters into *roff escapes 217that may be adequate in troff and may be readable (if ugly) in nroff. This 218was the default behavior of versions of B<pod2man> before 5.00. With this 219encoding, all other non-ASCII characters will be replaced with C<X>. It may 220be required for very old troff and nroff implementations that do not support 221UTF-8, but its representation of any non-ASCII character is very poor and 222often specific to European languages. Its use is discouraged. 223 224WARNING: The input encoding of the POD source is independent from the output 225encoding, and setting this option does not affect the interpretation of the 226POD input. Unless your POD source is US-ASCII, its encoding should be 227declared with the C<=encoding> command in the source. If this is not done, 228Pod::Simple will will attempt to guess the encoding and may be successful if 229it's Latin-1 or UTF-8, but it will produce warnings. See L<perlpod(1)> for 230more information. 231 232=item B<--errors>=I<style> 233 234[2.5.0] Set the error handling style. C<die> says to throw an exception on 235any POD formatting error. C<stderr> says to report errors on standard error, 236but not to throw an exception. C<pod> says to include a POD ERRORS section in 237the resulting documentation summarizing the errors. C<none> ignores POD 238errors entirely, as much as possible. 239 240The default is C<die>. 241 242=item B<--fixed>=I<font> 243 244[1.0] The fixed-width font to use for verbatim text and code. Defaults to 245C<CW>. Some systems may want C<CR> instead. Only matters for B<troff> 246output. 247 248=item B<--fixedbold>=I<font> 249 250[1.0] Bold version of the fixed-width font. Defaults to C<CB>. Only matters 251for B<troff> output. 252 253=item B<--fixeditalic>=I<font> 254 255[1.0] Italic version of the fixed-width font (something of a misnomer, since 256most fixed-width fonts only have an oblique version, not an italic version). 257Defaults to C<CI>. Only matters for B<troff> output. 258 259=item B<--fixedbolditalic>=I<font> 260 261[1.0] Bold italic (in theory, probably oblique in practice) version of the 262fixed-width font. Pod::Man doesn't assume you have this, and defaults to 263C<CB>. Some systems (such as Solaris) have this font available as C<CX>. 264Only matters for B<troff> output. 265 266=item B<--guesswork>=I<rule>[,I<rule>...] 267 268[5.00] By default, B<pod2man> applies some default formatting rules based on 269guesswork and regular expressions that are intended to make writing Perl 270documentation easier and require less explicit markup. These rules may not 271always be appropriate, particularly for documentation that isn't about Perl. 272This option allows turning all or some of it off. 273 274The special rule C<all> enables all guesswork. This is also the default for 275backward compatibility reasons. The special rule C<none> disables all 276guesswork. Otherwise, the value of this option should be a comma-separated 277list of one or more of the following keywords: 278 279=over 4 280 281=item functions 282 283Convert function references like C<foo()> to bold even if they have no markup. 284The function name accepts valid Perl characters for function names (including 285C<:>), and the trailing parentheses must be present and empty. 286 287=item manref 288 289Make the first part (before the parentheses) of man page references like 290C<foo(1)> bold even if they have no markup. The section must be a single 291number optionally followed by lowercase letters. 292 293=item quoting 294 295If no guesswork is enabled, any text enclosed in CZ<><> is surrounded by 296double quotes in nroff (terminal) output unless the contents are already 297quoted. When this guesswork is enabled, quote marks will also be suppressed 298for Perl variables, function names, function calls, numbers, and hex 299constants. 300 301=item variables 302 303Convert Perl variable names to a fixed-width font even if they have no markup. 304This transformation will only be apparent in troff output, or some other 305output format (unlike nroff terminal output) that supports fixed-width fonts. 306 307=back 308 309Any unknown guesswork name is silently ignored (for potential future 310compatibility), so be careful about spelling. 311 312=item B<-h>, B<--help> 313 314[1.00] Print out usage information. 315 316=item B<-l>, B<--lax> 317 318[1.00] No longer used. B<pod2man> used to check its input for validity as a 319manual page, but this should now be done by L<podchecker(1)> instead. 320Accepted for backward compatibility; this option no longer does anything. 321 322=item B<--language>=I<language> 323 324[5.00] Add commands telling B<groff> that the input file is in the given 325language. The value of this setting must be a language abbreviation for which 326B<groff> provides supplemental configuration, such as C<ja> (for Japanese) or 327C<zh> (for Chinese). 328 329This adds: 330 331 .mso <language>.tmac 332 .hla <language> 333 334to the start of the file, which configure correct line breaking for the 335specified language. Without these commands, groff may not know how to add 336proper line breaks for Chinese and Japanese text if the man page is installed 337into the normal man page directory, such as F</usr/share/man>. 338 339On many systems, this will be done automatically if the man page is installed 340into a language-specific man page directory, such as F</usr/share/man/zh_CN>. 341In that case, this option is not required. 342 343Unfortunately, the commands added with this option are specific to B<groff> 344and will not work with other B<troff> and B<nroff> implementations. 345 346=item B<--lquote>=I<quote> 347 348=item B<--rquote>=I<quote> 349 350[4.08] Sets the quote marks used to surround CE<lt>> text. B<--lquote> sets 351the left quote mark and B<--rquote> sets the right quote mark. Either may 352also be set to the special value C<none>, in which case no quote mark is added 353on that side of CE<lt>> text (but the font is still changed for troff output). 354 355Also see the B<--quotes> option, which can be used to set both quotes at once. 356If both B<--quotes> and one of the other options is set, B<--lquote> or 357B<--rquote> overrides B<--quotes>. 358 359=item B<-n> I<name>, B<--name>=I<name> 360 361[4.08] Set the name of the manual page for the C<.TH> macro to I<name>. 362Without this option, the manual name is set to the uppercased base name of the 363file being converted unless the manual section is 3, in which case the path is 364parsed to see if it is a Perl module path. If it is, a path like 365C<.../lib/Pod/Man.pm> is converted into a name like C<Pod::Man>. This option, 366if given, overrides any automatic determination of the name. 367 368Although one does not have to follow this convention, be aware that the 369convention for UNIX manual pages is for the title to be in all-uppercase, even 370if the command isn't. (Perl modules traditionally use mixed case for the 371manual page title, however.) 372 373This option is probably not useful when converting multiple POD files at once. 374 375When converting POD source from standard input, the name will be set to 376C<STDIN> if this option is not provided. Providing this option is strongly 377recommended to set a meaningful manual page name. 378 379=item B<--nourls> 380 381[2.5.0] Normally, LZ<><> formatting codes with a URL but anchor text are 382formatted to show both the anchor text and the URL. In other words: 383 384 L<foo|http://example.com/> 385 386is formatted as: 387 388 foo <http://example.com/> 389 390This flag, if given, suppresses the URL when anchor text is given, so this 391example would be formatted as just C<foo>. This can produce less 392cluttered output in cases where the URLs are not particularly important. 393 394=item B<-o>, B<--official> 395 396[1.00] Set the default header to indicate that this page is part of the 397standard Perl release, if B<--center> is not also given. 398 399=item B<-q> I<quotes>, B<--quotes>=I<quotes> 400 401[4.00] Sets the quote marks used to surround CE<lt>> text to I<quotes>. If 402I<quotes> is a single character, it is used as both the left and right quote. 403Otherwise, it is split in half, and the first half of the string is used as 404the left quote and the second is used as the right quote. 405 406I<quotes> may also be set to the special value C<none>, in which case no quote 407marks are added around CE<lt>> text (but the font is still changed for troff 408output). 409 410Also see the B<--lquote> and B<--rquote> options, which can be used to set the 411left and right quotes independently. If both B<--quotes> and one of the other 412options is set, B<--lquote> or B<--rquote> overrides B<--quotes>. 413 414=item B<-r> I<version>, B<--release>=I<version> 415 416[1.00] Set the centered footer for the C<.TH> macro to I<version>. By 417default, this is set to the version of Perl you run B<pod2man> under. Setting 418this to the empty string will cause some *roff implementations to use the 419system default value. 420 421Note that some system C<an> macro sets assume that the centered footer will be 422a modification date and will prepend something like C<Last modified: >. If 423this is the case for your target system, you may want to set B<--release> to 424the last modified date and B<--date> to the version number. 425 426=item B<-s> I<string>, B<--section>=I<string> 427 428[1.00] Set the section for the C<.TH> macro. The standard section numbering 429convention is to use 1 for user commands, 2 for system calls, 3 for functions, 4304 for devices, 5 for file formats, 6 for games, 7 for miscellaneous 431information, and 8 for administrator commands. There is a lot of variation 432here, however; some systems (like Solaris) use 4 for file formats, 5 for 433miscellaneous information, and 7 for devices. Still others use 1m instead of 4348, or some mix of both. About the only section numbers that are reliably 435consistent are 1, 2, and 3. 436 437By default, section 1 will be used unless the file ends in C<.pm>, in which 438case section 3 will be selected. 439 440=item B<--stderr> 441 442[2.1.3] By default, B<pod2man> dies if any errors are detected in the POD 443input. If B<--stderr> is given and no B<--errors> flag is present, errors are 444sent to standard error, but B<pod2man> does not abort. This is equivalent to 445C<--errors=stderr> and is supported for backward compatibility. 446 447=item B<-u>, B<--utf8> 448 449[2.1.0] This option used to tell B<pod2man> to produce UTF-8 output. Since 450this is now the default as of version 5.00, it is ignored and does nothing. 451 452=item B<-v>, B<--verbose> 453 454[1.11] Print out the name of each output file as it is being generated. 455 456=back 457 458=head1 EXIT STATUS 459 460As long as all documents processed result in some output, even if that output 461includes errata (a C<POD ERRORS> section generated with C<--errors=pod>), 462B<pod2man> will exit with status 0. If any of the documents being processed 463do not result in an output document, B<pod2man> will exit with status 1. If 464there are syntax errors in a POD document being processed and the error 465handling style is set to the default of C<die>, B<pod2man> will abort 466immediately with exit status 255. 467 468=head1 DIAGNOSTICS 469 470If B<pod2man> fails with errors, see L<Pod::Man> and L<Pod::Simple> for 471information about what those errors might mean. 472 473=head1 EXAMPLES 474 475 pod2man program > program.1 476 pod2man SomeModule.pm /usr/perl/man/man3/SomeModule.3 477 pod2man --section=7 note.pod > note.7 478 479If you would like to print out a lot of man page continuously, you probably 480want to set the C and D registers to set contiguous page numbering and 481even/odd paging, at least on some versions of man(7). 482 483 troff -man -rC1 -rD1 perl.1 perldata.1 perlsyn.1 ... 484 485To get index entries on C<STDERR>, turn on the F register, as in: 486 487 troff -man -rF1 perl.1 488 489The indexing merely outputs messages via C<.tm> for each major page, section, 490subsection, item, and any C<XE<lt>E<gt>> directives. 491 492=head1 AUTHOR 493 494Russ Allbery <rra@cpan.org>, based on the original B<pod2man> by Larry Wall 495and Tom Christiansen. 496 497=head1 COPYRIGHT AND LICENSE 498 499Copyright 1999-2001, 2004, 2006, 2008, 2010, 2012-2019, 2022 Russ Allbery 500<rra@cpan.org> 501 502This program is free software; you may redistribute it and/or modify it 503under the same terms as Perl itself. 504 505=head1 SEE ALSO 506 507L<Pod::Man>, L<Pod::Simple>, L<man(1)>, L<nroff(1)>, L<perlpod(1)>, 508L<podchecker(1)>, L<perlpodstyle(1)>, L<troff(1)>, L<man(7)> 509 510The man page documenting the an macro set may be L<man(5)> instead of 511L<man(7)> on your system. 512 513The current version of this script is always available from its web site at 514L<https://www.eyrie.org/~eagle/software/podlators/>. It is also part of the 515Perl core distribution as of 5.6.0. 516 517=cut 518SCRIPT_BODY 519 520# Finish the generation of the script. 521close($out) or die "Cannot close $file: $!\n"; 522chmod(0755, $file) or die "Cannot reset permissions for $file: $!\n"; 523if ($Config{'eunicefix'} ne q{:}) { 524 exec("$Config{'eunicefix'} $file"); 525} 526 527# Local Variables: 528# copyright-at-end-flag: t 529# End: 530