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