This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
allow Sys::Syslog test to fail gracefully
[perl5.git] / pod / buildtoc.PL
CommitLineData
4755096e
GS
1#!/usr/local/bin/perl
2
3use Config;
4use File::Basename qw(&basename &dirname);
5use 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;
17chdir(dirname($0));
18($file = basename($0)) =~ s/\.PL$//;
19$file =~ s/\.pl$// if ($^O eq 'os2' or $^O eq 'dos'); # "case-forgiving"
20$file =~ s/\.pl$/.com/ if ($^O eq 'VMS'); # "case-forgiving"
21
22open OUT,">$file" or die "Can't create $file: $!";
23
24print "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
29print 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
37print OUT <<'!NO!SUBS!';
38
39#
40# buildtoc
41#
42# !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
43# This file is autogenerated by buildtoc.PL.
44# Edit that file and run it to effect changes.
45#
46# Builds perltoc.pod and sanity checks the list of pods against all
47# of the MANIFEST, perl.pod, and ourselves.
48#
49
50use File::Find;
51use Cwd;
52use Text::Wrap;
53
54@PODS = glob("*.pod");
55
56sub output ($);
57
58if (-d "pod") {
59 die "$0: failed to chdir('pod'): $!\n" unless chdir("pod");
60}
61
a83b6f46
JH
62@ARCHPODS = qw(
63 perlaix
64 perlapollo
65 perlamiga
66 perlbeos
67 perlbs2000
a1f19229 68 perlce
a83b6f46
JH
69 perlcygwin
70 perldgux
71 perldos
72 perlepoc
18a271bd 73 perlfreebsd
a83b6f46
JH
74 perlhpux
75 perlhurd
469e7be4 76 perlirix
a83b6f46
JH
77 perlmachten
78 perlmacos
79 perlmint
80 perlmpeix
9038e305 81 perlnetware
a83b6f46
JH
82 perlos2
83 perlos390
84 perlqnx
85 perlplan9
86 perlsolaris
87 perltru64
91144103 88 perluts
a83b6f46
JH
89 perlvmesa
90 perlvms
91 perlvos
92 perlwin32
93 );
94
d8416318
JH
95@CJKPODS = qw(
96 perlcn
97 perljp
98 perlko
99 perltw
100 );
101
a83b6f46
JH
102@pods =
103 (
104 qw(
105
c2e66d9e 106 perl
10151d09 107 perlintro
c2e66d9e
GS
108 perlfaq
109 perltoc
110 perlbook
111
112 perlsyn
113 perldata
114 perlop
115 perlsub
116 perlfunc
117 perlreftut
118 perldsc
119 perlrequick
120 perlpod
8a93676d 121 perlpodspec
c2e66d9e
GS
122 perlstyle
123 perltrap
124
125 perlrun
126 perldiag
127 perllexwarn
10862624 128 perldebtut
c2e66d9e
GS
129 perldebug
130
131 perlvar
132 perllol
133 perlopentut
34babc16 134 perlpacktut
c2e66d9e
GS
135 perlretut
136
c2e66d9e 137 perlre
d396a558
JH
138 perlref
139
c2e66d9e 140 perlform
d396a558
JH
141
142 perlboot
143 perltoot
890a53b9 144 perltooc
d396a558
JH
145 perlobj
146 perlbot
147 perltie
c2e66d9e
GS
148
149 perlipc
150 perlfork
151 perlnumber
53d7eaa8 152
c2e66d9e 153 perlthrtut
53d7eaa8 154 perlothrtut
c2e66d9e
GS
155
156 perlport
d396a558 157 perllocale
07fcf8ff 158 perluniintro
d396a558
JH
159 perlunicode
160 perlebcdic
c2e66d9e 161
d396a558 162 perlsec
c2e66d9e
GS
163
164 perlmod
c2e66d9e 165 perlmodinstall
35bf961c
JH
166 perlmodlib
167 perlmodstyle
c2e66d9e
GS
168 perlnewmod
169
4755096e
GS
170 perlfaq1
171 perlfaq2
172 perlfaq3
173 perlfaq4
174 perlfaq5
175 perlfaq6
176 perlfaq7
177 perlfaq8
178 perlfaq9
179
180 perlcompile
181
182 perlembed
183 perldebguts
184 perlxstut
185 perlxs
f40a6c71 186 perlclib
4755096e
GS
187 perlguts
188 perlcall
189 perlutil
190 perlfilter
191 perldbmfilter
192 perlapi
193 perlintern
dc5c060f 194 perliol
4755096e
GS
195 perlapio
196 perltodo
197 perlhack
198
199 perlhist
200 perldelta
245d750e 201 perl572delta
1db9e106
JH
202 perl571delta
203 perl570delta
493a87da 204 perl561delta
4755096e
GS
205 perl56delta
206 perl5005delta
207 perl5004delta
208
a83b6f46
JH
209 ),
210
d8416318 211 @ARCHPODS,
a83b6f46
JH
212
213 );
4755096e 214
4755096e
GS
215for (@ARCHPODS) { s/$/.pod/ }
216@ARCHPODS{@ARCHPODS} = ();
217
d8416318
JH
218for (@CJKPODS) { s/$/.pod/ }
219@CJKPODS{@CJKPODS} = ();
220
4755096e
GS
221for (@pods) { s/$/.pod/ }
222@pods{@pods} = ();
223@PODS{@PODS} = ();
224
225open(MANI, "../MANIFEST") || die "$0: opening ../MANIFEST failed: $!";
226while (<MANI>) {
227 if (m!^pod/([^.]+\.pod)\s+!i) {
228 push @MANIPODS, $1;
229 }
230}
231close(MANI);
232@MANIPODS{@MANIPODS} = ();
233
234open(PERLPOD, "perl.pod") || die "$0: opening perl.pod failed: $!\n";
235while (<PERLPOD>) {
236 if (/^For ease of access, /../^\(If you're intending /) {
c2e66d9e 237 if (/^\s+(perl\S*)\s+\w/) {
4755096e
GS
238 push @PERLPODS, "$1.pod";
239 }
240 }
241}
242close(PERLPOD);
243die "$0: could not find the pod listing of perl.pod\n"
244 unless @PERLPODS;
245@PERLPODS{@PERLPODS} = ();
246
d8416318
JH
247# Delete the CJK because we cannot mix their encodings.
248delete @PERLPODS{@CJKPODS};
249delete @PODS{@CJKPODS};
250delete @pods{@CJKPODS};
251
4755096e
GS
252# Cross-check against ourselves
253# Cross-check against the MANIFEST
254# Cross-check against the perl.pod
255
256foreach my $i (sort keys %PODS) {
257 warn "$0: $i exists but is unknown by buildtoc\n"
258 unless exists $pods{$i};
259 warn "$0: $i exists but is unknown by ../MANIFEST\n"
d8416318 260 if !exists $MANIPODS{$i} && !exists $ARCHPODS{$i} && !exists $CJKPODS{$i};
4755096e
GS
261 warn "$0: $i exists but is unknown by perl.pod\n"
262 unless exists $PERLPODS{$i};
263}
264foreach my $i (sort keys %pods) {
265 warn "$0: $i is known by buildtoc but does not exist\n"
266 unless exists $PODS{$i};
267}
268foreach my $i (sort keys %MANIPODS) {
269 warn "$0: $i is known by ../MANIFEST but does not exist\n"
270 unless exists $PODS{$i};
271}
272foreach my $i (sort keys %PERLPODS) {
273 warn "$0: $i is known by perl.pod but does not exist\n"
274 unless exists $PODS{$i};
275}
276
277# We are ready to rock.
278open(OUT, ">perltoc.pod") || die "$0: creating perltoc.pod failed: $!";
279
280$/ = '';
281@ARGV = @pods;
282
283($_= <<EOPOD2B) =~ s/^\t//gm && output($_);
284
285 =head1 NAME
286
287 perltoc - perl documentation table of contents
288
289 =head1 DESCRIPTION
290
291 This page provides a brief table of contents for the rest of the Perl
292 documentation set. It is meant to be scanned quickly or grepped
293 through to locate the proper section you're looking for.
294
295 =head1 BASIC DOCUMENTATION
296
297EOPOD2B
298#' make emacs happy
299
300podset(@pods);
301
302find \&getpods => qw(../lib ../ext);
303
304sub getpods {
305 if (/\.p(od|m)$/) {
4755096e 306 my $file = $File::Find::name;
ad716b8e 307 return if $file eq '../lib/Pod/Functions.pm'; # Used only by pod itself
a83b6f46 308 return if $file =~ m!lib/Attribute/Handlers/demo/!;
ad716b8e 309 return if $file =~ m!lib/Net/FTP/.+\.pm!; # Hi, Graham! :-)
ba62762e 310 return if $file =~ m!lib/Math/BigInt/t/!;
ad716b8e
JH
311 return if $file =~ m!/Devel/PPPort/[Hh]arness|lib/Devel/Harness!i;
312 return if $file =~ m!XS/(?:APItest|Typemap)!;
313 die "tut $name" if $file =~ /TUT/;
4755096e
GS
314 unless (open (F, "< $_\0")) {
315 warn "bogus <$file>: $!";
316 system "ls", "-l", $file;
317 }
318 else {
319 my $line;
320 while ($line = <F>) {
321 if ($line =~ /^=head1\s+NAME\b/) {
322 push @modpods, $file;
323 #warn "GOOD $file\n";
324 return;
325 }
326 }
327 warn "$0: $file: cannot find =head1 NAME\n";
328 }
329 }
330}
331
332die "no pods" unless @modpods;
333
334for (@modpods) {
335 #($name) = /(\w+)\.p(m|od)$/;
336 $name = path2modname($_);
337 if ($name =~ /^[a-z]/) {
338 push @pragmata, $_;
339 } else {
340 if ($done{$name}++) {
341 # warn "already did $_\n";
342 next;
343 }
344 push @modules, $_;
345 push @modname, $name;
346 }
347}
348
349($_= <<EOPOD2B) =~ s/^\t//gm && output($_);
350
351
352
353 =head1 PRAGMA DOCUMENTATION
354
355EOPOD2B
356
357podset(sort @pragmata);
358
359($_= <<EOPOD2B) =~ s/^\t//gm && output($_);
360
361
362
363 =head1 MODULE DOCUMENTATION
364
365EOPOD2B
366
367podset( @modules[ sort { $modname[$a] cmp $modname[$b] } 0 .. $#modules ] );
368
369($_= <<EOPOD2B) =~ s/^\t//gm;
370
371
372 =head1 AUXILIARY DOCUMENTATION
373
374 Here should be listed all the extra programs' documentation, but they
375 don't all have manual pages yet:
376
13a2d996 377 =over 4
4755096e
GS
378
379 =item a2p
380
381 =item s2p
382
383 =item find2perl
384
385 =item h2ph
386
387 =item c2ph
388
389 =item h2xs
390
391 =item xsubpp
392
393 =item pod2man
394
395 =item wrapsuid
396
397 =back
398
399 =head1 AUTHOR
400
401 Larry Wall <F<larry\@wall.org>>, with the help of oodles
402 of other folks.
403
404
405EOPOD2B
406output $_;
407output "\n"; # flush $LINE
408exit;
409
410sub podset {
411 local @ARGV = @_;
412
413 while(<>) {
414 if (s/^=head1 (NAME)\s*/=head2 /) {
415 $pod = path2modname($ARGV);
416 unhead1();
417 output "\n \n\n=head2 ";
418 $_ = <>;
419 if ( /^\s*$pod\b/ ) {
420 s/$pod\.pm/$pod/; # '.pm' in NAME !?
421 output $_;
422 } else {
423 s/^/$pod, /;
424 output $_;
425 }
426 next;
427 }
428 if (s/^=head1 (.*)/=item $1/) {
429 unhead2();
13a2d996 430 output "=over 4\n\n" unless $inhead1;
4755096e
GS
431 $inhead1 = 1;
432 output $_; nl(); next;
433 }
434 if (s/^=head2 (.*)/=item $1/) {
435 unitem();
13a2d996 436 output "=over 4\n\n" unless $inhead2;
4755096e
GS
437 $inhead2 = 1;
438 output $_; nl(); next;
439 }
440 if (s/^=item ([^=].*)/$1/) {
441 next if $pod eq 'perldiag';
442 s/^\s*\*\s*$// && next;
443 s/^\s*\*\s*//;
444 s/\n/ /g;
445 s/\s+$//;
446 next if /^[\d.]+$/;
447 next if $pod eq 'perlmodlib' && /^ftp:/;
13a2d996 448 ##print "=over 4\n\n" unless $initem;
4755096e
GS
449 output ", " if $initem;
450 $initem = 1;
451 s/\.$//;
452 s/^-X\b/-I<X>/;
453 output $_; next;
454 }
455 if (s/^=cut\s*\n//) {
456 unhead1();
457 next;
458 }
459 }
460}
461
462sub path2modname {
463 local $_ = shift;
464 s/\.p(m|od)$//;
465 s-.*?/(lib|ext)/--;
466 s-/-::-g;
467 s/(\w+)::\1/$1/;
468 return $_;
469}
470
471sub unhead1 {
472 unhead2();
473 if ($inhead1) {
474 output "\n\n=back\n\n";
475 }
476 $inhead1 = 0;
477}
478
479sub unhead2 {
480 unitem();
481 if ($inhead2) {
482 output "\n\n=back\n\n";
483 }
484 $inhead2 = 0;
485}
486
487sub unitem {
488 if ($initem) {
489 output "\n\n";
490 ##print "\n\n=back\n\n";
491 }
492 $initem = 0;
493}
494
495sub nl {
496 output "\n";
497}
498
499my $NEWLINE; # how many newlines have we seen recently
500my $LINE; # what remains to be printed
501
502sub output ($) {
503 for (split /(\n)/, shift) {
504 if ($_ eq "\n") {
505 if ($LINE) {
506 print OUT wrap('', '', $LINE);
507 $LINE = '';
508 }
509 if ($NEWLINE < 2) {
510 print OUT;
511 $NEWLINE++;
512 }
513 }
514 elsif (/\S/ && length) {
515 $LINE .= $_;
516 $NEWLINE = 0;
517 }
518 }
519}
520
521!NO!SUBS!
522
6bbf1b34
LM
523close OUT or die "Can't close $file: $!";
524chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
525exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
526chdir $origdir;