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