]>
Commit | Line | Data |
---|---|---|
1bc74519 | 1 | #! /usr/bin/env perl |
95f92d57 | 2 | # Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved. |
05ea606a | 3 | # |
9059ab42 | 4 | # Licensed under the Apache License 2.0 (the "License"). You may not use |
05ea606a RS |
5 | # this file except in compliance with the License. You can obtain a copy |
6 | # in the file LICENSE in the source distribution or at | |
7 | # https://www.openssl.org/source/license.html | |
8 | ||
1bc74519 RS |
9 | |
10 | require 5.10.0; | |
11 | use warnings; | |
12 | use strict; | |
13 | use Pod::Checker; | |
14 | use File::Find; | |
169a8e39 | 15 | use File::Basename; |
71a8b855 | 16 | use File::Spec::Functions; |
35ea640a | 17 | use Getopt::Std; |
71a8b855 RS |
18 | use lib catdir(dirname($0), "perl"); |
19 | use OpenSSL::Util::Pod; | |
35ea640a | 20 | |
71a8b855 | 21 | # Options. |
8d50b9c1 | 22 | our($opt_d); |
b5283535 MC |
23 | our($opt_e); |
24 | our($opt_s); | |
a03749a8 | 25 | our($opt_o); |
71a8b855 | 26 | our($opt_h); |
9e183d22 | 27 | our($opt_l); |
8d50b9c1 | 28 | our($opt_n); |
274d1bee | 29 | our($opt_p); |
8d50b9c1 | 30 | our($opt_u); |
b5283535 | 31 | our($opt_v); |
e75138ab | 32 | our($opt_c); |
71a8b855 RS |
33 | |
34 | sub help() | |
35 | { | |
36 | print <<EOF; | |
37 | Find small errors (nits) in documentation. Options: | |
8d50b9c1 | 38 | -d Detailed list of undocumented (implies -u) |
b5283535 MC |
39 | -e Detailed list of new undocumented (implies -v) |
40 | -s Same as -e except no output is generated if nothing is undocumented | |
a03749a8 | 41 | -o Causes -e/-v to count symbols added since 1.1.1 as new (implies -v) |
9e183d22 | 42 | -l Print bogus links |
71a8b855 | 43 | -n Print nits in POD pages |
274d1bee | 44 | -p Warn if non-public name documented (implies -n) |
ee4afacd | 45 | -u Count undocumented functions |
b5283535 | 46 | -v Count new undocumented functions |
71a8b855 | 47 | -h Print this help message |
e75138ab | 48 | -c List undocumented commands and options |
71a8b855 RS |
49 | EOF |
50 | exit; | |
51 | } | |
1bc74519 | 52 | |
05ea606a RS |
53 | my $temp = '/tmp/docnits.txt'; |
54 | my $OUT; | |
274d1bee | 55 | my %public; |
05ea606a | 56 | |
169a8e39 RL |
57 | my %mandatory_sections = |
58 | ( '*' => [ 'NAME', 'DESCRIPTION', 'COPYRIGHT' ], | |
3dfda1a6 RS |
59 | 1 => [ 'SYNOPSIS', 'OPTIONS' ], |
60 | 3 => [ 'SYNOPSIS', 'RETURN VALUES' ], | |
169a8e39 RL |
61 | 5 => [ ], |
62 | 7 => [ ] ); | |
169a8e39 | 63 | |
35ea640a RS |
64 | # Cross-check functions in the NAME and SYNOPSIS section. |
65 | sub name_synopsis() | |
66 | { | |
67 | my $id = shift; | |
68 | my $filename = shift; | |
69 | my $contents = shift; | |
70 | ||
35ea640a RS |
71 | # Get NAME section and all words in it. |
72 | return unless $contents =~ /=head1 NAME(.*)=head1 SYNOPSIS/ms; | |
73 | my $tmp = $1; | |
74 | $tmp =~ tr/\n/ /; | |
3ba4dac6 | 75 | print "$id trailing comma before - in NAME\n" if $tmp =~ /, *-/; |
2bcb232e | 76 | $tmp =~ s/ -.*//g; |
1f79ddf5 | 77 | print "$id POD markup among the names in NAME\n" if $tmp =~ /[<>]/; |
2bcb232e RS |
78 | $tmp =~ s/ */ /g; |
79 | print "$id missing comma in NAME\n" if $tmp =~ /[^,] /; | |
fbba5d11 RS |
80 | |
81 | my $dirname = dirname($filename); | |
f6800e37 | 82 | my $simplename = basename(basename($filename, ".in"), ".pod"); |
fbba5d11 RS |
83 | my $foundfilename = 0; |
84 | my %foundfilenames = (); | |
35ea640a | 85 | my %names; |
23ab880d RL |
86 | foreach my $n ( split ',', $tmp ) { |
87 | $n =~ s/^\s+//; | |
88 | $n =~ s/\s+$//; | |
89 | print "$id the name '$n' contains white-space\n" | |
90 | if $n =~ /\s/; | |
35ea640a | 91 | $names{$n} = 1; |
fbba5d11 RS |
92 | $foundfilename++ if $n eq $simplename; |
93 | $foundfilenames{$n} = 1 | |
f6800e37 RL |
94 | if ((-f "$dirname/$n.pod.in" || -f "$dirname/$n.pod") |
95 | && $n ne $simplename); | |
35ea640a | 96 | } |
f6800e37 | 97 | print "$id the following exist as other .pod or .pod.in files:\n", |
fbba5d11 RS |
98 | join(" ", sort keys %foundfilenames), "\n" |
99 | if %foundfilenames; | |
274d1bee | 100 | print "$id $simplename (filename) missing from NAME section\n" |
fbba5d11 | 101 | unless $foundfilename; |
1722496f RS |
102 | foreach my $n ( keys %names ) { |
103 | print "$id $n is not public\n" | |
104 | if $opt_p and !defined $public{$n}; | |
105 | } | |
35ea640a RS |
106 | |
107 | # Find all functions in SYNOPSIS | |
108 | return unless $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms; | |
109 | my $syn = $1; | |
110 | foreach my $line ( split /\n+/, $syn ) { | |
be80b21d | 111 | next unless $line =~ /^\s/; |
8162f6f5 | 112 | my $sym; |
c952780c | 113 | $line =~ s/STACK_OF\([^)]+\)/int/g; |
4460ad90 | 114 | $line =~ s/SPARSE_ARRAY_OF\([^)]+\)/int/g; |
c952780c | 115 | $line =~ s/__declspec\([^)]+\)//; |
121677b4 RS |
116 | if ( $line =~ /env (\S*)=/ ) { |
117 | # environment variable env NAME=... | |
118 | $sym = $1; | |
119 | } elsif ( $line =~ /typedef.*\(\*(\S+)\)\(.*/ ) { | |
0ed78e78 RL |
120 | # a callback function pointer: typedef ... (*NAME)(... |
121 | $sym = $1; | |
122 | } elsif ( $line =~ /typedef.* (\S+)\(.*/ ) { | |
123 | # a callback function signature: typedef ... NAME(... | |
121677b4 RS |
124 | $sym = $1; |
125 | } elsif ( $line =~ /typedef.* (\S+);/ ) { | |
126 | # a simple typedef: typedef ... NAME; | |
8162f6f5 | 127 | $sym = $1; |
5d583521 | 128 | } elsif ( $line =~ /enum (\S*) \{/ ) { |
d4ea9659 RS |
129 | # an enumeration: enum ... { |
130 | $sym = $1; | |
0695b193 | 131 | } elsif ( $line =~ /#(?:define|undef) ([A-Za-z0-9_]+)/ ) { |
8162f6f5 RS |
132 | $sym = $1; |
133 | } elsif ( $line =~ /([A-Za-z0-9_]+)\(/ ) { | |
134 | $sym = $1; | |
135 | } | |
136 | else { | |
137 | next; | |
138 | } | |
139 | print "$id $sym missing from NAME section\n" | |
140 | unless defined $names{$sym}; | |
141 | $names{$sym} = 2; | |
aebb9aac RS |
142 | |
143 | # Do some sanity checks on the prototype. | |
144 | print "$id prototype missing spaces around commas: $line\n" | |
145 | if ( $line =~ /[a-z0-9],[^ ]/ ); | |
35ea640a RS |
146 | } |
147 | ||
148 | foreach my $n ( keys %names ) { | |
149 | next if $names{$n} == 2; | |
150 | print "$id $n missing from SYNOPSIS\n"; | |
151 | } | |
152 | } | |
153 | ||
39a117d1 | 154 | # Check if SECTION ($3) is located before BEFORE ($4) |
95f92d57 | 155 | sub check_section_location() |
cc838ee2 | 156 | { |
39a117d1 | 157 | my $id = shift; |
cc838ee2 | 158 | my $contents = shift; |
95f92d57 JL |
159 | my $section = shift; |
160 | my $before = shift; | |
cc838ee2 | 161 | |
39a117d1 RS |
162 | return |
163 | unless $contents =~ /=head1 $section/ and $contents =~ /=head1 $before/; | |
164 | print "$id $section should be placed before $before section\n" | |
95f92d57 | 165 | if $contents =~ /=head1 $before.*=head1 $section/ms; |
cc838ee2 PY |
166 | } |
167 | ||
1bc74519 RS |
168 | sub check() |
169 | { | |
169a8e39 RL |
170 | my $filename = shift; |
171 | my $dirname = basename(dirname($filename)); | |
843666ff | 172 | |
1bc74519 RS |
173 | my $contents = ''; |
174 | { | |
175 | local $/ = undef; | |
169a8e39 | 176 | open POD, $filename or die "Couldn't open $filename, $!"; |
1bc74519 RS |
177 | $contents = <POD>; |
178 | close POD; | |
179 | } | |
843666ff RS |
180 | |
181 | my $id = "${filename}:1:"; | |
35ea640a | 182 | |
39a117d1 RS |
183 | # Check ordering of some sections in man3 |
184 | if ( $filename =~ m|man3/| ) { | |
cda77422 | 185 | &check_section_location($id, $contents, "RETURN VALUES", "EXAMPLES"); |
39a117d1 | 186 | &check_section_location($id, $contents, "SEE ALSO", "HISTORY"); |
cda77422 | 187 | &check_section_location($id, $contents, "EXAMPLES", "SEE ALSO"); |
39a117d1 RS |
188 | } |
189 | ||
4692340e | 190 | &name_synopsis($id, $filename, $contents) |
8162f6f5 | 191 | unless $contents =~ /=for comment generic/ |
99d63d46 | 192 | or $filename =~ m@man[157]/@; |
35ea640a RS |
193 | |
194 | print "$id doesn't start with =pod\n" | |
05ea606a | 195 | if $contents !~ /^=pod/; |
35ea640a | 196 | print "$id doesn't end with =cut\n" |
05ea606a | 197 | if $contents !~ /=cut\n$/; |
35ea640a | 198 | print "$id more than one cut line.\n" |
05ea606a | 199 | if $contents =~ /=cut.*=cut/ms; |
cda77422 RS |
200 | print "$id EXAMPLE not EXAMPLES section.\n" |
201 | if $contents =~ /=head1 EXAMPLE[^S]/; | |
35ea640a | 202 | print "$id missing copyright\n" |
05ea606a | 203 | if $contents !~ /Copyright .* The OpenSSL Project Authors/; |
35ea640a | 204 | print "$id copyright not last\n" |
05ea606a | 205 | if $contents =~ /head1 COPYRIGHT.*=head/ms; |
35ea640a | 206 | print "$id head2 in All uppercase\n" |
843666ff | 207 | if $contents =~ /head2\s+[A-Z ]+\n/; |
35ea640a RS |
208 | print "$id extra space after head\n" |
209 | if $contents =~ /=head\d\s\s+/; | |
210 | print "$id period in NAME section\n" | |
211 | if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms; | |
5a3371e2 RS |
212 | print "$id Duplicate $1 in L<>\n" |
213 | if $contents =~ /L<([^>]*)\|([^>]*)>/ && $1 eq $2; | |
e1271ac2 | 214 | print "$id Bad =over $1\n" |
2f61bc2e | 215 | if $contents =~ /=over([^ ][^24])/; |
e90fc053 RS |
216 | print "$id Possible version style issue\n" |
217 | if $contents =~ /OpenSSL version [019]/; | |
843666ff | 218 | |
843666ff | 219 | if ( $contents !~ /=for comment multiple includes/ ) { |
a95d7574 RS |
220 | # Look for multiple consecutive openssl #include lines |
221 | # (non-consecutive lines are okay; see man3/MD5.pod). | |
843666ff RS |
222 | if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) { |
223 | my $count = 0; | |
224 | foreach my $line ( split /\n+/, $1 ) { | |
225 | if ( $line =~ m@include <openssl/@ ) { | |
a95d7574 | 226 | print "$id has multiple includes\n" if ++$count == 2; |
843666ff RS |
227 | } else { |
228 | $count = 0; | |
229 | } | |
230 | } | |
231 | } | |
232 | } | |
05ea606a | 233 | |
35ea640a RS |
234 | open my $OUT, '>', $temp |
235 | or die "Can't open $temp, $!"; | |
169a8e39 | 236 | podchecker($filename, $OUT); |
35ea640a RS |
237 | close $OUT; |
238 | open $OUT, '<', $temp | |
239 | or die "Can't read $temp, $!"; | |
240 | while ( <$OUT> ) { | |
241 | next if /\(section\) in.*deprecated/; | |
242 | print; | |
243 | } | |
244 | close $OUT; | |
245 | unlink $temp || warn "Can't remove $temp, $!"; | |
a95d7574 RS |
246 | |
247 | # Find what section this page is in; assume 3. | |
248 | my $section = 3; | |
249 | $section = $1 if $dirname =~ /man([1-9])/; | |
250 | ||
251 | foreach ((@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}})) { | |
252 | # Skip "return values" if not -s | |
a95d7574 RS |
253 | print "$id: missing $_ head1 section\n" |
254 | if $contents !~ /^=head1\s+${_}\s*$/m; | |
255 | } | |
05ea606a | 256 | } |
1bc74519 | 257 | |
71a8b855 RS |
258 | my %dups; |
259 | ||
260 | sub parsenum() | |
261 | { | |
262 | my $file = shift; | |
263 | my @apis; | |
264 | ||
265 | open my $IN, '<', $file | |
266 | or die "Can't open $file, $!, stopped"; | |
267 | ||
268 | while ( <$IN> ) { | |
274d1bee | 269 | next if /^#/; |
71a8b855 | 270 | next if /\bNOEXIST\b/; |
1722496f RS |
271 | my @fields = split(); |
272 | die "Malformed line $_" | |
273 | if scalar @fields != 2 && scalar @fields != 4; | |
274 | push @apis, $fields[0]; | |
71a8b855 RS |
275 | } |
276 | ||
277 | close $IN; | |
278 | ||
274d1bee | 279 | print "# Found ", scalar(@apis), " in $file\n" unless $opt_p; |
71a8b855 RS |
280 | return sort @apis; |
281 | } | |
282 | ||
23ab880d | 283 | sub getdocced |
71a8b855 RS |
284 | { |
285 | my $dir = shift; | |
286 | my %return; | |
287 | ||
f6800e37 | 288 | foreach my $pod ( glob("$dir/*.pod"), glob("$dir/*.pod.in") ) { |
71a8b855 RS |
289 | my %podinfo = extract_pod_info($pod); |
290 | foreach my $n ( @{$podinfo{names}} ) { | |
291 | $return{$n} = $pod; | |
292 | print "# Duplicate $n in $pod and $dups{$n}\n" | |
293 | if defined $dups{$n} && $dups{$n} ne $pod; | |
294 | $dups{$n} = $pod; | |
295 | } | |
296 | } | |
297 | ||
298 | return %return; | |
299 | } | |
300 | ||
301 | my %docced; | |
302 | ||
b5283535 MC |
303 | sub loadmissing($) |
304 | { | |
305 | my $missingfile = shift; | |
306 | my @missing; | |
307 | ||
308 | open FH, $missingfile | |
309 | || die "Can't open $missingfile"; | |
310 | while ( <FH> ) { | |
311 | chomp; | |
312 | next if /^#/; | |
313 | push @missing, $_; | |
314 | } | |
315 | close FH; | |
316 | ||
317 | return @missing; | |
318 | } | |
319 | ||
9a2dfc0f RS |
320 | sub checkmacros() |
321 | { | |
322 | my $count = 0; | |
ee4afacd | 323 | my %seen; |
a03749a8 | 324 | my @missing; |
9a2dfc0f | 325 | |
a03749a8 MC |
326 | if ($opt_o) { |
327 | @missing = loadmissing('util/missingmacro111.txt'); | |
328 | } elsif ($opt_v) { | |
329 | @missing = loadmissing('util/missingmacro.txt'); | |
330 | } | |
b5283535 MC |
331 | |
332 | print "# Checking macros (approximate)\n" if !$opt_s; | |
9a2dfc0f RS |
333 | foreach my $f ( glob('include/openssl/*.h') ) { |
334 | # Skip some internals we don't want to document yet. | |
335 | next if $f eq 'include/openssl/asn1.h'; | |
336 | next if $f eq 'include/openssl/asn1t.h'; | |
337 | next if $f eq 'include/openssl/err.h'; | |
338 | open(IN, $f) || die "Can't open $f, $!"; | |
339 | while ( <IN> ) { | |
340 | next unless /^#\s*define\s*(\S+)\(/; | |
341 | my $macro = $1; | |
ee4afacd | 342 | next if $docced{$macro} || defined $seen{$macro}; |
9a2dfc0f RS |
343 | next if $macro =~ /i2d_/ |
344 | || $macro =~ /d2i_/ | |
345 | || $macro =~ /DEPRECATEDIN/ | |
346 | || $macro =~ /IMPLEMENT_/ | |
347 | || $macro =~ /DECLARE_/; | |
b5283535 MC |
348 | |
349 | # Skip macros known to be missing | |
350 | next if $opt_v && grep( /^$macro$/, @missing); | |
351 | ||
352 | print "$f:$macro\n" if $opt_d || $opt_e; | |
9a2dfc0f | 353 | $count++; |
ee4afacd | 354 | $seen{$macro} = 1; |
9a2dfc0f RS |
355 | } |
356 | close(IN); | |
357 | } | |
b5283535 | 358 | print "# Found $count macros missing\n" if !$opt_s || $count > 0; |
9a2dfc0f RS |
359 | } |
360 | ||
71a8b855 RS |
361 | sub printem() |
362 | { | |
363 | my $libname = shift; | |
364 | my $numfile = shift; | |
b5283535 | 365 | my $missingfile = shift; |
71a8b855 | 366 | my $count = 0; |
ee4afacd | 367 | my %seen; |
71a8b855 | 368 | |
b5283535 MC |
369 | my @missing = loadmissing($missingfile) if ($opt_v); |
370 | ||
71a8b855 | 371 | foreach my $func ( &parsenum($numfile) ) { |
ee4afacd | 372 | next if $docced{$func} || defined $seen{$func}; |
71a8b855 RS |
373 | |
374 | # Skip ASN1 utilities | |
375 | next if $func =~ /^ASN1_/; | |
376 | ||
b5283535 MC |
377 | # Skip functions known to be missing |
378 | next if $opt_v && grep( /^$func$/, @missing); | |
379 | ||
380 | print "$libname:$func\n" if $opt_d || $opt_e; | |
71a8b855 | 381 | $count++; |
ee4afacd | 382 | $seen{$func} = 1; |
71a8b855 | 383 | } |
b5283535 | 384 | print "# Found $count missing from $numfile\n\n" if !$opt_s || $count > 0; |
71a8b855 RS |
385 | } |
386 | ||
387 | ||
9e183d22 RS |
388 | # Collection of links in each POD file. |
389 | # filename => [ "foo(1)", "bar(3)", ... ] | |
390 | my %link_collection = (); | |
391 | # Collection of names in each POD file. | |
392 | # "name(s)" => filename | |
393 | my %name_collection = (); | |
394 | ||
395 | sub collectnames { | |
396 | my $filename = shift; | |
397 | $filename =~ m|man(\d)/|; | |
398 | my $section = $1; | |
f6800e37 | 399 | my $simplename = basename(basename($filename, ".in"), ".pod"); |
9e183d22 RS |
400 | my $id = "${filename}:1:"; |
401 | ||
402 | my $contents = ''; | |
403 | { | |
404 | local $/ = undef; | |
405 | open POD, $filename or die "Couldn't open $filename, $!"; | |
406 | $contents = <POD>; | |
407 | close POD; | |
408 | } | |
409 | ||
410 | $contents =~ /=head1 NAME([^=]*)=head1 /ms; | |
411 | my $tmp = $1; | |
412 | unless (defined $tmp) { | |
413 | print "$id weird name section\n"; | |
414 | return; | |
415 | } | |
416 | $tmp =~ tr/\n/ /; | |
f6800e37 | 417 | $tmp =~ s/ -.*//g; |
9e183d22 | 418 | |
f6800e37 RL |
419 | my @names = |
420 | map { s|/|-|g; $_ } # Treat slash as dash | |
421 | map { s/^\s+//g; s/\s+$//g; $_ } # Trim prefix and suffix blanks | |
422 | split(/,/, $tmp); | |
9e183d22 RS |
423 | unless (grep { $simplename eq $_ } @names) { |
424 | print "$id missing $simplename\n"; | |
425 | push @names, $simplename; | |
426 | } | |
427 | foreach my $name (@names) { | |
428 | next if $name eq ""; | |
23ab880d RL |
429 | if ($name =~ /\s/) { |
430 | print "$id '$name' contains white space\n"; | |
431 | } | |
9e183d22 RS |
432 | my $name_sec = "$name($section)"; |
433 | if (! exists $name_collection{$name_sec}) { | |
434 | $name_collection{$name_sec} = $filename; | |
f6800e37 RL |
435 | } elsif ($filename eq $name_collection{$name_sec}) { |
436 | print "$id $name_sec repeated in NAME section of $name_collection{$name_sec}\n" | |
437 | } else { | |
438 | print "$id $name_sec also in NAME section of $name_collection{$name_sec}\n"; | |
9e183d22 RS |
439 | } |
440 | } | |
441 | ||
442 | my @foreign_names = | |
443 | map { map { s/\s+//g; $_ } split(/,/, $_) } | |
444 | $contents =~ /=for\s+comment\s+foreign\s+manuals:\s*(.*)\n\n/; | |
445 | foreach (@foreign_names) { | |
446 | $name_collection{$_} = undef; # It still exists! | |
447 | } | |
448 | ||
449 | my @links = $contents =~ /L< | |
450 | # if the link is of the form L<something|name(s)>, | |
451 | # then remove 'something'. Note that 'something' | |
452 | # may contain POD codes as well... | |
453 | (?:(?:[^\|]|<[^>]*>)*\|)? | |
46f4e1be | 454 | # we're only interested in references that have |
9e183d22 RS |
455 | # a one digit section number |
456 | ([^\/>\(]+\(\d\)) | |
457 | /gx; | |
458 | $link_collection{$filename} = [ @links ]; | |
459 | } | |
460 | ||
461 | sub checklinks { | |
462 | foreach my $filename (sort keys %link_collection) { | |
463 | foreach my $link (@{$link_collection{$filename}}) { | |
464 | print "${filename}:1: reference to non-existing $link\n" | |
465 | unless exists $name_collection{$link}; | |
466 | } | |
467 | } | |
468 | } | |
469 | ||
274d1bee RS |
470 | sub publicize() { |
471 | foreach my $name ( &parsenum('util/libcrypto.num') ) { | |
472 | $public{$name} = 1; | |
473 | } | |
474 | foreach my $name ( &parsenum('util/libssl.num') ) { | |
475 | $public{$name} = 1; | |
476 | } | |
477 | foreach my $name ( &parsenum('util/private.num') ) { | |
478 | $public{$name} = 1; | |
479 | } | |
480 | } | |
481 | ||
e75138ab RS |
482 | my %skips = ( |
483 | 'aes128' => 1, | |
484 | 'aes192' => 1, | |
485 | 'aes256' => 1, | |
486 | 'aria128' => 1, | |
487 | 'aria192' => 1, | |
488 | 'aria256' => 1, | |
489 | 'camellia128' => 1, | |
490 | 'camellia192' => 1, | |
491 | 'camellia256' => 1, | |
492 | 'des' => 1, | |
493 | 'des3' => 1, | |
494 | 'idea' => 1, | |
495 | '[cipher]' => 1, | |
496 | '[digest]' => 1, | |
497 | ); | |
498 | ||
499 | sub checkflags() { | |
500 | my $cmd = shift; | |
501 | my %cmdopts; | |
502 | my %docopts; | |
503 | my $ok = 1; | |
504 | ||
505 | # Get the list of options in the command. | |
506 | open CFH, "./apps/openssl list --options $cmd|" | |
507 | || die "Can list options for $cmd, $!"; | |
508 | while ( <CFH> ) { | |
509 | chop; | |
510 | s/ .$//; | |
511 | $cmdopts{$_} = 1; | |
512 | } | |
513 | close CFH; | |
514 | ||
515 | # Get the list of flags from the synopsis | |
516 | open CFH, "<doc/man1/$cmd.pod" | |
517 | || die "Can't open $cmd.pod, $!"; | |
518 | while ( <CFH> ) { | |
519 | chop; | |
520 | last if /DESCRIPTION/; | |
521 | next unless /\[B<-([^ >]+)/; | |
522 | $docopts{$1} = 1; | |
523 | } | |
524 | close CFH; | |
525 | ||
526 | # See what's in the command not the manpage. | |
527 | my @undocced = (); | |
528 | foreach my $k ( keys %cmdopts ) { | |
529 | push @undocced, $k unless $docopts{$k}; | |
530 | } | |
531 | if ( scalar @undocced > 0 ) { | |
532 | $ok = 0; | |
533 | foreach ( @undocced ) { | |
534 | print "doc/man1/$cmd.pod: Missing -$_\n"; | |
535 | } | |
536 | } | |
537 | ||
538 | # See what's in the command not the manpage. | |
539 | my @unimpl = (); | |
540 | foreach my $k ( keys %docopts ) { | |
541 | push @unimpl, $k unless $cmdopts{$k}; | |
542 | } | |
543 | if ( scalar @unimpl > 0 ) { | |
544 | $ok = 0; | |
545 | foreach ( @unimpl ) { | |
546 | next if defined $skips{$_}; | |
547 | print "doc/man1/$cmd.pod: Not implemented -$_\n"; | |
548 | } | |
549 | } | |
550 | ||
551 | return $ok; | |
552 | } | |
553 | ||
a03749a8 | 554 | getopts('cdesolnphuv'); |
274d1bee RS |
555 | |
556 | &help() if $opt_h; | |
b5283535 | 557 | |
a085f43f | 558 | $opt_n = 1 if $opt_p; |
8d50b9c1 | 559 | $opt_u = 1 if $opt_d; |
b5283535 | 560 | $opt_e = 1 if $opt_s; |
a03749a8 | 561 | $opt_v = 1 if $opt_o || $opt_e; |
b5283535 MC |
562 | |
563 | die "Cannot use both -u and -v" if $opt_u && $opt_v; | |
564 | die "Cannot use both -d and -e" if $opt_d && $opt_e; | |
35ea640a | 565 | |
a03749a8 MC |
566 | # We only need to check c, l, n, u and v. |
567 | # Options d, e, s, o and p imply one of the above. | |
568 | die "Need one of -[cdesolnpuv] flags.\n" | |
b5283535 | 569 | unless $opt_c or $opt_l or $opt_n or $opt_u or $opt_v; |
71a8b855 | 570 | |
e75138ab RS |
571 | if ( $opt_c ) { |
572 | my $ok = 1; | |
573 | my @commands = (); | |
3dfda1a6 | 574 | |
e75138ab RS |
575 | # Get list of commands. |
576 | open FH, "./apps/openssl list -1 -commands|" | |
577 | || die "Can't list commands, $!"; | |
578 | while ( <FH> ) { | |
579 | chop; | |
580 | push @commands, $_; | |
581 | } | |
582 | close FH; | |
583 | ||
584 | # See if each has a manpage. | |
585 | foreach ( @commands ) { | |
586 | next if $_ eq 'help' || $_ eq 'exit'; | |
587 | if ( ! -f "doc/man1/$_.pod" ) { | |
588 | print "doc/man1/$_.pod does not exist\n"; | |
589 | $ok = 0; | |
590 | } else { | |
591 | $ok = 0 if not &checkflags($_); | |
592 | } | |
71a8b855 | 593 | } |
e75138ab RS |
594 | |
595 | # See what help is missing. | |
596 | open FH, "./apps/openssl list --missing-help |" | |
597 | || die "Can't list missing help, $!"; | |
598 | while ( <FH> ) { | |
599 | chop; | |
600 | my ($cmd, $flag) = split; | |
601 | print "$cmd has no help for -$flag\n"; | |
602 | $ok = 0; | |
603 | } | |
604 | close FH; | |
605 | ||
606 | exit 1 if not $ok; | |
71a8b855 | 607 | } |
9e183d22 RS |
608 | |
609 | if ( $opt_l ) { | |
f6800e37 | 610 | foreach (@ARGV ? @ARGV : (glob('doc/*/*.pod'), glob('doc/*/*.pod.in'), |
23ab880d | 611 | glob('doc/internal/*/*.pod'))) { |
9e183d22 RS |
612 | collectnames($_); |
613 | } | |
614 | checklinks(); | |
615 | } | |
616 | ||
e75138ab RS |
617 | if ( $opt_n ) { |
618 | &publicize() if $opt_p; | |
f6800e37 | 619 | foreach (@ARGV ? @ARGV : (glob('doc/*/*.pod'), glob('doc/*/*.pod.in'))) { |
e75138ab RS |
620 | &check($_); |
621 | } | |
23ab880d RL |
622 | { |
623 | local $opt_p = undef; | |
624 | foreach (@ARGV ? @ARGV : glob('doc/internal/*/*.pod')) { | |
625 | &check($_); | |
626 | } | |
627 | } | |
e75138ab RS |
628 | } |
629 | ||
b5283535 | 630 | if ( $opt_u || $opt_v) { |
23ab880d | 631 | my %temp = getdocced('doc/man3'); |
71a8b855 RS |
632 | foreach ( keys %temp ) { |
633 | $docced{$_} = $temp{$_}; | |
634 | } | |
a03749a8 MC |
635 | if ($opt_o) { |
636 | &printem('crypto', 'util/libcrypto.num', 'util/missingcrypto111.txt'); | |
637 | &printem('ssl', 'util/libssl.num', 'util/missingssl111.txt'); | |
638 | } else { | |
639 | &printem('crypto', 'util/libcrypto.num', 'util/missingcrypto.txt'); | |
640 | &printem('ssl', 'util/libssl.num', 'util/missingssl.txt'); | |
641 | } | |
9a2dfc0f | 642 | &checkmacros(); |
1bc74519 | 643 | } |
05ea606a | 644 | |
35ea640a | 645 | exit; |