skip integrate of problematic change#6292 from cfgperl into mainline
[p5sagit/p5-mst-13.2.git] / pod / buildtoc
CommitLineData
cb1a09d0 1use File::Find;
2use Cwd;
8ebc5c01 3use Text::Wrap;
cb1a09d0 4
8ebc5c01 5sub output ($);
6
7@pods = qw(
68dc0745 8 perl perlfaq perlfaq1 perlfaq2 perlfaq3 perlfaq4 perlfaq5
9 perlfaq6 perlfaq7 perlfaq8 perlfaq9 perldelta perldata
10 perlsyn perlop perlre perlrun perlfunc perlvar perlsub
7766f137 11 perlmod perlmodlib perlmodinstall perlfork perlform perllocale
a1e2a320 12 perlref perlreftut perldsc
694468e3 13 perllol perlboot perltoot perltootc perlobj perltie perlbot perlipc
b38f6a39 14 perldbmfilter perldebug perlnumber perldebguts
fb9cefb4 15 perldiag perlsec perltrap perlport perlstyle perlpod perlbook
54a137f5 16 perlembed perlapio perlxs perlxstut perlguts perlcall perlcompile
954c1994 17 perlapi perlintern perlhist
8ebc5c01 18 );
19
20for (@pods) { s/$/.pod/ }
cb1a09d0 21
22$/ = '';
23@ARGV = @pods;
24
8ebc5c01 25($_= <<EOPOD2B) =~ s/^\t//gm && output($_);
cb1a09d0 26
27 =head1 NAME
28
29 perltoc - perl documentation table of contents
30
31 =head1 DESCRIPTION
32
8ebc5c01 33 This page provides a brief table of contents for the rest of the Perl
28757baa 34 documentation set. It is meant to be scanned quickly or grepped
cb1a09d0 35 through to locate the proper section you're looking for.
36
37 =head1 BASIC DOCUMENTATION
38
39EOPOD2B
8ebc5c01 40#' make emacs happy
cb1a09d0 41
42podset(@pods);
43
44find \&getpods => qw(../lib ../ext);
8ebc5c01 45
cb1a09d0 46sub getpods {
8ebc5c01 47 if (/\.p(od|m)$/) {
903a5071 48 # Skip .pm files that have corresponding .pod files, and Functions.pm.
8ebc5c01 49 return if /(.*)\.pm$/ && -f "$1.pod";
cb1a09d0 50 my $file = $File::Find::name;
8ebc5c01 51 return if $file eq '../lib/Pod/Functions.pm'; # Used only by pod itself
52
cb1a09d0 53 die "tut $name" if $file =~ /TUT/;
54 unless (open (F, "< $_\0")) {
55 warn "bogus <$file>: $!";
56 system "ls", "-l", $file;
8ebc5c01 57 }
58 else {
cb1a09d0 59 my $line;
60 while ($line = <F>) {
61 if ($line =~ /^=head1\s+NAME\b/) {
62 push @modpods, $file;
63 #warn "GOOD $file\n";
64 return;
8ebc5c01 65 }
66 }
cb1a09d0 67 warn "EVIL $file\n";
68 }
69 }
70}
71
72die "no pods" unless @modpods;
73
74for (@modpods) {
75 #($name) = /(\w+)\.p(m|od)$/;
76 $name = path2modname($_);
77 if ($name =~ /^[a-z]/) {
78 push @pragmata, $_;
79 } else {
80 if ($done{$name}++) {
81 # warn "already did $_\n";
82 next;
8ebc5c01 83 }
cb1a09d0 84 push @modules, $_;
85 push @modname, $name;
8ebc5c01 86 }
87}
88
89($_= <<EOPOD2B) =~ s/^\t//gm && output($_);
cb1a09d0 90
cb1a09d0 91
92
93 =head1 PRAGMA DOCUMENTATION
94
95EOPOD2B
96
97podset(sort @pragmata);
98
8ebc5c01 99($_= <<EOPOD2B) =~ s/^\t//gm && output($_);
100
cb1a09d0 101
102
103 =head1 MODULE DOCUMENTATION
104
105EOPOD2B
106
107podset( @modules[ sort { $modname[$a] cmp $modname[$b] } 0 .. $#modules ] );
108
109($_= <<EOPOD2B) =~ s/^\t//gm;
8ebc5c01 110
cb1a09d0 111
112 =head1 AUXILIARY DOCUMENTATION
113
8ebc5c01 114 Here should be listed all the extra programs' documentation, but they
115 don't all have manual pages yet:
cb1a09d0 116
a45bd81d 117 =over
118
cb1a09d0 119 =item a2p
120
121 =item s2p
122
123 =item find2perl
8ebc5c01 124
cb1a09d0 125 =item h2ph
8ebc5c01 126
cb1a09d0 127 =item c2ph
128
129 =item h2xs
130
131 =item xsubpp
132
8ebc5c01 133 =item pod2man
cb1a09d0 134
135 =item wrapsuid
136
a45bd81d 137 =back
cb1a09d0 138
139 =head1 AUTHOR
140
352854fa 141 Larry Wall <F<larry\@wall.org>>, with the help of oodles
cb1a09d0 142 of other folks.
143
144
145EOPOD2B
8ebc5c01 146output $_;
147output "\n"; # flush $LINE
cb1a09d0 148exit;
149
150sub podset {
151 local @ARGV = @_;
152
153 while(<>) {
154 if (s/^=head1 (NAME)\s*/=head2 /) {
155 $pod = path2modname($ARGV);
a45bd81d 156 unhead1();
8ebc5c01 157 output "\n \n\n=head2 ";
cb1a09d0 158 $_ = <>;
159 if ( /^\s*$pod\b/ ) {
8ebc5c01 160 s/$pod\.pm/$pod/; # '.pm' in NAME !?
161 output $_;
cb1a09d0 162 } else {
163 s/^/$pod, /;
8ebc5c01 164 output $_;
165 }
cb1a09d0 166 next;
167 }
168 if (s/^=head1 (.*)/=item $1/) {
a45bd81d 169 unhead2();
170 output "=over\n\n" unless $inhead1;
171 $inhead1 = 1;
8ebc5c01 172 output $_; nl(); next;
173 }
cb1a09d0 174 if (s/^=head2 (.*)/=item $1/) {
175 unitem();
8ebc5c01 176 output "=over\n\n" unless $inhead2;
cb1a09d0 177 $inhead2 = 1;
8ebc5c01 178 output $_; nl(); next;
8ebc5c01 179 }
74940639 180 if (s/^=item ([^=].*)/$1/) {
cb1a09d0 181 next if $pod eq 'perldiag';
182 s/^\s*\*\s*$// && next;
183 s/^\s*\*\s*//;
74940639 184 s/\n/ /g;
cb1a09d0 185 s/\s+$//;
186 next if /^[\d.]+$/;
f102b883 187 next if $pod eq 'perlmodlib' && /^ftp:/;
cb1a09d0 188 ##print "=over\n\n" unless $initem;
8ebc5c01 189 output ", " if $initem;
cb1a09d0 190 $initem = 1;
191 s/\.$//;
8ebc5c01 192 s/^-X\b/-I<X>/;
193 output $_; next;
194 }
a45bd81d 195 if (s/^=cut\s*\n//) {
196 unhead1();
197 next;
198 }
8ebc5c01 199 }
200}
cb1a09d0 201
8ebc5c01 202sub path2modname {
203 local $_ = shift;
204 s/\.p(m|od)$//;
205 s-.*?/(lib|ext)/--;
206 s-/-::-g;
207 s/(\w+)::\1/$1/;
208 return $_;
209}
cb1a09d0 210
a45bd81d 211sub unhead1 {
212 unhead2();
213 if ($inhead1) {
214 output "\n\n=back\n\n";
215 }
216 $inhead1 = 0;
217}
218
cb1a09d0 219sub unhead2 {
a45bd81d 220 unitem();
cb1a09d0 221 if ($inhead2) {
8ebc5c01 222 output "\n\n=back\n\n";
223 }
224 $inhead2 = 0;
8ebc5c01 225}
cb1a09d0 226
227sub unitem {
228 if ($initem) {
8ebc5c01 229 output "\n\n";
cb1a09d0 230 ##print "\n\n=back\n\n";
8ebc5c01 231 }
cb1a09d0 232 $initem = 0;
8ebc5c01 233}
cb1a09d0 234
235sub nl {
8ebc5c01 236 output "\n";
237}
238
239my $NEWLINE; # how many newlines have we seen recently
240my $LINE; # what remains to be printed
241
242sub output ($) {
243 for (split /(\n)/, shift) {
244 if ($_ eq "\n") {
245 if ($LINE) {
246 print wrap('', '', $LINE);
247 $LINE = '';
248 }
249 if ($NEWLINE < 2) {
250 print;
251 $NEWLINE++;
252 }
253 }
254 elsif (/\S/ && length) {
255 $LINE .= $_;
256 $NEWLINE = 0;
257 }
258 }
259}