| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
require 5.006; |
|
2
|
|
|
|
|
|
|
package Pod::Perldoc::ToMan; |
|
3
|
2
|
|
|
2
|
|
14164
|
use strict; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
43
|
|
|
4
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
|
2
|
|
|
|
|
1
|
|
|
|
2
|
|
|
|
|
41
|
|
|
5
|
2
|
|
|
2
|
|
6
|
use parent qw(Pod::Perldoc::BaseTo); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
74
|
use vars qw($VERSION); |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
71
|
|
|
8
|
|
|
|
|
|
|
$VERSION = '3.27'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
6
|
use File::Spec::Functions qw(catfile); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
79
|
|
|
11
|
2
|
|
|
2
|
|
576
|
use Pod::Man 2.18; |
|
|
2
|
|
|
|
|
35328
|
|
|
|
2
|
|
|
|
|
2806
|
|
|
12
|
|
|
|
|
|
|
# This class is unlike ToText.pm et al, because we're NOT paging thru |
|
13
|
|
|
|
|
|
|
# the output in our particular format -- we make the output and |
|
14
|
|
|
|
|
|
|
# then we run nroff (or whatever) on it, and then page thru the |
|
15
|
|
|
|
|
|
|
# (plaintext) output of THAT! |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub SUCCESS () { 1 } |
|
18
|
|
|
|
|
|
|
sub FAILED () { 0 } |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
0
|
0
|
sub is_pageable { 1 } |
|
21
|
0
|
|
|
0
|
0
|
0
|
sub write_with_binmode { 0 } |
|
22
|
0
|
|
|
0
|
0
|
0
|
sub output_extension { 'txt' } |
|
23
|
|
|
|
|
|
|
|
|
24
|
0
|
|
|
0
|
|
0
|
sub __filter_nroff { shift->_perldoc_elem('__filter_nroff' , @_) } |
|
25
|
0
|
|
|
0
|
|
0
|
sub __nroffer { shift->_perldoc_elem('__nroffer' , @_) } |
|
26
|
0
|
|
|
0
|
|
0
|
sub __bindir { shift->_perldoc_elem('__bindir' , @_) } |
|
27
|
0
|
|
|
0
|
|
0
|
sub __pod2man { shift->_perldoc_elem('__pod2man' , @_) } |
|
28
|
0
|
|
|
0
|
|
0
|
sub __output_file { shift->_perldoc_elem('__output_file' , @_) } |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
|
0
|
0
|
0
|
sub center { shift->_perldoc_elem('center' , @_) } |
|
31
|
0
|
|
|
0
|
0
|
0
|
sub date { shift->_perldoc_elem('date' , @_) } |
|
32
|
0
|
|
|
0
|
0
|
0
|
sub fixed { shift->_perldoc_elem('fixed' , @_) } |
|
33
|
0
|
|
|
0
|
0
|
0
|
sub fixedbold { shift->_perldoc_elem('fixedbold' , @_) } |
|
34
|
0
|
|
|
0
|
0
|
0
|
sub fixeditalic { shift->_perldoc_elem('fixeditalic' , @_) } |
|
35
|
0
|
|
|
0
|
0
|
0
|
sub fixedbolditalic { shift->_perldoc_elem('fixedbolditalic', @_) } |
|
36
|
0
|
|
|
0
|
0
|
0
|
sub name { shift->_perldoc_elem('name' , @_) } |
|
37
|
0
|
|
|
0
|
0
|
0
|
sub quotes { shift->_perldoc_elem('quotes' , @_) } |
|
38
|
0
|
|
|
0
|
0
|
0
|
sub release { shift->_perldoc_elem('release' , @_) } |
|
39
|
0
|
|
|
0
|
0
|
0
|
sub section { shift->_perldoc_elem('section' , @_) } |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new { |
|
42
|
0
|
|
|
0
|
0
|
0
|
my( $either ) = shift; |
|
43
|
0
|
|
0
|
|
|
0
|
my $self = bless {}, ref($either) || $either; |
|
44
|
0
|
|
|
|
|
0
|
$self->init( @_ ); |
|
45
|
0
|
|
|
|
|
0
|
return $self; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub init { |
|
49
|
0
|
|
|
0
|
0
|
0
|
my( $self, @args ) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
0
|
unless( $self->__nroffer ) { |
|
52
|
0
|
|
|
|
|
0
|
my $roffer = $self->_find_roffer( $self->_roffer_candidates ); |
|
53
|
0
|
|
|
|
|
0
|
$self->debug( "Using $roffer\n" ); |
|
54
|
0
|
|
|
|
|
0
|
$self->__nroffer( $roffer ); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
else { |
|
57
|
0
|
|
|
|
|
0
|
$self->debug( "__nroffer is " . $self->__nroffer() . "\n" ); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
$self->_check_nroffer; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _roffer_candidates { |
|
64
|
0
|
|
|
0
|
|
0
|
my( $self ) = @_; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
0
|
0
|
|
|
0
|
if( $self->is_openbsd || $self->is_freebsd || $self->is_bitrig ) { qw( mandoc groff nroff ) } |
|
|
0
|
|
0
|
|
|
0
|
|
|
67
|
0
|
|
|
|
|
0
|
else { qw( groff nroff mandoc ) } |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _find_roffer { |
|
71
|
0
|
|
|
0
|
|
0
|
my( $self, @candidates ) = @_; |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
my @found = (); |
|
74
|
0
|
|
|
|
|
0
|
foreach my $candidate ( @candidates ) { |
|
75
|
0
|
|
|
|
|
0
|
push @found, $self->_find_executable_in_path( $candidate ); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
0
|
return wantarray ? @found : $found[0]; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _check_nroffer { |
|
82
|
0
|
|
|
0
|
|
0
|
return 1; |
|
83
|
|
|
|
|
|
|
# where is it in the PATH? |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# is it executable? |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# what is its real name? |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# what is its version? |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# does it support the flags we need? |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# is it good enough for us? |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
0
|
|
0
|
sub _get_stty { `stty -a` } |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _get_columns_from_stty { |
|
99
|
22
|
|
|
22
|
|
49
|
my $output = $_[0]->_get_stty; |
|
100
|
|
|
|
|
|
|
|
|
101
|
22
|
100
|
|
|
|
116
|
if( $output =~ /\bcolumns\s+(\d+)/ ) { return $1 } |
|
|
10
|
100
|
|
|
|
41
|
|
|
102
|
6
|
|
|
|
|
28
|
elsif( $output =~ /;\s*(\d+)\s+columns;/ ) { return $1 } |
|
103
|
6
|
|
|
|
|
23
|
else { return 0 } |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _get_columns_from_manwidth { |
|
107
|
24
|
|
|
24
|
|
4100
|
my( $self ) = @_; |
|
108
|
|
|
|
|
|
|
|
|
109
|
24
|
100
|
|
|
|
94
|
return 0 unless defined $ENV{MANWIDTH}; |
|
110
|
|
|
|
|
|
|
|
|
111
|
10
|
100
|
|
|
|
32
|
unless( $ENV{MANWIDTH} =~ m/\A\d+\z/ ) { |
|
112
|
6
|
|
|
|
|
19
|
$self->warn( "Ignoring non-numeric MANWIDTH ($ENV{MANWIDTH})\n" ); |
|
113
|
6
|
|
|
|
|
31
|
return 0; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
4
|
50
|
|
|
|
8
|
if( $ENV{MANWIDTH} == 0 ) { |
|
117
|
0
|
|
|
|
|
0
|
$self->warn( "Ignoring MANWIDTH of 0. Really? Why even run the program? :)\n" ); |
|
118
|
0
|
|
|
|
|
0
|
return 0; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
4
|
50
|
|
|
|
10
|
if( $ENV{MANWIDTH} =~ m/\A(\d+)\z/ ) { return $1 } |
|
|
4
|
|
|
|
|
15
|
|
|
122
|
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
0
|
return 0; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub _get_default_width { |
|
127
|
3
|
|
|
3
|
|
10
|
73 |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _get_columns { |
|
131
|
12
|
100
|
100
|
12
|
|
26
|
$_[0]->_get_columns_from_manwidth || |
|
132
|
|
|
|
|
|
|
$_[0]->_get_columns_from_stty || |
|
133
|
|
|
|
|
|
|
$_[0]->_get_default_width; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _get_podman_switches { |
|
137
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my @switches = map { $_, $self->{$_} } grep !m/^_/s, keys %$self; |
|
|
0
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# There needs to be a cleaner way to handle setting |
|
142
|
|
|
|
|
|
|
# the UTF-8 flag, but for now, comment out this |
|
143
|
|
|
|
|
|
|
# line because it often does the wrong thing. |
|
144
|
|
|
|
|
|
|
# |
|
145
|
|
|
|
|
|
|
# See RT #77465 |
|
146
|
|
|
|
|
|
|
# |
|
147
|
|
|
|
|
|
|
#push @switches, 'utf8' => 1; |
|
148
|
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
$self->debug( "Pod::Man switches are [@switches]\n" ); |
|
150
|
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
return @switches; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub _parse_with_pod_man { |
|
155
|
0
|
|
|
0
|
|
|
my( $self, $file ) = @_; |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
#->output_fh and ->output_string from Pod::Simple aren't |
|
158
|
|
|
|
|
|
|
# working, apparently, so there's this ugly hack: |
|
159
|
0
|
|
|
|
|
|
local *STDOUT; |
|
160
|
0
|
|
|
|
|
|
open STDOUT, '>', $self->{_text_ref}; |
|
161
|
0
|
|
|
|
|
|
my $parser = Pod::Man->new( $self->_get_podman_switches ); |
|
162
|
0
|
|
|
|
|
|
$self->debug( "Parsing $file\n" ); |
|
163
|
0
|
|
|
|
|
|
$parser->parse_from_file( $file ); |
|
164
|
0
|
|
|
|
|
|
$self->debug( "Done parsing $file\n" ); |
|
165
|
0
|
|
|
|
|
|
close STDOUT; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
$self->die( "No output from Pod::Man!\n" ) |
|
168
|
0
|
0
|
|
|
|
|
unless length $self->{_text_ref}; |
|
169
|
|
|
|
|
|
|
|
|
170
|
0
|
0
|
|
|
|
|
$self->_save_pod_man_output if $self->debugging; |
|
171
|
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
return SUCCESS; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub _save_pod_man_output { |
|
176
|
0
|
|
|
0
|
|
|
my( $self, $fh ) = @_; |
|
177
|
|
|
|
|
|
|
|
|
178
|
0
|
0
|
|
|
|
|
$fh = do { |
|
179
|
0
|
|
|
|
|
|
my $file = "podman.out.$$.txt"; |
|
180
|
0
|
|
|
|
|
|
$self->debug( "Writing $file with Pod::Man output\n" ); |
|
181
|
0
|
|
|
|
|
|
open my $fh2, '>', $file; |
|
182
|
0
|
|
|
|
|
|
$fh2; |
|
183
|
|
|
|
|
|
|
} unless $fh; |
|
184
|
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
print { $fh } ${ $self->{_text_ref} }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub _have_groff_with_utf8 { |
|
189
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
190
|
|
|
|
|
|
|
|
|
191
|
0
|
0
|
|
|
|
|
return 0 unless $self->_is_groff; |
|
192
|
0
|
|
|
|
|
|
my $roffer = $self->__nroffer; |
|
193
|
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
my $minimum_groff_version = '1.20.1'; |
|
195
|
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
my $version_string = `$roffer -v`; |
|
197
|
0
|
|
|
|
|
|
my( $version ) = $version_string =~ /\(?groff\)? version (\d+\.\d+(?:\.\d+)?)/; |
|
198
|
0
|
|
|
|
|
|
$self->debug( "Found groff $version\n" ); |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# is a string comparison good enough? |
|
201
|
0
|
0
|
|
|
|
|
if( $version lt $minimum_groff_version ) { |
|
202
|
0
|
|
|
|
|
|
$self->warn( |
|
203
|
|
|
|
|
|
|
"You have an old groff." . |
|
204
|
|
|
|
|
|
|
" Update to version $minimum_groff_version for good Unicode support.\n" . |
|
205
|
|
|
|
|
|
|
"If you don't upgrade, wide characters may come out oddly.\n" |
|
206
|
|
|
|
|
|
|
); |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
$version ge $minimum_groff_version; |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub _have_mandoc_with_utf8 { |
|
213
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
214
|
|
|
|
|
|
|
|
|
215
|
0
|
0
|
|
|
|
|
$self->_is_mandoc and not system 'mandoc -Tlocale -V > /dev/null 2>&1'; |
|
216
|
|
|
|
|
|
|
} |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub _collect_nroff_switches { |
|
219
|
0
|
|
|
0
|
|
|
my( $self ) = shift; |
|
220
|
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
my @render_switches = ('-man', $self->_get_device_switches); |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
# Thanks to Brendan O'Dea for contributing the following block |
|
224
|
0
|
0
|
0
|
|
|
|
if( $self->_is_roff and -t STDOUT and my ($cols) = $self->_get_columns ) { |
|
|
|
|
0
|
|
|
|
|
|
225
|
0
|
|
|
|
|
|
my $c = $cols * 39 / 40; |
|
226
|
0
|
0
|
|
|
|
|
$cols = $c > $cols - 2 ? $c : $cols -2; |
|
227
|
0
|
0
|
|
|
|
|
push @render_switches, '-rLL=' . (int $c) . 'n' if $cols > 80; |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# I hear persistent reports that adding a -c switch to $render |
|
231
|
|
|
|
|
|
|
# solves many people's problems. But I also hear that some mans |
|
232
|
|
|
|
|
|
|
# don't have a -c switch, so that unconditionally adding it here |
|
233
|
|
|
|
|
|
|
# would presumably be a Bad Thing -- sburke@cpan.org |
|
234
|
0
|
0
|
0
|
|
|
|
push @render_switches, '-c' if( $self->_is_roff and $self->is_cygwin ); |
|
235
|
|
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
return @render_switches; |
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub _get_device_switches { |
|
240
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
241
|
|
|
|
|
|
|
|
|
242
|
0
|
0
|
|
|
|
|
if( $self->_is_nroff ) { qw() } |
|
|
0
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
243
|
0
|
|
|
|
|
|
elsif( $self->_have_groff_with_utf8 ) { qw(-Kutf8 -Tutf8) } |
|
244
|
0
|
|
|
|
|
|
elsif( $self->_is_ebcdic ) { qw(-Tcp1047) } |
|
245
|
0
|
|
|
|
|
|
elsif( $self->_have_mandoc_with_utf8 ) { qw(-Tlocale) } |
|
246
|
0
|
|
|
|
|
|
elsif( $self->_is_mandoc ) { qw() } |
|
247
|
0
|
|
|
|
|
|
else { qw(-Tlatin1) } |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub _is_roff { |
|
251
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
252
|
|
|
|
|
|
|
|
|
253
|
0
|
0
|
|
|
|
|
$self->_is_nroff or $self->_is_groff; |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub _is_nroff { |
|
257
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
258
|
|
|
|
|
|
|
|
|
259
|
0
|
|
|
|
|
|
$self->__nroffer =~ /\bnroff\b/; |
|
260
|
|
|
|
|
|
|
} |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
sub _is_groff { |
|
263
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
264
|
|
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
|
$self->__nroffer =~ /\bgroff\b/; |
|
266
|
|
|
|
|
|
|
} |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub _is_mandoc { |
|
269
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
270
|
|
|
|
|
|
|
|
|
271
|
0
|
|
|
|
|
|
$self->__nroffer =~ /\bmandoc\b/; |
|
272
|
|
|
|
|
|
|
} |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
sub _is_ebcdic { |
|
275
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
276
|
|
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
|
return 0; |
|
278
|
|
|
|
|
|
|
} |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
sub _filter_through_nroff { |
|
281
|
0
|
|
|
0
|
|
|
my( $self ) = shift; |
|
282
|
0
|
|
|
|
|
|
$self->debug( "Filtering through " . $self->__nroffer() . "\n" ); |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
# Maybe someone set rendering switches as part of the opt_n value |
|
285
|
|
|
|
|
|
|
# Deal with that here. |
|
286
|
|
|
|
|
|
|
|
|
287
|
0
|
|
|
|
|
|
my ($render, $switches) = $self->__nroffer() =~ /\A([\/a-zA-Z0-9_\.-]+)\b(.+)?\z/; |
|
288
|
|
|
|
|
|
|
|
|
289
|
0
|
0
|
|
|
|
|
$self->die("no nroffer!?") unless $render; |
|
290
|
0
|
|
|
|
|
|
my @render_switches = $self->_collect_nroff_switches; |
|
291
|
|
|
|
|
|
|
|
|
292
|
0
|
0
|
|
|
|
|
if ( $switches ) { |
|
293
|
|
|
|
|
|
|
# Eliminate whitespace |
|
294
|
0
|
|
|
|
|
|
$switches =~ s/\s//g; |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
# Then separate the switches with a zero-width positive |
|
297
|
|
|
|
|
|
|
# lookahead on the dash. |
|
298
|
|
|
|
|
|
|
# |
|
299
|
|
|
|
|
|
|
# See: |
|
300
|
|
|
|
|
|
|
# http://www.effectiveperlprogramming.com/blog/1411 |
|
301
|
|
|
|
|
|
|
# for a good discussion of this technique |
|
302
|
|
|
|
|
|
|
|
|
303
|
0
|
|
|
|
|
|
push @render_switches, split(/(?=-)/, $switches); |
|
304
|
|
|
|
|
|
|
} |
|
305
|
|
|
|
|
|
|
|
|
306
|
0
|
|
|
|
|
|
$self->debug( "render is $render\n" ); |
|
307
|
0
|
|
|
|
|
|
$self->debug( "render options are @render_switches\n" ); |
|
308
|
|
|
|
|
|
|
|
|
309
|
0
|
|
|
|
|
|
require Symbol; |
|
310
|
0
|
|
|
|
|
|
require IPC::Open3; |
|
311
|
0
|
|
|
|
|
|
require IO::Handle; |
|
312
|
|
|
|
|
|
|
|
|
313
|
0
|
|
|
|
|
|
my $pid = IPC::Open3::open3( |
|
314
|
|
|
|
|
|
|
my $writer, |
|
315
|
|
|
|
|
|
|
my $reader, |
|
316
|
|
|
|
|
|
|
my $err = Symbol::gensym(), |
|
317
|
|
|
|
|
|
|
$render, |
|
318
|
|
|
|
|
|
|
@render_switches |
|
319
|
|
|
|
|
|
|
); |
|
320
|
|
|
|
|
|
|
|
|
321
|
0
|
|
|
|
|
|
$reader->autoflush(1); |
|
322
|
|
|
|
|
|
|
|
|
323
|
2
|
|
|
2
|
|
844
|
use IO::Select; |
|
|
2
|
|
|
|
|
2067
|
|
|
|
2
|
|
|
|
|
1440
|
|
|
324
|
0
|
|
|
|
|
|
my $selector = IO::Select->new( $reader ); |
|
325
|
|
|
|
|
|
|
|
|
326
|
0
|
|
|
|
|
|
$self->debug( "Writing to pipe to $render\n" ); |
|
327
|
|
|
|
|
|
|
|
|
328
|
0
|
|
|
|
|
|
my $offset = 0; |
|
329
|
0
|
|
|
|
|
|
my $chunk_size = 4096; |
|
330
|
0
|
|
|
|
|
|
my $length = length( ${ $self->{_text_ref} } ); |
|
|
0
|
|
|
|
|
|
|
|
331
|
0
|
|
|
|
|
|
my $chunks = $length / $chunk_size; |
|
332
|
0
|
|
|
|
|
|
my $done; |
|
333
|
|
|
|
|
|
|
my $buffer; |
|
334
|
0
|
|
|
|
|
|
while( $offset <= $length ) { |
|
335
|
0
|
|
|
|
|
|
$self->debug( "Writing chunk $chunks\n" ); $chunks++; |
|
|
0
|
|
|
|
|
|
|
|
336
|
0
|
0
|
|
|
|
|
syswrite $writer, ${ $self->{_text_ref} }, $chunk_size, $offset |
|
|
0
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
or $self->die( $! ); |
|
338
|
0
|
|
|
|
|
|
$offset += $chunk_size; |
|
339
|
0
|
|
|
|
|
|
$self->debug( "Checking read\n" ); |
|
340
|
|
|
|
|
|
|
READ: { |
|
341
|
0
|
0
|
|
|
|
|
last READ unless $selector->can_read( 0.01 ); |
|
|
0
|
|
|
|
|
|
|
|
342
|
0
|
|
|
|
|
|
$self->debug( "Reading\n" ); |
|
343
|
0
|
|
|
|
|
|
my $bytes = sysread $reader, $buffer, 4096; |
|
344
|
0
|
|
|
|
|
|
$self->debug( "Read $bytes bytes\n" ); |
|
345
|
0
|
|
|
|
|
|
$done .= $buffer; |
|
346
|
0
|
|
|
|
|
|
$self->debug( sprintf "Output is %d bytes\n", |
|
347
|
|
|
|
|
|
|
length $done |
|
348
|
|
|
|
|
|
|
); |
|
349
|
0
|
|
|
|
|
|
next READ; |
|
350
|
|
|
|
|
|
|
} |
|
351
|
|
|
|
|
|
|
} |
|
352
|
0
|
|
|
|
|
|
close $writer; |
|
353
|
0
|
|
|
|
|
|
$self->debug( "Done writing\n" ); |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
# read any leftovers |
|
356
|
0
|
|
|
|
|
|
$done .= do { local $/; <$reader> }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
357
|
0
|
|
|
|
|
|
$self->debug( sprintf "Done reading. Output is %d bytes\n", |
|
358
|
|
|
|
|
|
|
length $done |
|
359
|
|
|
|
|
|
|
); |
|
360
|
|
|
|
|
|
|
|
|
361
|
0
|
0
|
|
|
|
|
if( $? ) { |
|
362
|
0
|
|
|
|
|
|
$self->warn( "Error from pipe to $render!\n" ); |
|
363
|
0
|
|
|
|
|
|
$self->debug( 'Error: ' . do { local $/; <$err> } ); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
} |
|
365
|
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
|
|
367
|
0
|
|
|
|
|
|
close $reader; |
|
368
|
0
|
0
|
|
|
|
|
if( my $err = $? ) { |
|
369
|
0
|
|
|
|
|
|
$self->debug( |
|
370
|
|
|
|
|
|
|
"Nonzero exit ($?) while running `$render @render_switches`.\n" . |
|
371
|
|
|
|
|
|
|
"Falling back to Pod::Perldoc::ToPod\n" |
|
372
|
|
|
|
|
|
|
); |
|
373
|
0
|
|
|
|
|
|
return $self->_fallback_to_pod( @_ ); |
|
374
|
|
|
|
|
|
|
} |
|
375
|
|
|
|
|
|
|
|
|
376
|
0
|
|
|
|
|
|
$self->debug( "Output:\n----\n$done\n----\n" ); |
|
377
|
|
|
|
|
|
|
|
|
378
|
0
|
|
|
|
|
|
${ $self->{_text_ref} } = $done; |
|
|
0
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
|
|
380
|
0
|
0
|
|
|
|
|
return length ${ $self->{_text_ref} } ? SUCCESS : FAILED; |
|
|
0
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
} |
|
382
|
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
sub parse_from_file { |
|
384
|
0
|
|
|
0
|
0
|
|
my( $self, $file, $outfh) = @_; |
|
385
|
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
# We have a pipeline of filters each affecting the reference |
|
387
|
|
|
|
|
|
|
# in $self->{_text_ref} |
|
388
|
0
|
|
|
|
|
|
$self->{_text_ref} = \my $output; |
|
389
|
|
|
|
|
|
|
|
|
390
|
0
|
|
|
|
|
|
$self->_parse_with_pod_man( $file ); |
|
391
|
|
|
|
|
|
|
# so far, nroff is an external command so we ensure it worked |
|
392
|
0
|
|
|
|
|
|
my $result = $self->_filter_through_nroff; |
|
393
|
0
|
0
|
|
|
|
|
return $self->_fallback_to_pod( @_ ) unless $result == SUCCESS; |
|
394
|
|
|
|
|
|
|
|
|
395
|
0
|
|
|
|
|
|
$self->_post_nroff_processing; |
|
396
|
|
|
|
|
|
|
|
|
397
|
0
|
0
|
|
|
|
|
print { $outfh } $output or |
|
|
0
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
$self->die( "Can't print to $$self{__output_file}: $!" ); |
|
399
|
|
|
|
|
|
|
|
|
400
|
0
|
|
|
|
|
|
return; |
|
401
|
|
|
|
|
|
|
} |
|
402
|
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
sub _fallback_to_pod { |
|
404
|
0
|
|
|
0
|
|
|
my( $self, @args ) = @_; |
|
405
|
0
|
|
|
|
|
|
$self->warn( "Falling back to Pod because there was a problem!\n" ); |
|
406
|
0
|
|
|
|
|
|
require Pod::Perldoc::ToPod; |
|
407
|
0
|
|
|
|
|
|
return Pod::Perldoc::ToPod->new->parse_from_file(@_); |
|
408
|
|
|
|
|
|
|
} |
|
409
|
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
# maybe there's a user setting we should check? |
|
411
|
0
|
|
|
0
|
|
|
sub _get_tab_width { 4 } |
|
412
|
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
sub _expand_tabs { |
|
414
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
415
|
|
|
|
|
|
|
|
|
416
|
0
|
|
|
|
|
|
my $tab_width = ' ' x $self->_get_tab_width; |
|
417
|
|
|
|
|
|
|
|
|
418
|
0
|
|
|
|
|
|
${ $self->{_text_ref} } =~ s/\t/$tab_width/g; |
|
|
0
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
} |
|
420
|
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
sub _post_nroff_processing { |
|
422
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
423
|
|
|
|
|
|
|
|
|
424
|
0
|
0
|
|
|
|
|
if( $self->is_hpux ) { |
|
425
|
0
|
|
|
|
|
|
$self->debug( "On HP-UX, I'm going to expand tabs for you\n" ); |
|
426
|
|
|
|
|
|
|
# this used to be a pipe to `col -x` for HP-UX |
|
427
|
0
|
|
|
|
|
|
$self->_expand_tabs; |
|
428
|
|
|
|
|
|
|
} |
|
429
|
|
|
|
|
|
|
|
|
430
|
0
|
0
|
|
|
|
|
if( $self->{'__filter_nroff'} ) { |
|
431
|
0
|
|
|
|
|
|
$self->debug( "filter_nroff is set, so filtering\n" ); |
|
432
|
0
|
|
|
|
|
|
$self->_remove_nroff_header; |
|
433
|
0
|
|
|
|
|
|
$self->_remove_nroff_footer; |
|
434
|
|
|
|
|
|
|
} |
|
435
|
|
|
|
|
|
|
else { |
|
436
|
0
|
|
|
|
|
|
$self->debug( "filter_nroff is not set, so not filtering\n" ); |
|
437
|
|
|
|
|
|
|
} |
|
438
|
|
|
|
|
|
|
|
|
439
|
0
|
|
|
|
|
|
$self->_handle_unicode; |
|
440
|
|
|
|
|
|
|
|
|
441
|
0
|
|
|
|
|
|
return 1; |
|
442
|
|
|
|
|
|
|
} |
|
443
|
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
# I don't think this does anything since there aren't two consecutive |
|
445
|
|
|
|
|
|
|
# newlines in the Pod::Man output |
|
446
|
|
|
|
|
|
|
sub _remove_nroff_header { |
|
447
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
448
|
0
|
|
|
|
|
|
$self->debug( "_remove_nroff_header is still a stub!\n" ); |
|
449
|
0
|
|
|
|
|
|
return 1; |
|
450
|
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
# my @data = split /\n{2,}/, shift; |
|
452
|
|
|
|
|
|
|
# shift @data while @data and $data[0] !~ /\S/; # Go to header |
|
453
|
|
|
|
|
|
|
# shift @data if @data and $data[0] =~ /Contributed\s+Perl/; # Skip header |
|
454
|
|
|
|
|
|
|
} |
|
455
|
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
# I don't think this does anything since there aren't two consecutive |
|
457
|
|
|
|
|
|
|
# newlines in the Pod::Man output |
|
458
|
|
|
|
|
|
|
sub _remove_nroff_footer { |
|
459
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
460
|
0
|
|
|
|
|
|
$self->debug( "_remove_nroff_footer is still a stub!\n" ); |
|
461
|
0
|
|
|
|
|
|
return 1; |
|
462
|
0
|
|
|
|
|
|
${ $self->{_text_ref} } =~ s/\n\n+.*\w.*\Z//m; |
|
|
0
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
# my @data = split /\n{2,}/, shift; |
|
465
|
|
|
|
|
|
|
# pop @data if @data and $data[-1] =~ /^\w/; # Skip footer, like |
|
466
|
|
|
|
|
|
|
# 28/Jan/99 perl 5.005, patch 53 1 |
|
467
|
|
|
|
|
|
|
} |
|
468
|
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
sub _unicode_already_handled { |
|
470
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
471
|
|
|
|
|
|
|
|
|
472
|
0
|
0
|
|
|
|
|
$self->_have_groff_with_utf8 || |
|
473
|
|
|
|
|
|
|
1 # so, we don't have a case that needs _handle_unicode |
|
474
|
|
|
|
|
|
|
; |
|
475
|
|
|
|
|
|
|
} |
|
476
|
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
sub _handle_unicode { |
|
478
|
|
|
|
|
|
|
# this is the job of preconv |
|
479
|
|
|
|
|
|
|
# we don't need this with groff 1.20 and later. |
|
480
|
0
|
|
|
0
|
|
|
my( $self ) = @_; |
|
481
|
|
|
|
|
|
|
|
|
482
|
0
|
0
|
|
|
|
|
return 1 if $self->_unicode_already_handled; |
|
483
|
|
|
|
|
|
|
|
|
484
|
0
|
|
|
|
|
|
require Encode; |
|
485
|
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
# it's UTF-8 here, but we need character data |
|
487
|
0
|
|
|
|
|
|
my $text = Encode::decode( 'UTF-8', ${ $self->{_text_ref} } ) ; |
|
|
0
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
# http://www.mail-archive.com/groff@gnu.org/msg01378.html |
|
490
|
|
|
|
|
|
|
# http://linux.die.net/man/7/groff_char |
|
491
|
|
|
|
|
|
|
# http://www.gnu.org/software/groff/manual/html_node/Using-Symbols.html |
|
492
|
|
|
|
|
|
|
# http://lists.gnu.org/archive/html/groff/2011-05/msg00007.html |
|
493
|
|
|
|
|
|
|
# http://www.simplicidade.org/notes/archives/2009/05/fixing_the_pod.html |
|
494
|
|
|
|
|
|
|
# http://lists.freebsd.org/pipermail/freebsd-questions/2011-July/232239.html |
|
495
|
0
|
|
|
|
|
|
$text =~ s/(\P{ASCII})/ |
|
496
|
0
|
|
|
|
|
|
sprintf '\\[u%04X]', ord $1 |
|
497
|
2
|
|
|
2
|
|
962
|
/eg; |
|
|
2
|
|
|
|
|
17
|
|
|
|
2
|
|
|
|
|
24
|
|
|
498
|
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
# should we encode? |
|
500
|
0
|
|
|
|
|
|
${ $self->{_text_ref} } = $text; |
|
|
0
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
} |
|
502
|
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
1; |
|
504
|
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
__END__ |