This repository was archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpodtohtml
More file actions
executable file
·272 lines (201 loc) · 5.2 KB
/
podtohtml
File metadata and controls
executable file
·272 lines (201 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/local/bin/new/perl -w
use 5.004;
use strict;
use Pod::Find qw(pod_find);
use Pod::Links;
use Pod::Usage;
use Pod::HTML_Elements;
use Getopt::Std;
use File::Basename;
use File::Path;
use Carp;
use Cwd;
use Config;
$SIG{__DIE__} = \&confess;
my %opt = ('s' => '.html','d' => 'html');
getopts('bhqISvd:ps:Di:',\%opt);
pod2usage( -verbose => ($opt{'v'}) ? 1 : 0, -exitval => 0) if $opt{'h'};
my $here = getcwd();
mkpath($opt{'d'},1,0777) unless -d $opt{'d'};
chdir($opt{'d'}) || die "Cannot cd to $opt{'d'}:$!";
$opt{'d'} = getcwd();
chdir($here) || die "Cannot cd back to $here:$!";
my @pods;
sub add_dir
{
my $dir = shift;
if (chdir($dir))
{
my %pods = pod_find( {}, getcwd());
push @pods, keys %{ { pod_find( {}, getcwd())} };
chdir($here) || die "Cannot cd back to $here:$!";
}
else
{
warn "Cannot cd to $dir:$!";
}
}
if (@ARGV)
{
foreach my $dir (@ARGV)
{
if (-d $dir)
{
add_dir($dir);
}
elsif (-f $dir && contains_pod($dir)) # XXX
{
push(@pods,$dir);
}
}
}
add_dir($Config{'scriptdirexp'}) if ($opt{'S'});
if ($opt{'I'})
{
foreach my $dir (@INC)
{
add_dir($dir);
}
}
require Data::Dumper if $opt{'D'};
my @args = ();
my $sfx = $opt{'s'};
if ($opt{'p'})
{
push(@args,PostScript => 1);
$sfx = '.ps';
}
if ($opt{'D'})
{
push(@args,Dump => 1);
$sfx = '.dmp';
}
push(@args,Index => $opt{'i'}) if (defined $opt{'i'});
if (@pods)
{
warn "Pre-Scan for links\n" unless $opt{'q'};
my $links = new Pod::Links Verbose => $opt{'v'};
foreach my $pod (@pods)
{
$links->parse_from_file($pod);
}
foreach my $name ($links->names)
{
my $file = $links->pod($name);
if (defined $file || ($opt{'b'} && $name =~ /^\w(?:\w|::)+\w$/))
{
warn "Creating broken links to $name\n" unless $opt{'q'} || defined $file;
my $outfile = $name;
$outfile =~ s#::#/#g;
$outfile =~ s#[^/a-z0-9A-Z._-]##g;
$outfile .= $sfx;
$outfile = $opt{'d'}."/$outfile" if defined $opt{'d'};
$links->link($name,$outfile);
print "$name => $outfile\n" if $opt{'v'};
}
}
my $parser = new Pod::HTML_Elements @args, Links => $links;
warn "Generating Output\n" unless $opt{'q'};
foreach my $name ($links->names)
{
my $file = $links->pod($name);
my $outfile = $links->link($name);
if (defined $file)
{
print "$file => $outfile\n" if $opt{'v'};
mkpath(File::Basename::dirname($outfile),1,0777);
$parser->parse_from_file($file,$outfile);
}
}
$parser->write_index;
}
else
{
}
sub contains_pod
{
my $file = shift;
local $/ = '';
my $pod = 0;
if (open(POD,"<$file"))
{
local $_;
while (<POD>)
{
if ($pod = /^=head\d\s/)
{
last;
}
}
close(POD);
}
else
{
warn "Cannot open $file:$!\n";
}
return $pod;
}
__END__
=head1 NAME
podtohtml - (DEPRECATED) convert POD documentation to HTML
=head1 SYNOPSIS
THIS IS A DEPRECATED PROGRAM. See Pod::Simple::HTML instead.
podtohtml [-bhqvIS] [-i index] [-d outdirectory] [-s sfx] <pods or directories of pods...>
=head1 DESCRIPTION
THIS IS A DEPRECATED PROGRAM.
C<podtohtml> converts POD documentation to HTML. It is based on
the generic L<Pod::Parser>. It works by making two passes over the
selected pods, the fisrt pass uses L<Pod::Links> to pre-scan for
LE<lt>E<gt> links and C<=head1 NAME> sections, and then a second to build a tree
of L<HTML::Element>s for each POD and calling the C<as_HTML> method on
the resulting tree.
The Generated HTML uses relative links.
=head1 OPTIONS
The following command line options affect the behaviour:
=over 4
=item -b
Create broken links
=item -d I<outdirectory>
The directory into which the HTML is written.
=item -q
Run as quietly as possible
=item -v
Verbose - print messages about files being processed.
=item -s I<suffix>
Set the suffix for generated files. Default is '.html' for HTML files
and '.ps' for PostScript files.
=item -i I<index>
Build an index file in I<index>.
=item -I
Search perl's C<@INC> for pods. Heuristics implemented in L<Pod::Find>
attempt to restrict search to files related to the version of perl
executing the script.
=item -S
Search directory that is specified in C<Config> as install location
of scripts for pods.
=item -p
Generate PostScript rather than HTML. This is done using L<HTML::FormatPS>
and font sizes etc. are not yet specifiable.
=item -D
Print L<Data::Dumper> dump of generated tree rather than generating HTML
(for debugging).
=back
=head1 EXAMPLES
=head2 Build HTML for all installed modules and associated scripts :
podtohtml -I -S -d "/home/WWW/perl" -i "/home/WWW/perl/index.html"
That takes rather a long time (22 minutes on my 60MHz SPARCStation10).
=head2 Build HTML for unistalled Tk extension:
podtohtml -d "/home/WWW/Tk8" -i /home/WWW/TkIndex.html ~/Tk8/pod
=head1 BUGS
THIS IS A DEPRECATED PROGRAM. THESE BUGS WILL NOT BE FIXED.
=over 4
=item * Active links are only built for pods processed in the same invocation.
=item * Large documents are not split.
=item * L<HTML::FormatPS>'s style does not suit Nick's taste.
=item * The index file needs more structure.
=back
=head1 SEE ALSO
L<Pod::Simple::HTML>
=head1 AUTHOR
Nick Ing-Simmons <nick@ni-s.u-net.com>
=cut