]>
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); | |
82 | my $simplename = basename($filename); | |
83 | $simplename =~ s/.pod$//; | |
84 | my $foundfilename = 0; | |
85 | my %foundfilenames = (); | |
35ea640a | 86 | my %names; |
23ab880d RL |
87 | foreach my $n ( split ',', $tmp ) { |
88 | $n =~ s/^\s+//; | |
89 | $n =~ s/\s+$//; | |
90 | print "$id the name '$n' contains white-space\n" | |
91 | if $n =~ /\s/; | |
35ea640a | 92 | $names{$n} = 1; |
fbba5d11 RS |
93 | $foundfilename++ if $n eq $simplename; |
94 | $foundfilenames{$n} = 1 | |
95 | if -f "$dirname/$n.pod" && $n ne $simplename; | |
35ea640a | 96 | } |
fbba5d11 RS |
97 | print "$id the following exist as other .pod files:\n", |
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 | ||
95f92d57 JL |
154 | # Check if SECTION is located before BEFORE |
155 | sub check_section_location() | |
cc838ee2 PY |
156 | { |
157 | my $filename = shift; | |
158 | my $contents = shift; | |
95f92d57 JL |
159 | my $section = shift; |
160 | my $before = shift; | |
cc838ee2 | 161 | |
95f92d57 JL |
162 | return unless $contents =~ /=head1 $section/ |
163 | and $contents =~ /=head1 $before/; | |
164 | print "$filename: $section should be placed before $before section\n" | |
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 | 180 | |
95f92d57 JL |
181 | # Check if EXAMPLES is located after RETURN VALUES section. |
182 | &check_section_location($filename, $contents, "RETURN VALUES", "EXAMPLES") if $filename =~ m|man3/|; | |
573ac8f2 JL |
183 | # Check if HISTORY is located after SEE ALSO |
184 | &check_section_location($filename, $contents, "SEE ALSO", "HISTORY") if $filename =~ m|man3/|; | |
185 | # Check if SEE ALSO is located after EXAMPLES | |
186 | &check_section_location($filename, $contents, "EXAMPLES", "SEE ALSO") if $filename =~ m|man3/|; | |
cc838ee2 | 187 | |
843666ff | 188 | my $id = "${filename}:1:"; |
35ea640a | 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; |
35ea640a | 200 | print "$id missing copyright\n" |
05ea606a | 201 | if $contents !~ /Copyright .* The OpenSSL Project Authors/; |
35ea640a | 202 | print "$id copyright not last\n" |
05ea606a | 203 | if $contents =~ /head1 COPYRIGHT.*=head/ms; |
35ea640a | 204 | print "$id head2 in All uppercase\n" |
843666ff | 205 | if $contents =~ /head2\s+[A-Z ]+\n/; |
35ea640a RS |
206 | print "$id extra space after head\n" |
207 | if $contents =~ /=head\d\s\s+/; | |
208 | print "$id period in NAME section\n" | |
209 | if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms; | |
5a3371e2 RS |
210 | print "$id Duplicate $1 in L<>\n" |
211 | if $contents =~ /L<([^>]*)\|([^>]*)>/ && $1 eq $2; | |
e1271ac2 | 212 | print "$id Bad =over $1\n" |
2f61bc2e | 213 | if $contents =~ /=over([^ ][^24])/; |
e90fc053 RS |
214 | print "$id Possible version style issue\n" |
215 | if $contents =~ /OpenSSL version [019]/; | |
843666ff | 216 | |
843666ff | 217 | if ( $contents !~ /=for comment multiple includes/ ) { |
a95d7574 RS |
218 | # Look for multiple consecutive openssl #include lines |
219 | # (non-consecutive lines are okay; see man3/MD5.pod). | |
843666ff RS |
220 | if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) { |
221 | my $count = 0; | |
222 | foreach my $line ( split /\n+/, $1 ) { | |
223 | if ( $line =~ m@include <openssl/@ ) { | |
a95d7574 | 224 | print "$id has multiple includes\n" if ++$count == 2; |
843666ff RS |
225 | } else { |
226 | $count = 0; | |
227 | } | |
228 | } | |
229 | } | |
230 | } | |
05ea606a | 231 | |
35ea640a RS |
232 | open my $OUT, '>', $temp |
233 | or die "Can't open $temp, $!"; | |
169a8e39 | 234 | podchecker($filename, $OUT); |
35ea640a RS |
235 | close $OUT; |
236 | open $OUT, '<', $temp | |
237 | or die "Can't read $temp, $!"; | |
238 | while ( <$OUT> ) { | |
239 | next if /\(section\) in.*deprecated/; | |
240 | print; | |
241 | } | |
242 | close $OUT; | |
243 | unlink $temp || warn "Can't remove $temp, $!"; | |
a95d7574 RS |
244 | |
245 | # Find what section this page is in; assume 3. | |
246 | my $section = 3; | |
247 | $section = $1 if $dirname =~ /man([1-9])/; | |
248 | ||
249 | foreach ((@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}})) { | |
250 | # Skip "return values" if not -s | |
a95d7574 RS |
251 | print "$id: missing $_ head1 section\n" |
252 | if $contents !~ /^=head1\s+${_}\s*$/m; | |
253 | } | |
05ea606a | 254 | } |
1bc74519 | 255 | |
71a8b855 RS |
256 | my %dups; |
257 | ||
258 | sub parsenum() | |
259 | { | |
260 | my $file = shift; | |
261 | my @apis; | |
262 | ||
263 | open my $IN, '<', $file | |
264 | or die "Can't open $file, $!, stopped"; | |
265 | ||
266 | while ( <$IN> ) { | |
274d1bee | 267 | next if /^#/; |
71a8b855 RS |
268 | next if /\bNOEXIST\b/; |
269 | next if /\bEXPORT_VAR_AS_FUNC\b/; | |
1722496f RS |
270 | my @fields = split(); |
271 | die "Malformed line $_" | |
272 | if scalar @fields != 2 && scalar @fields != 4; | |
273 | push @apis, $fields[0]; | |
71a8b855 RS |
274 | } |
275 | ||
276 | close $IN; | |
277 | ||
274d1bee | 278 | print "# Found ", scalar(@apis), " in $file\n" unless $opt_p; |
71a8b855 RS |
279 | return sort @apis; |
280 | } | |
281 | ||
23ab880d | 282 | sub getdocced |
71a8b855 RS |
283 | { |
284 | my $dir = shift; | |
285 | my %return; | |
286 | ||
287 | foreach my $pod ( glob("$dir/*.pod") ) { | |
288 | my %podinfo = extract_pod_info($pod); | |
289 | foreach my $n ( @{$podinfo{names}} ) { | |
290 | $return{$n} = $pod; | |
291 | print "# Duplicate $n in $pod and $dups{$n}\n" | |
292 | if defined $dups{$n} && $dups{$n} ne $pod; | |
293 | $dups{$n} = $pod; | |
294 | } | |
295 | } | |
296 | ||
297 | return %return; | |
298 | } | |
299 | ||
300 | my %docced; | |
301 | ||
b5283535 MC |
302 | sub loadmissing($) |
303 | { | |
304 | my $missingfile = shift; | |
305 | my @missing; | |
306 | ||
307 | open FH, $missingfile | |
308 | || die "Can't open $missingfile"; | |
309 | while ( <FH> ) { | |
310 | chomp; | |
311 | next if /^#/; | |
312 | push @missing, $_; | |
313 | } | |
314 | close FH; | |
315 | ||
316 | return @missing; | |
317 | } | |
318 | ||
9a2dfc0f RS |
319 | sub checkmacros() |
320 | { | |
321 | my $count = 0; | |
ee4afacd | 322 | my %seen; |
a03749a8 | 323 | my @missing; |
9a2dfc0f | 324 | |
a03749a8 MC |
325 | if ($opt_o) { |
326 | @missing = loadmissing('util/missingmacro111.txt'); | |
327 | } elsif ($opt_v) { | |
328 | @missing = loadmissing('util/missingmacro.txt'); | |
329 | } | |
b5283535 MC |
330 | |
331 | print "# Checking macros (approximate)\n" if !$opt_s; | |
9a2dfc0f RS |
332 | foreach my $f ( glob('include/openssl/*.h') ) { |
333 | # Skip some internals we don't want to document yet. | |
334 | next if $f eq 'include/openssl/asn1.h'; | |
335 | next if $f eq 'include/openssl/asn1t.h'; | |
336 | next if $f eq 'include/openssl/err.h'; | |
337 | open(IN, $f) || die "Can't open $f, $!"; | |
338 | while ( <IN> ) { | |
339 | next unless /^#\s*define\s*(\S+)\(/; | |
340 | my $macro = $1; | |
ee4afacd | 341 | next if $docced{$macro} || defined $seen{$macro}; |
9a2dfc0f RS |
342 | next if $macro =~ /i2d_/ |
343 | || $macro =~ /d2i_/ | |
344 | || $macro =~ /DEPRECATEDIN/ | |
345 | || $macro =~ /IMPLEMENT_/ | |
346 | || $macro =~ /DECLARE_/; | |
b5283535 MC |
347 | |
348 | # Skip macros known to be missing | |
349 | next if $opt_v && grep( /^$macro$/, @missing); | |
350 | ||
351 | print "$f:$macro\n" if $opt_d || $opt_e; | |
9a2dfc0f | 352 | $count++; |
ee4afacd | 353 | $seen{$macro} = 1; |
9a2dfc0f RS |
354 | } |
355 | close(IN); | |
356 | } | |
b5283535 | 357 | print "# Found $count macros missing\n" if !$opt_s || $count > 0; |
9a2dfc0f RS |
358 | } |
359 | ||
71a8b855 RS |
360 | sub printem() |
361 | { | |
362 | my $libname = shift; | |
363 | my $numfile = shift; | |
b5283535 | 364 | my $missingfile = shift; |
71a8b855 | 365 | my $count = 0; |
ee4afacd | 366 | my %seen; |
71a8b855 | 367 | |
b5283535 MC |
368 | my @missing = loadmissing($missingfile) if ($opt_v); |
369 | ||
71a8b855 | 370 | foreach my $func ( &parsenum($numfile) ) { |
ee4afacd | 371 | next if $docced{$func} || defined $seen{$func}; |
71a8b855 RS |
372 | |
373 | # Skip ASN1 utilities | |
374 | next if $func =~ /^ASN1_/; | |
375 | ||
b5283535 MC |
376 | # Skip functions known to be missing |
377 | next if $opt_v && grep( /^$func$/, @missing); | |
378 | ||
379 | print "$libname:$func\n" if $opt_d || $opt_e; | |
71a8b855 | 380 | $count++; |
ee4afacd | 381 | $seen{$func} = 1; |
71a8b855 | 382 | } |
b5283535 | 383 | print "# Found $count missing from $numfile\n\n" if !$opt_s || $count > 0; |
71a8b855 RS |
384 | } |
385 | ||
386 | ||
9e183d22 RS |
387 | # Collection of links in each POD file. |
388 | # filename => [ "foo(1)", "bar(3)", ... ] | |
389 | my %link_collection = (); | |
390 | # Collection of names in each POD file. | |
391 | # "name(s)" => filename | |
392 | my %name_collection = (); | |
393 | ||
394 | sub collectnames { | |
395 | my $filename = shift; | |
396 | $filename =~ m|man(\d)/|; | |
397 | my $section = $1; | |
398 | my $simplename = basename($filename, ".pod"); | |
399 | my $id = "${filename}:1:"; | |
400 | ||
401 | my $contents = ''; | |
402 | { | |
403 | local $/ = undef; | |
404 | open POD, $filename or die "Couldn't open $filename, $!"; | |
405 | $contents = <POD>; | |
406 | close POD; | |
407 | } | |
408 | ||
409 | $contents =~ /=head1 NAME([^=]*)=head1 /ms; | |
410 | my $tmp = $1; | |
411 | unless (defined $tmp) { | |
412 | print "$id weird name section\n"; | |
413 | return; | |
414 | } | |
415 | $tmp =~ tr/\n/ /; | |
416 | $tmp =~ s/-.*//g; | |
417 | ||
23ab880d | 418 | my @names = map { s/^\s+//g; s/\s+$//g; $_ } split(/,/, $tmp); |
9e183d22 RS |
419 | unless (grep { $simplename eq $_ } @names) { |
420 | print "$id missing $simplename\n"; | |
421 | push @names, $simplename; | |
422 | } | |
423 | foreach my $name (@names) { | |
424 | next if $name eq ""; | |
23ab880d RL |
425 | if ($name =~ /\s/) { |
426 | print "$id '$name' contains white space\n"; | |
427 | } | |
9e183d22 RS |
428 | my $name_sec = "$name($section)"; |
429 | if (! exists $name_collection{$name_sec}) { | |
430 | $name_collection{$name_sec} = $filename; | |
431 | } else { #elsif ($filename ne $name_collection{$name_sec}) { | |
432 | print "$id $name_sec also in $name_collection{$name_sec}\n"; | |
433 | } | |
434 | } | |
435 | ||
436 | my @foreign_names = | |
437 | map { map { s/\s+//g; $_ } split(/,/, $_) } | |
438 | $contents =~ /=for\s+comment\s+foreign\s+manuals:\s*(.*)\n\n/; | |
439 | foreach (@foreign_names) { | |
440 | $name_collection{$_} = undef; # It still exists! | |
441 | } | |
442 | ||
443 | my @links = $contents =~ /L< | |
444 | # if the link is of the form L<something|name(s)>, | |
445 | # then remove 'something'. Note that 'something' | |
446 | # may contain POD codes as well... | |
447 | (?:(?:[^\|]|<[^>]*>)*\|)? | |
46f4e1be | 448 | # we're only interested in references that have |
9e183d22 RS |
449 | # a one digit section number |
450 | ([^\/>\(]+\(\d\)) | |
451 | /gx; | |
452 | $link_collection{$filename} = [ @links ]; | |
453 | } | |
454 | ||
455 | sub checklinks { | |
456 | foreach my $filename (sort keys %link_collection) { | |
457 | foreach my $link (@{$link_collection{$filename}}) { | |
458 | print "${filename}:1: reference to non-existing $link\n" | |
459 | unless exists $name_collection{$link}; | |
460 | } | |
461 | } | |
462 | } | |
463 | ||
274d1bee RS |
464 | sub publicize() { |
465 | foreach my $name ( &parsenum('util/libcrypto.num') ) { | |
466 | $public{$name} = 1; | |
467 | } | |
468 | foreach my $name ( &parsenum('util/libssl.num') ) { | |
469 | $public{$name} = 1; | |
470 | } | |
471 | foreach my $name ( &parsenum('util/private.num') ) { | |
472 | $public{$name} = 1; | |
473 | } | |
474 | } | |
475 | ||
e75138ab RS |
476 | my %skips = ( |
477 | 'aes128' => 1, | |
478 | 'aes192' => 1, | |
479 | 'aes256' => 1, | |
480 | 'aria128' => 1, | |
481 | 'aria192' => 1, | |
482 | 'aria256' => 1, | |
483 | 'camellia128' => 1, | |
484 | 'camellia192' => 1, | |
485 | 'camellia256' => 1, | |
486 | 'des' => 1, | |
487 | 'des3' => 1, | |
488 | 'idea' => 1, | |
489 | '[cipher]' => 1, | |
490 | '[digest]' => 1, | |
491 | ); | |
492 | ||
493 | sub checkflags() { | |
494 | my $cmd = shift; | |
495 | my %cmdopts; | |
496 | my %docopts; | |
497 | my $ok = 1; | |
498 | ||
499 | # Get the list of options in the command. | |
500 | open CFH, "./apps/openssl list --options $cmd|" | |
501 | || die "Can list options for $cmd, $!"; | |
502 | while ( <CFH> ) { | |
503 | chop; | |
504 | s/ .$//; | |
505 | $cmdopts{$_} = 1; | |
506 | } | |
507 | close CFH; | |
508 | ||
509 | # Get the list of flags from the synopsis | |
510 | open CFH, "<doc/man1/$cmd.pod" | |
511 | || die "Can't open $cmd.pod, $!"; | |
512 | while ( <CFH> ) { | |
513 | chop; | |
514 | last if /DESCRIPTION/; | |
515 | next unless /\[B<-([^ >]+)/; | |
516 | $docopts{$1} = 1; | |
517 | } | |
518 | close CFH; | |
519 | ||
520 | # See what's in the command not the manpage. | |
521 | my @undocced = (); | |
522 | foreach my $k ( keys %cmdopts ) { | |
523 | push @undocced, $k unless $docopts{$k}; | |
524 | } | |
525 | if ( scalar @undocced > 0 ) { | |
526 | $ok = 0; | |
527 | foreach ( @undocced ) { | |
528 | print "doc/man1/$cmd.pod: Missing -$_\n"; | |
529 | } | |
530 | } | |
531 | ||
532 | # See what's in the command not the manpage. | |
533 | my @unimpl = (); | |
534 | foreach my $k ( keys %docopts ) { | |
535 | push @unimpl, $k unless $cmdopts{$k}; | |
536 | } | |
537 | if ( scalar @unimpl > 0 ) { | |
538 | $ok = 0; | |
539 | foreach ( @unimpl ) { | |
540 | next if defined $skips{$_}; | |
541 | print "doc/man1/$cmd.pod: Not implemented -$_\n"; | |
542 | } | |
543 | } | |
544 | ||
545 | return $ok; | |
546 | } | |
547 | ||
a03749a8 | 548 | getopts('cdesolnphuv'); |
274d1bee RS |
549 | |
550 | &help() if $opt_h; | |
b5283535 | 551 | |
a085f43f | 552 | $opt_n = 1 if $opt_p; |
8d50b9c1 | 553 | $opt_u = 1 if $opt_d; |
b5283535 | 554 | $opt_e = 1 if $opt_s; |
a03749a8 | 555 | $opt_v = 1 if $opt_o || $opt_e; |
b5283535 MC |
556 | |
557 | die "Cannot use both -u and -v" if $opt_u && $opt_v; | |
558 | die "Cannot use both -d and -e" if $opt_d && $opt_e; | |
35ea640a | 559 | |
a03749a8 MC |
560 | # We only need to check c, l, n, u and v. |
561 | # Options d, e, s, o and p imply one of the above. | |
562 | die "Need one of -[cdesolnpuv] flags.\n" | |
b5283535 | 563 | unless $opt_c or $opt_l or $opt_n or $opt_u or $opt_v; |
71a8b855 | 564 | |
e75138ab RS |
565 | if ( $opt_c ) { |
566 | my $ok = 1; | |
567 | my @commands = (); | |
3dfda1a6 | 568 | |
e75138ab RS |
569 | # Get list of commands. |
570 | open FH, "./apps/openssl list -1 -commands|" | |
571 | || die "Can't list commands, $!"; | |
572 | while ( <FH> ) { | |
573 | chop; | |
574 | push @commands, $_; | |
575 | } | |
576 | close FH; | |
577 | ||
578 | # See if each has a manpage. | |
579 | foreach ( @commands ) { | |
580 | next if $_ eq 'help' || $_ eq 'exit'; | |
581 | if ( ! -f "doc/man1/$_.pod" ) { | |
582 | print "doc/man1/$_.pod does not exist\n"; | |
583 | $ok = 0; | |
584 | } else { | |
585 | $ok = 0 if not &checkflags($_); | |
586 | } | |
71a8b855 | 587 | } |
e75138ab RS |
588 | |
589 | # See what help is missing. | |
590 | open FH, "./apps/openssl list --missing-help |" | |
591 | || die "Can't list missing help, $!"; | |
592 | while ( <FH> ) { | |
593 | chop; | |
594 | my ($cmd, $flag) = split; | |
595 | print "$cmd has no help for -$flag\n"; | |
596 | $ok = 0; | |
597 | } | |
598 | close FH; | |
599 | ||
600 | exit 1 if not $ok; | |
71a8b855 | 601 | } |
9e183d22 RS |
602 | |
603 | if ( $opt_l ) { | |
23ab880d RL |
604 | foreach (@ARGV ? @ARGV : (glob('doc/*/*.pod'), |
605 | glob('doc/internal/*/*.pod'))) { | |
9e183d22 RS |
606 | collectnames($_); |
607 | } | |
608 | checklinks(); | |
609 | } | |
610 | ||
e75138ab RS |
611 | if ( $opt_n ) { |
612 | &publicize() if $opt_p; | |
613 | foreach (@ARGV ? @ARGV : glob('doc/*/*.pod')) { | |
614 | &check($_); | |
615 | } | |
23ab880d RL |
616 | { |
617 | local $opt_p = undef; | |
618 | foreach (@ARGV ? @ARGV : glob('doc/internal/*/*.pod')) { | |
619 | &check($_); | |
620 | } | |
621 | } | |
e75138ab RS |
622 | } |
623 | ||
b5283535 | 624 | if ( $opt_u || $opt_v) { |
23ab880d | 625 | my %temp = getdocced('doc/man3'); |
71a8b855 RS |
626 | foreach ( keys %temp ) { |
627 | $docced{$_} = $temp{$_}; | |
628 | } | |
a03749a8 MC |
629 | if ($opt_o) { |
630 | &printem('crypto', 'util/libcrypto.num', 'util/missingcrypto111.txt'); | |
631 | &printem('ssl', 'util/libssl.num', 'util/missingssl111.txt'); | |
632 | } else { | |
633 | &printem('crypto', 'util/libcrypto.num', 'util/missingcrypto.txt'); | |
634 | &printem('ssl', 'util/libssl.num', 'util/missingssl.txt'); | |
635 | } | |
9a2dfc0f | 636 | &checkmacros(); |
1bc74519 | 637 | } |
05ea606a | 638 | |
35ea640a | 639 | exit; |