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 |
7766f137 |
11 | perlmod perlmodlib perlmodinstall perlfork perlform perllocale |
a1e2a320 |
12 | perlref perlreftut perldsc |
19799a22 |
13 | perllol perltoot perltootc perlobj perltie perlbot perlipc |
14 | perldbmfilter perldebug |
fb9cefb4 |
15 | perldiag perlsec perltrap perlport perlstyle perlpod perlbook |
54a137f5 |
16 | perlembed perlapio perlxs perlxstut perlguts perlcall perlcompile |
d516a115 |
17 | perlhist |
8ebc5c01 |
18 | ); |
19 | |
20 | for (@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 | |
39 | EOPOD2B |
8ebc5c01 |
40 | #' make emacs happy |
cb1a09d0 |
41 | |
42 | podset(@pods); |
43 | |
44 | find \&getpods => qw(../lib ../ext); |
8ebc5c01 |
45 | |
cb1a09d0 |
46 | sub 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 | |
72 | die "no pods" unless @modpods; |
73 | |
74 | for (@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 | |
95 | EOPOD2B |
96 | |
97 | podset(sort @pragmata); |
98 | |
8ebc5c01 |
99 | ($_= <<EOPOD2B) =~ s/^\t//gm && output($_); |
100 | |
cb1a09d0 |
101 | |
102 | |
103 | =head1 MODULE DOCUMENTATION |
104 | |
105 | EOPOD2B |
106 | |
107 | podset( @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 | |
117 | =item a2p |
118 | |
119 | =item s2p |
120 | |
121 | =item find2perl |
8ebc5c01 |
122 | |
cb1a09d0 |
123 | =item h2ph |
8ebc5c01 |
124 | |
cb1a09d0 |
125 | =item c2ph |
126 | |
127 | =item h2xs |
128 | |
129 | =item xsubpp |
130 | |
8ebc5c01 |
131 | =item pod2man |
cb1a09d0 |
132 | |
133 | =item wrapsuid |
134 | |
135 | |
136 | =head1 AUTHOR |
137 | |
352854fa |
138 | Larry Wall <F<larry\@wall.org>>, with the help of oodles |
cb1a09d0 |
139 | of other folks. |
140 | |
141 | |
142 | EOPOD2B |
8ebc5c01 |
143 | output $_; |
144 | output "\n"; # flush $LINE |
cb1a09d0 |
145 | exit; |
146 | |
147 | sub podset { |
148 | local @ARGV = @_; |
149 | |
150 | while(<>) { |
151 | if (s/^=head1 (NAME)\s*/=head2 /) { |
152 | $pod = path2modname($ARGV); |
8ebc5c01 |
153 | unitem(); |
154 | unhead2(); |
155 | output "\n \n\n=head2 "; |
cb1a09d0 |
156 | $_ = <>; |
157 | if ( /^\s*$pod\b/ ) { |
8ebc5c01 |
158 | s/$pod\.pm/$pod/; # '.pm' in NAME !? |
159 | output $_; |
cb1a09d0 |
160 | } else { |
161 | s/^/$pod, /; |
8ebc5c01 |
162 | output $_; |
163 | } |
cb1a09d0 |
164 | next; |
165 | } |
166 | if (s/^=head1 (.*)/=item $1/) { |
167 | unitem(); unhead2(); |
8ebc5c01 |
168 | output $_; nl(); next; |
169 | } |
cb1a09d0 |
170 | if (s/^=head2 (.*)/=item $1/) { |
171 | unitem(); |
8ebc5c01 |
172 | output "=over\n\n" unless $inhead2; |
cb1a09d0 |
173 | $inhead2 = 1; |
8ebc5c01 |
174 | output $_; nl(); next; |
cb1a09d0 |
175 | |
8ebc5c01 |
176 | } |
d516a115 |
177 | if (s/^=item ([^=].*)\n/$1/) { |
cb1a09d0 |
178 | next if $pod eq 'perldiag'; |
179 | s/^\s*\*\s*$// && next; |
180 | s/^\s*\*\s*//; |
181 | s/\s+$//; |
182 | next if /^[\d.]+$/; |
f102b883 |
183 | next if $pod eq 'perlmodlib' && /^ftp:/; |
cb1a09d0 |
184 | ##print "=over\n\n" unless $initem; |
8ebc5c01 |
185 | output ", " if $initem; |
cb1a09d0 |
186 | $initem = 1; |
187 | s/\.$//; |
8ebc5c01 |
188 | s/^-X\b/-I<X>/; |
189 | output $_; next; |
190 | } |
191 | } |
192 | } |
cb1a09d0 |
193 | |
8ebc5c01 |
194 | sub path2modname { |
195 | local $_ = shift; |
196 | s/\.p(m|od)$//; |
197 | s-.*?/(lib|ext)/--; |
198 | s-/-::-g; |
199 | s/(\w+)::\1/$1/; |
200 | return $_; |
201 | } |
cb1a09d0 |
202 | |
203 | sub unhead2 { |
204 | if ($inhead2) { |
8ebc5c01 |
205 | output "\n\n=back\n\n"; |
206 | } |
207 | $inhead2 = 0; |
208 | $initem = 0; |
209 | } |
cb1a09d0 |
210 | |
211 | sub unitem { |
212 | if ($initem) { |
8ebc5c01 |
213 | output "\n\n"; |
cb1a09d0 |
214 | ##print "\n\n=back\n\n"; |
8ebc5c01 |
215 | } |
cb1a09d0 |
216 | $initem = 0; |
8ebc5c01 |
217 | } |
cb1a09d0 |
218 | |
219 | sub nl { |
8ebc5c01 |
220 | output "\n"; |
221 | } |
222 | |
223 | my $NEWLINE; # how many newlines have we seen recently |
224 | my $LINE; # what remains to be printed |
225 | |
226 | sub output ($) { |
227 | for (split /(\n)/, shift) { |
228 | if ($_ eq "\n") { |
229 | if ($LINE) { |
230 | print wrap('', '', $LINE); |
231 | $LINE = ''; |
232 | } |
233 | if ($NEWLINE < 2) { |
234 | print; |
235 | $NEWLINE++; |
236 | } |
237 | } |
238 | elsif (/\S/ && length) { |
239 | $LINE .= $_; |
240 | $NEWLINE = 0; |
241 | } |
242 | } |
243 | } |