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