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