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