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