Commit | Line | Data |
---|---|---|
41630250 JH |
1 | #!/usr/bin/perl -w |
2 | ||
3 | use strict; | |
41630250 | 4 | use File::Spec; |
41630250 | 5 | use FindBin; |
41630250 JH |
6 | use Text::Wrap; |
7 | use Getopt::Long; | |
8 | ||
3d3a0a8a | 9 | our $Quiet; |
41630250 JH |
10 | no locale; |
11 | ||
ccbc7283 NC |
12 | # Assumption is that we're either already being run from the top level (*nix, |
13 | # VMS), or have absolute paths in @INC (Win32, pod/Makefile) | |
d7816c47 | 14 | BEGIN { |
d5e2eea9 | 15 | my $Top = File::Spec->catdir($FindBin::Bin, File::Spec->updir); |
ccbc7283 | 16 | chdir $Top or die "Can't chdir to $Top: $!"; |
3d7c117d | 17 | require './Porting/pod_lib.pl'; |
ad77fdb4 | 18 | } |
41630250 | 19 | |
b78c1104 | 20 | die "$0: Usage: $0 [--quiet]\n" |
bb4830e6 | 21 | unless GetOptions ('q|quiet' => \$Quiet) && !@ARGV; |
41630250 | 22 | |
d4c6b7ae | 23 | my $state = get_pod_metadata(0, sub { warn @_ if @_ }, 'pod/perltoc.pod'); |
41630250 | 24 | |
9bbb230a NC |
25 | my $found = pods_to_install(); |
26 | ||
27 | my_die "Can't find any pods!\n" unless %$found; | |
41630250 | 28 | |
b78c1104 NC |
29 | # Accumulating everything into a lexical before writing to disk dates from the |
30 | # time when this script also provided the functionality of regen/pod_rules.pl | |
31 | # and this code was in a subroutine do_toc(). In turn, the use of a file scoped | |
32 | # lexical instead of a parameter or return value is because the code dates back | |
33 | # further still, and used *only* to create pod/perltoc.pod by printing direct | |
41630250 | 34 | |
d871876a | 35 | my $OUT; |
60f0ee9d | 36 | my $roffitall; |
d871876a | 37 | |
b78c1104 | 38 | ($_= <<"EOPOD2B") =~ s/^\t//gm and $OUT .= $_; |
41630250 | 39 | |
97f32038 JH |
40 | # !!!!!!! DO NOT EDIT THIS FILE !!!!!!! |
41 | # This file is autogenerated by buildtoc from all the other pods. | |
b78c1104 | 42 | # Edit those files and run $0 to effect changes. |
97f32038 | 43 | |
c9dde696 DH |
44 | =encoding UTF-8 |
45 | ||
41630250 JH |
46 | =head1 NAME |
47 | ||
48 | perltoc - perl documentation table of contents | |
49 | ||
50 | =head1 DESCRIPTION | |
51 | ||
52 | This page provides a brief table of contents for the rest of the Perl | |
53 | documentation set. It is meant to be scanned quickly or grepped | |
54 | through to locate the proper section you're looking for. | |
55 | ||
56 | =head1 BASIC DOCUMENTATION | |
57 | ||
58 | EOPOD2B | |
41630250 | 59 | |
b78c1104 | 60 | # All the things in the master list that happen to be pod filenames |
2ce3647c NC |
61 | foreach (grep {!$_->[2]{toc_omit}} @{$state->{master}}) { |
62 | $roffitall .= " \$mandir/$_->[0].1 \\\n"; | |
63 | podset($_->[0], $_->[1]); | |
b78c1104 | 64 | } |
41630250 | 65 | |
8c9aa8a0 NC |
66 | foreach my $type (qw(PRAGMA MODULE)) { |
67 | ($_= <<"EOPOD2B") =~ s/^\t//gm and $OUT .= $_; | |
41630250 JH |
68 | |
69 | ||
70 | ||
8c9aa8a0 | 71 | =head1 $type DOCUMENTATION |
41630250 JH |
72 | |
73 | EOPOD2B | |
74 | ||
9bbb230a | 75 | foreach my $name (sort keys %{$found->{$type}}) { |
524b4932 | 76 | $roffitall .= " \$libdir/$name.3 \\\n"; |
9bbb230a | 77 | podset($name, $found->{$type}{$name}); |
8c9aa8a0 | 78 | } |
b78c1104 | 79 | } |
41630250 | 80 | |
b78c1104 | 81 | $_= <<"EOPOD2B"; |
41630250 JH |
82 | |
83 | ||
84 | =head1 AUXILIARY DOCUMENTATION | |
85 | ||
86 | Here should be listed all the extra programs' documentation, but they | |
87 | don't all have manual pages yet: | |
88 | ||
89 | =over 4 | |
90 | ||
91 | EOPOD2B | |
92 | ||
4e604983 | 93 | $_ .= join "\n", map {"\t=item $_\n"} @{$state->{aux}}; |
b78c1104 | 94 | $_ .= <<"EOPOD2B" ; |
41630250 JH |
95 | |
96 | =back | |
97 | ||
98 | =head1 AUTHOR | |
99 | ||
100 | Larry Wall <F<larry\@wall.org>>, with the help of oodles | |
101 | of other folks. | |
102 | ||
103 | ||
104 | EOPOD2B | |
105 | ||
b78c1104 NC |
106 | s/^\t//gm; |
107 | $OUT .= "$_\n"; | |
d871876a | 108 | |
b78c1104 NC |
109 | $OUT =~ s/\n\s+\n/\n\n/gs; |
110 | $OUT =~ s/\n{3,}/\n\n/g; | |
b8ce93b8 | 111 | |
b78c1104 | 112 | $OUT =~ s/([^\n]+)/wrap('', '', $1)/ge; |
b8ce93b8 | 113 | |
3b0c5c72 | 114 | write_or_die('pod/perltoc.pod', $OUT); |
b78c1104 | 115 | |
60f0ee9d NC |
116 | write_or_die('pod/roffitall', <<'EOH' . $roffitall . <<'EOT'); |
117 | #!/bin/sh | |
118 | # | |
119 | # Usage: roffitall [-nroff|-psroff|-groff] | |
120 | # | |
121 | # Authors: Tom Christiansen, Raphael Manfredi | |
122 | ||
123 | me=roffitall | |
124 | tmp=. | |
125 | ||
126 | if test -f ../config.sh; then | |
127 | . ../config.sh | |
128 | fi | |
129 | ||
130 | mandir=$installman1dir | |
131 | libdir=$installman3dir | |
132 | ||
133 | test -d $mandir || mandir=/usr/new/man/man1 | |
134 | test -d $libdir || libdir=/usr/new/man/man3 | |
135 | ||
136 | case "$1" in | |
137 | -nroff) cmd="nroff -man"; ext='txt';; | |
138 | -psroff) cmd="psroff -t"; ext='ps';; | |
139 | -groff) cmd="groff -man"; ext='ps';; | |
140 | *) | |
141 | echo "Usage: roffitall [-nroff|-psroff|-groff]" >&2 | |
142 | exit 1 | |
143 | ;; | |
144 | esac | |
145 | ||
146 | toroff=` | |
147 | echo \ | |
148 | EOH | |
149 | | perl -ne 'map { -r && print "$_ " } split'` | |
150 | ||
151 | # Bypass internal shell buffer limit -- can't use case | |
152 | if perl -e '$a = shift; exit($a =~ m|/|)' $toroff; then | |
153 | echo "$me: empty file list -- did you run install?" >&2 | |
154 | exit 1 | |
155 | fi | |
156 | ||
157 | #psroff -t -man -rC1 -rD1 -rF1 > $tmp/PerlDoc.ps 2>$tmp/PerlTOC.raw | |
158 | #nroff -man -rC1 -rD1 -rF1 > $tmp/PerlDoc.txt 2>$tmp/PerlTOC.nr.raw | |
159 | ||
160 | # First, create the raw data | |
161 | run="$cmd -rC1 -rD1 -rF1 >$tmp/PerlDoc.$ext 2>$tmp/PerlTOC.$ext.raw" | |
162 | echo "$me: running $run" | |
163 | eval $run $toroff | |
164 | ||
165 | #Now create the TOC | |
166 | echo "$me: parsing TOC" | |
167 | perl rofftoc $tmp/PerlTOC.$ext.raw > $tmp/PerlTOC.tmp.man | |
168 | run="$cmd $tmp/PerlTOC.tmp.man >$tmp/PerlTOC.$ext" | |
169 | echo "$me: running $run" | |
170 | eval $run | |
171 | ||
172 | # Finally, recreate the Doc, without the blank page 0 | |
173 | run="$cmd -rC1 -rD1 >$tmp/PerlDoc.$ext 2>$tmp/PerlTOC.$ext.raw" | |
174 | echo "$me: running $run" | |
175 | eval $run $toroff | |
176 | rm -f $tmp/PerlTOC.tmp.man $tmp/PerlTOC.$ext.raw | |
177 | echo "$me: leaving you with $tmp/PerlDoc.$ext and $tmp/PerlTOC.$ext" | |
178 | EOT | |
179 | ||
b78c1104 | 180 | exit(0); |
41630250 JH |
181 | |
182 | # Below are all the auxiliary routines for generating perltoc.pod | |
183 | ||
184 | my ($inhead1, $inhead2, $initem); | |
185 | ||
186 | sub podset { | |
524b4932 | 187 | my ($pod, $file) = @_; |
41630250 | 188 | |
2fb0e7e4 | 189 | open my $fh, '<:raw', $file or my_die "Can't open file '$file' for $pod: $!"; |
3a527656 | 190 | |
4027e27b | 191 | local *_; |
3a527656 NC |
192 | my $found_pod; |
193 | while (<$fh>) { | |
194 | if (/^=head1\s+NAME\b/) { | |
195 | ++$found_pod; | |
196 | last; | |
197 | } | |
198 | } | |
536d7404 | 199 | |
3a527656 NC |
200 | unless ($found_pod) { |
201 | warn "$0: NOTE: cannot find '=head1 NAME' in:\n $file\n" unless $Quiet; | |
202 | return; | |
203 | } | |
204 | ||
205 | seek $fh, 0, 0 or my_die "Can't rewind file '$file': $!"; | |
206 | local $/ = ''; | |
0b01631d | 207 | |
84f07fb2 | 208 | while(<$fh>) { |
16114dde | 209 | tr/\015//d; |
41630250 | 210 | if (s/^=head1 (NAME)\s*/=head2 /) { |
41630250 | 211 | unhead1(); |
c0f8aaaa | 212 | $OUT .= "\n\n=head2 "; |
84f07fb2 | 213 | $_ = <$fh>; |
767650bc NC |
214 | # Remove svn keyword expansions from the Perl FAQ |
215 | s/ \(\$Revision: \d+ \$\)//g; | |
32ebae07 | 216 | if ( /^\s*\Q$pod\E\b/ ) { |
41630250 | 217 | s/$pod\.pm/$pod/; # '.pm' in NAME !? |
41630250 JH |
218 | } else { |
219 | s/^/$pod, /; | |
41630250 | 220 | } |
41630250 | 221 | } |
1fa7865d | 222 | elsif (s/^=head1 (.*)/=item $1/) { |
41630250 | 223 | unhead2(); |
c0f8aaaa | 224 | $OUT .= "=over 4\n\n" unless $inhead1; |
41630250 | 225 | $inhead1 = 1; |
1fa7865d | 226 | $_ .= "\n"; |
41630250 | 227 | } |
1fa7865d | 228 | elsif (s/^=head2 (.*)/=item $1/) { |
41630250 | 229 | unitem(); |
c0f8aaaa | 230 | $OUT .= "=over 4\n\n" unless $inhead2; |
41630250 | 231 | $inhead2 = 1; |
1fa7865d | 232 | $_ .= "\n"; |
41630250 | 233 | } |
1fa7865d | 234 | elsif (s/^=item ([^=].*)/$1/) { |
41630250 JH |
235 | next if $pod eq 'perldiag'; |
236 | s/^\s*\*\s*$// && next; | |
237 | s/^\s*\*\s*//; | |
238 | s/\n/ /g; | |
239 | s/\s+$//; | |
240 | next if /^[\d.]+$/; | |
241 | next if $pod eq 'perlmodlib' && /^ftp:/; | |
c0f8aaaa | 242 | $OUT .= ", " if $initem; |
41630250 JH |
243 | $initem = 1; |
244 | s/\.$//; | |
245 | s/^-X\b/-I<X>/; | |
41630250 | 246 | } |
1fa7865d NC |
247 | else { |
248 | unhead1() if /^=cut\s*\n/; | |
41630250 JH |
249 | next; |
250 | } | |
1fa7865d | 251 | $OUT .= $_; |
41630250 JH |
252 | } |
253 | } | |
254 | ||
255 | sub unhead1 { | |
256 | unhead2(); | |
257 | if ($inhead1) { | |
c0f8aaaa | 258 | $OUT .= "\n\n=back\n\n"; |
41630250 JH |
259 | } |
260 | $inhead1 = 0; | |
261 | } | |
262 | ||
263 | sub unhead2 { | |
264 | unitem(); | |
265 | if ($inhead2) { | |
c0f8aaaa | 266 | $OUT .= "\n\n=back\n\n"; |
41630250 JH |
267 | } |
268 | $inhead2 = 0; | |
269 | } | |
270 | ||
271 | sub unitem { | |
272 | if ($initem) { | |
c0f8aaaa | 273 | $OUT .= "\n\n"; |
41630250 JH |
274 | } |
275 | $initem = 0; | |
276 | } | |
b1a2f073 | 277 | |
ec8fadde JK |
278 | =head1 NAME |
279 | ||
280 | pod/buildtoc - Generate table of contents | |
281 | ||
282 | =head1 DESCRIPTION | |
283 | ||
284 | This program generates a table of contents for the documentation included in the Perl core distribution. This table of contents takes two forms: | |
285 | ||
286 | =over 4 | |
287 | ||
288 | =item 1 F<pod/perltoc.pod> | |
289 | ||
290 | A file in Perl's Plain Old Documentation (POD) format found in the F<pod/> directory in the core distribution. Once Perl is installed, this file becomes accessible system-wide via C<perldoc perltoc>. | |
291 | ||
292 | =item 2 F<pod/roffitall> | |
293 | ||
294 | A shell script originally written by Tom Christiansen and Raphael Manfredi, also found in the F<pod/> directory, which can be used to translate Perl documentation into F<man> pages. | |
295 | ||
296 | =back | |
297 | ||
298 | =head1 USAGE | |
299 | ||
300 | This program will typically B<not> need to be called directly by a user. Rather, it is one of the last commands invoked during C<make test_prep>: | |
301 | ||
302 | ./perl -Ilib -I. -f pod/buildtoc -q | |
303 | ||
304 | The only command-line switch is C<-q|--quiet>, which quiets some non-critical warnings. | |
305 | ||
306 | =head2 Diagnosing Problems | |
307 | ||
308 | This program C<require>s F<Porting/pod_lib.pl> and makes use of several subroutines found in that file: C<get_pod_metadata()> and C<pods_to_install()> in particular. Consequently, any warnings or exceptions you see when this program is running may be being passed through from those subroutines. You may have to (a) examine those subroutines and/or (b) run that program from the command-line to fully understand what is causing such warnings or exceptions. | |
309 | ||
310 | =head2 AUTHORS and MAINTENANCE | |
311 | ||
312 | This program was introduced into the Perl 5 core distribution by Andy Dougherty, based on earlier work by Tom Christiansen. It is maintained by the Perl 5 Porters. | |
313 | ||
314 | =cut | |
315 | ||
b1a2f073 | 316 | # ex: set ts=8 sts=4 sw=4 et: |