Fix a bug in the description of endianness. Reported in
[p5sagit/p5-mst-13.2.git] / pod / pod2usage.PL
1 #!/usr/local/bin/perl
2
3 use Config;
4 use File::Basename qw(&basename &dirname);
5 use Cwd;
6
7 # List explicitly here the variables you want Configure to
8 # generate.  Metaconfig only looks for shell variables, so you
9 # have to mention them as if they were shell variables, not
10 # %Config entries.  Thus you write
11 #  $startperl
12 # to ensure Configure will look for $Config{startperl}.
13
14 # This forces PL files to create target in same directory as PL file.
15 # This is so that make depend always knows where to find PL derivatives.
16 $origdir = cwd;
17 chdir(dirname($0));
18 ($file = basename($0)) =~ s/\.PL$//;
19 $file =~ s/\.pl$//
20         if ($^O eq 'VMS' or $^O eq 'os2' or $^O eq 'dos');  # "case-forgiving"
21
22 open OUT,">$file" or die "Can't create $file: $!";
23
24 print "Extracting $file (with variable substitutions)\n";
25
26 # In this section, perl variables will be expanded during extraction.
27 # You can use $Config{...} to use Configure variables.
28
29 print OUT <<"!GROK!THIS!";
30 $Config{'startperl'}
31     eval 'exec perl -S \$0 "\$@"'
32         if 0;
33 !GROK!THIS!
34
35 # In the following, perl variables are not expanded during extraction.
36
37 print OUT <<'!NO!SUBS!';
38
39 #############################################################################
40 # pod2usage -- command to print usage messages from embedded pod docs
41 #
42 # Derived from Tom Christiansen's pod2text script.
43 # (with extensive modifications)
44 #
45 # Copyright (c) 1996 Bradford Appleton. All rights reserved.
46 # This file is part of "PodParser". PodParser is free software;
47 # you can redistribute it and/or modify it under the same terms
48 # as Perl itself.
49 #############################################################################
50
51 use strict;
52 use diagnostics;
53
54 =head1 NAME
55
56 pod2usage - print usage messages from embedded pod docs in files
57
58 =head1 SYNOPSIS
59
60 =over 12
61
62 =item B<pod2usage>
63
64 [B<-help>]
65 [B<-man>]
66 [B<-exit>S< >I<exitval>]
67 [B<-output>S< >I<outfile>]
68 [B<-verbose> I<level>]
69 [B<-pathlist> I<dirlist>]
70 I<file>
71
72 =back
73
74 =head1 OPTIONS AND ARGUMENTS
75
76 =over 8
77
78 =item B<-help>
79
80 Print a brief help message and exit.
81
82 =item B<-man>
83
84 Print this command's manual page and exit.
85
86 =item B<-exit> I<exitval>
87
88 The exit status value to return.
89
90 =item B<-output> I<outfile>
91
92 The output file to print to. If the special names "-" or ">&1" or ">&STDOUT"
93 are used then standard output is used. If ">&2" or ">&STDERR" is used then
94 standard error is used.
95
96 =item B<-verbose> I<level>
97
98 The desired level of verbosity to use:
99
100     1 : print SYNOPSIS only
101     2 : print SYNOPSIS sections and any OPTIONS/ARGUMENTS sections
102     3 : print the entire manpage (similar to running pod2text)
103
104 =item B<-pathlist> I<dirlist>
105
106 Specifies one or more directories to search for the input file if it
107 was not supplied with an absolute path. Each directory path in the given
108 list should be separated by a ':' on Unix (';' on MSWin32 and DOS).
109
110 =item I<file>
111
112 The pathname of a file containing pod documentation to be output in
113 usage mesage format (defaults to standard input).
114
115 =back
116
117 =head1 DESCRIPTION
118
119 B<pod2usage> will read the given input file looking for pod
120 documentation and will print the corresponding usage message.
121 If no input file is specifed than standard input is read.
122
123 B<pod2usage> invokes the B<pod2usage()> function in the B<Pod::Usage>
124 module. Please see L<Pod::Usage/pod2usage()>.
125
126 =head1 SEE ALSO
127
128 L<Pod::Usage>, L<pod2text(1)>
129
130 =head1 AUTHOR
131
132 Brad Appleton E<lt>bradapp@enteract.comE<gt>
133
134 Based on code for B<pod2text(1)> written by
135 Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
136
137 =cut
138
139 use Pod::Usage;
140 use Getopt::Long;
141
142 ## Define options
143 my %options = ();
144 my @opt_specs = (
145     "help",
146     "man",
147     "exit=i",
148     "output=s",
149     "pathlist=s",
150     "verbose=i",
151 );
152
153 ## Parse options
154 GetOptions(\%options, @opt_specs)  ||  pod2usage(2);
155 pod2usage(1)  if ($options{help});
156 pod2usage(VERBOSE => 2)  if ($options{man});
157
158 ## Dont default to STDIN if connected to a terminal
159 pod2usage(2) if ((@ARGV == 0) && (-t STDIN));
160
161 @ARGV = ("-")  unless (@ARGV > 0);
162 if (@ARGV > 1) {
163     print STDERR "pod2usage: Too many filenames given\n\n";
164     pod2usage(2);
165 }
166
167 my %usage = ();
168 $usage{-input}    = shift(@ARGV);
169 $usage{-exitval}  = $options{"exit"}      if (defined $options{"exit"});
170 $usage{-output}   = $options{"output"}    if (defined $options{"output"});
171 $usage{-verbose}  = $options{"verbose"}   if (defined $options{"verbose"});
172 $usage{-pathlist} = $options{"pathlist"}  if (defined $options{"pathlist"});
173
174 pod2usage(\%usage);
175
176
177 !NO!SUBS!
178
179 close OUT or die "Can't close $file: $!";
180 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
181 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
182 chdir $origdir;