2 # Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
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
14 use Carp qw(:DEFAULT cluck);
18 use File::Spec::Functions;
21 use lib "$FindBin::Bin/perl";
23 use OpenSSL::Util::Pod;
28 # Set to 1 for debug output
31 # Where to find openssl command
32 my $openssl = "./util/opensslwrap.sh";
47 # Print usage message and exit.
50 Find small errors (nits) in documentation. Options:
51 -c List undocumented commands and options
52 -d Detailed list of undocumented (implies -u)
53 -e Detailed list of new undocumented (implies -v)
54 -h Print this help message
56 -n Print nits in POD pages
57 -o Causes -e/-v to count symbols added since 1.1.1 as new (implies -v)
58 -u Count undocumented functions
59 -v Count new undocumented functions
68 $opt_v = 1 if $opt_o || $opt_e;
69 die "Cannot use both -u and -v"
71 die "Cannot use both -d and -e"
74 # We only need to check c, l, n, u and v.
75 # Options d, e, o imply one of the above.
76 die "Need one of -[cdehlnouv] flags.\n"
77 unless $opt_c or $opt_l or $opt_n or $opt_u or $opt_v;
80 my $temp = '/tmp/docnits.txt';
85 my @sections = ( 'man1', 'man3', 'man5', 'man7' );
86 my %mandatory_sections = (
87 '*' => [ 'NAME', 'DESCRIPTION', 'COPYRIGHT' ],
88 1 => [ 'SYNOPSIS', 'OPTIONS' ],
89 3 => [ 'SYNOPSIS', 'RETURN VALUES' ],
94 # Collect all POD files, both internal and public, and regardless of location
95 # We collect them in a hash table with each file being a key, so we can attach
96 # tags to them. For example, internal docs will have the word "internal"
99 # We collect files names on the fly, on known tag basis
100 my %collected_tags = ();
101 # We cache results based on tags
102 my %collected_results = ();
108 # files(TAGS => 'manual');
109 # files(TAGS => [ 'manual', 'man1' ]);
111 # This function returns an array of files corresponding to a set of tags
112 # given with the options "TAGS". The value of this option can be a single
113 # word, or an array of several words, which work as inclusive or exclusive
114 # selectors. Inclusive selectors are used to add one more set of files to
115 # the returned array, while exclusive selectors limit the set of files added
116 # to the array. The recognised tag values are:
118 # 'public_manual' - inclusive selector, adds public manuals to the
119 # returned array of files.
120 # 'internal_manual' - inclusive selector, adds internal manuals to the
121 # returned array of files.
122 # 'manual' - inclusive selector, adds any manual to the returned
123 # array of files. This is really a shorthand for
124 # 'public_manual' and 'internal_manual' combined.
125 # 'public_header' - inclusive selector, adds public headers to the
126 # returned array of files.
127 # 'header' - inclusive selector, adds any header file to the
128 # returned array of files. Since we currently only
129 # care about public headers, this is exactly
130 # equivalent to 'public_header', but is present for
133 # 'man1', 'man3', 'man5', 'man7'
134 # - exclusive selectors, only applicable together with
135 # any of the manual selectors. If any of these are
136 # present, only the manuals from the given sections
137 # will be include. If none of these are present,
138 # the manuals from all sections will be returned.
140 # All returned manual files come from configdata.pm.
141 # All returned header files come from looking inside
142 # "$config{sourcedir}/include/openssl"
145 my %opts = ( @_ ); # Make a copy of the arguments
147 $opts{TAGS} = [ $opts{TAGS} ] if ref($opts{TAGS}) eq '';
149 croak "No tags given, or not an array"
150 unless exists $opts{TAGS} && ref($opts{TAGS}) eq 'ARRAY';
152 my %tags = map { $_ => 1 } @{$opts{TAGS}};
153 $tags{public_manual} = 1
154 if $tags{manual} && ($tags{public} // !$tags{internal});
155 $tags{internal_manual} = 1
156 if $tags{manual} && ($tags{internal} // !$tags{public});
157 $tags{public_header} = 1
158 if $tags{header} && ($tags{public} // !$tags{internal});
159 delete $tags{manual};
160 delete $tags{header};
161 delete $tags{public};
162 delete $tags{internal};
164 my $tags_as_key = join(':', sort keys %tags);
166 cluck "DEBUG[files]: This is how we got here!" if $debug;
167 print STDERR "DEBUG[files]: tags: $tags_as_key\n" if $debug;
169 my %tags_to_collect = ( map { $_ => 1 }
170 grep { !exists $collected_tags{$_} }
173 if ($tags_to_collect{public_manual}) {
174 print STDERR "DEBUG[files]: collecting public manuals\n"
177 # The structure in configdata.pm is that $unified_info{mandocs}
178 # contains lists of man files, and in turn, $unified_info{depends}
179 # contains hash tables showing which POD file each of those man
180 # files depend on. We use that information to find the POD files,
181 # and to attach the man section they belong to as tags
182 foreach my $mansect ( @sections ) {
183 foreach ( map { @{$unified_info{depends}->{$_}} }
184 @{$unified_info{mandocs}->{$mansect}} ) {
185 $files{$_} = { $mansect => 1, public_manual => 1 };
188 $collected_tags{public_manual} = 1;
191 if ($tags_to_collect{internal_manual}) {
192 print STDERR "DEBUG[files]: collecting internal manuals\n"
195 # We don't have the internal docs in configdata.pm. However, they
196 # are all in the source tree, so they're easy to find.
197 foreach my $mansect ( @sections ) {
198 foreach ( glob(catfile($config{sourcedir},
199 'doc', 'internal', $mansect, '*.pod')) ) {
200 $files{$_} = { $mansect => 1, internal_manual => 1 };
203 $collected_tags{internal_manual} = 1;
206 if ($tags_to_collect{public_header}) {
207 print STDERR "DEBUG[files]: collecting public headers\n"
210 foreach ( glob(catfile($config{sourcedir},
211 'include', 'openssl', '*.h')) ) {
212 $files{$_} = { public_header => 1 };
216 my @result = @{$collected_results{$tags_as_key} // []};
219 # Produce a result based on caller tags
220 foreach my $type ( ( 'public_manual', 'internal_manual' ) ) {
221 next unless $tags{$type};
223 # If caller asked for specific sections, we care about sections.
224 # Otherwise, we give back all of them.
225 my @selected_sections =
226 grep { $tags{$_} } @sections;
227 @selected_sections = @sections unless @selected_sections;
229 foreach my $section ( ( @selected_sections ) ) {
231 ( sort { basename($a) cmp basename($b) }
232 grep { $files{$_}->{$type} && $files{$_}->{$section} }
236 if ($tags{public_header}) {
238 ( sort { basename($a) cmp basename($b) }
239 grep { $files{$_}->{public_header} }
244 print STDERR "DEBUG[files]: result:\n";
245 print STDERR "DEBUG[files]: $_\n" foreach @result;
247 $collected_results{$tags_as_key} = [ @result ];
253 # Print error message, set $status.
255 print join(" ", @_), "\n";
259 # Cross-check functions in the NAME and SYNOPSIS section.
262 my $filename = shift;
263 my $contents = shift;
265 # Get NAME section and all words in it.
266 return unless $contents =~ /=head1 NAME(.*)=head1 SYNOPSIS/ms;
269 err($id, "Trailing comma before - in NAME")
272 err($id, "POD markup among the names in NAME")
275 err($id, "Missing comma in NAME")
278 my $dirname = dirname($filename);
279 my $section = basename($dirname);
280 my $simplename = basename($filename, ".pod");
281 my $foundfilename = 0;
282 my %foundfilenames = ();
284 foreach my $n ( split ',', $tmp ) {
287 err($id, "The name '$n' contains white-space")
290 $foundfilename++ if $n eq $simplename;
291 $foundfilenames{$n} = 1
292 if ( ( grep { basename($_) eq "$n.pod" }
293 files(TAGS => [ 'manual', $section ]) )
294 && $n ne $simplename );
296 err($id, "The following exist as other .pod files:",
297 sort keys %foundfilenames)
299 err($id, "$simplename (filename) missing from NAME section")
300 unless $foundfilename;
301 if ( $filename !~ /internal/ ) {
302 foreach my $n ( keys %names ) {
303 err($id, "$n is not public")
304 if !defined $public{$n};
308 # Find all functions in SYNOPSIS
309 return unless $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms;
311 foreach my $line ( split /\n+/, $syn ) {
312 next unless $line =~ /^\s/;
314 my $is_prototype = 1;
315 $line =~ s/STACK_OF\([^)]+\)/int/g;
316 $line =~ s/SPARSE_ARRAY_OF\([^)]+\)/int/g;
317 $line =~ s/__declspec\([^)]+\)//;
318 if ( $line =~ /typedef.*\(\*\S+\)\s+\(/ ) {
319 # a callback function with whitespace before the argument list:
320 # typedef ... (*NAME) (...
321 err($id, "Function typedef has space before arg list: $line");
323 if ( $line =~ /env (\S*)=/ ) {
324 # environment variable env NAME=...
326 } elsif ( $line =~ /typedef.*\(\*(\S+)\)\s*\(/ ) {
327 # a callback function pointer: typedef ... (*NAME)(...
329 } elsif ( $line =~ /typedef.* (\S+)\(/ ) {
330 # a callback function signature: typedef ... NAME(...
332 } elsif ( $line =~ /typedef.* (\S+);/ ) {
333 # a simple typedef: typedef ... NAME;
336 } elsif ( $line =~ /enum (\S*) \{/ ) {
337 # an enumeration: enum ... {
339 } elsif ( $line =~ /#(?:define|undef) ([A-Za-z0-9_]+)/ ) {
342 } elsif ( $line =~ /([A-Za-z0-9_]+)\(/ ) {
348 err($id, "$sym missing from NAME section")
349 unless defined $names{$sym};
352 # Do some sanity checks on the prototype.
353 err($id, "Prototype missing spaces around commas: $line")
354 if $is_prototype && $line =~ /[a-z0-9],[^ ]/;
357 foreach my $n ( keys %names ) {
358 next if $names{$n} == 2;
359 err($id, "$n missing from SYNOPSIS")
363 # Check if SECTION ($3) is located before BEFORE ($4)
364 sub check_section_location {
366 my $contents = shift;
370 return unless $contents =~ /=head1 $section/
371 and $contents =~ /=head1 $before/;
372 err($id, "$section should appear before $before section")
373 if $contents =~ /=head1 $before.*=head1 $section/ms;
376 # Check if a =head1 is duplicated, or a =headX is duplicated within a
377 # =head1. Treats =head2 =head3 as equivalent -- it doesn't reset the head3
378 # sets if it finds a =head2 -- but that is good enough for now. Also check
379 # for proper capitalization, trailing periods, etc.
380 sub check_head_style {
382 my $contents = shift;
386 foreach my $line ( split /\n+/, $contents ) {
387 next unless $line =~ /^=head/;
388 if ( $line =~ /head1/ ) {
389 err($id, "Duplicate section $line")
390 if defined $head1{$line};
394 err($id, "Duplicate subsection $line")
395 if defined $subheads{$line};
396 $subheads{$line} = 1;
398 err($id, "Period in =head")
399 if $line =~ /\.[^\w]/ or $line =~ /\.$/;
400 err($id, "not all uppercase in =head1")
401 if $line =~ /head1.*[a-z]/;
402 err($id, "All uppercase in subhead")
403 if $line =~ /head[234][ A-Z0-9]+$/;
407 # Because we have options and symbols with extra markup, we need
408 # to take that into account, so we need a regexp that extracts
409 # markup chunks, including recursive markup.
410 # please read up on /(?R)/ in perlre(1)
411 # (note: order is important, (?R) needs to come before .)
412 # (note: non-greedy is important, or something like 'B<foo> and B<bar>'
413 # will be captured as one item)
416 [BIL]< # The start of what we recurse on
417 (?:(?-1)|.)*? # recurse the whole regexp (referring to
418 # the last opened capture group, i.e. the
419 # start of this regexp), or pick next
420 # character. Do NOT be greedy!
421 > # The end of what we recurse on
422 )/x; # (the x allows this sort of split up regexp)
424 # Options must start with a dash, followed by a letter, possibly
425 # followed by letters, digits, dashes and underscores, and the last
426 # character must be a letter or a digit.
427 # We do also accept the single -? or -n, where n is a digit
430 \? # Single question mark
436 [[:alpha:]](?:[-_[:alnum:]]*?[[:alnum:]])?
439 # Helper function to check if a given $thing is properly marked up
440 # option. It returns one of these values:
441 # undef if it's not an option
442 # "" if it's a malformed option
443 # $unwrapped the option with the outermost B<> wrapping removed.
444 sub normalise_option {
446 my $filename = shift;
449 my $unwrapped = $thing;
450 my $unmarked = $thing;
452 # $unwrapped is the option with the outer B<> markup removed
453 $unwrapped =~ s/^B<//;
454 $unwrapped =~ s/>$//;
455 # $unmarked is the option with *all* markup removed
456 $unmarked =~ s/[BIL]<|>//msg;
459 # If we found an option, check it, collect it
460 if ( $unwrapped =~ /^\s*-/ ) {
461 return $unwrapped # return option with outer B<> removed
462 if $unmarked =~ /^-${option_re}$/;
463 return ""; # Malformed option
465 return undef; # Something else
468 # Checks of command option (man1) formatting. The man1 checks are
469 # restricted to the SYNOPSIS and OPTIONS sections, the rest is too
470 # free form, we simply cannot be too strict there.
474 my $filename = shift;
475 my $contents = shift;
477 my $synopsis = ($contents =~ /=head1\s+SYNOPSIS(.*?)=head1/s, $1);
479 # Some pages have more than one OPTIONS section, let's make sure
482 while ( $contents =~ /=head1\s+[A-Z ]*?OPTIONS$(.*?)(?==head1)/msg ) {
486 # Look for options with no or incorrect markup
488 /(?<![-<[:alnum:]])-(?:$markup_re|.)*(?![->[:alnum:]])/msg ) {
489 err($id, "Malformed option [1] in SYNOPSIS: $&");
492 while ( $synopsis =~ /$markup_re/msg ) {
494 print STDERR "$id:DEBUG[option_check] SYNOPSIS: found $found\n"
496 my $option_uw = normalise_option($id, $filename, $found);
497 err($id, "Malformed option [2] in SYNOPSIS: $found")
498 if defined $option_uw && $option_uw eq '';
501 # In OPTIONS, we look for =item paragraphs.
502 # (?=^\s*$) detects an empty line.
503 while ( $options =~ /=item\s+(.*?)(?=^\s*$)/msg ) {
506 while ( $item =~ /(\[\s*)?($markup_re)/msg ) {
508 print STDERR "$id:DEBUG[option_check] OPTIONS: found $&\n"
510 err($id, "Unexpected bracket in OPTIONS =item: $item")
511 if ($1 // '') ne '' && $found =~ /^B<\s*-/;
513 my $option_uw = normalise_option($id, $filename, $found);
514 err($id, "Malformed option in OPTIONS: $found")
515 if defined $option_uw && $option_uw eq '';
521 my $symbol_re = qr/[[:alpha:]_][_[:alnum:]]*?/;
523 # Checks of function name (man3) formatting. The man3 checks are
524 # easier than the man1 checks, we only check the names followed by (),
525 # and only the names that have POD markup.
526 sub functionname_check {
528 my $filename = shift;
529 my $contents = shift;
531 while ( $contents =~ /($markup_re)\(\)/msg ) {
532 print STDERR "$id:DEBUG[functionname_check] SYNOPSIS: found $&\n"
536 my $unmarked = $symbol;
537 $unmarked =~ s/[BIL]<|>//msg;
539 err($id, "Malformed symbol: $symbol")
540 unless $symbol =~ /^B<.*>$/ && $unmarked =~ /^${symbol_re}$/
543 # We can't do the kind of collecting coolness that option_check()
544 # does, because there are too many things that can't be found in
545 # name repositories like the NAME sections, such as symbol names
546 # with a variable part (typically marked up as B<foo_I<TYPE>_bar>
549 # This is from http://man7.org/linux/man-pages/man7/man-pages.7.html
550 my %preferred_words = (
551 'bitmask' => 'bit mask',
552 'builtin' => 'built-in',
553 #'epoch' => 'Epoch', # handled specially, below
554 'file name' => 'filename',
555 'file system' => 'filesystem',
556 'host name' => 'hostname',
558 'lower case' => 'lowercase',
559 'lower-case' => 'lowercase',
560 'non-zero' => 'nonzero',
561 'path name' => 'pathname',
562 'pseudo-terminal' => 'pseudoterminal',
563 'reserved port' => 'privileged port',
564 'system port' => 'privileged port',
565 'realtime' => 'real-time',
566 'real time' => 'real-time',
567 'runtime' => 'run time',
568 'saved group ID'=> 'saved set-group-ID',
569 'saved set-GID' => 'saved set-group-ID',
570 'saved user ID' => 'saved set-user-ID',
571 'saved set-UID' => 'saved set-user-ID',
572 'set-GID' => 'set-group-ID',
573 'setgid' => 'set-group-ID',
574 'set-UID' => 'set-user-ID',
575 'setuid' => 'set-user-ID',
576 'super user' => 'superuser',
577 'super-user' => 'superuser',
578 'super block' => 'superblock',
579 'super-block' => 'superblock',
580 'time stamp' => 'timestamp',
581 'time zone' => 'timezone',
582 'upper case' => 'uppercase',
583 'upper-case' => 'uppercase',
584 'useable' => 'usable',
585 'userspace' => 'user space',
586 'user name' => 'username',
590 # Search manpage for words that have a different preferred use.
593 my $contents = shift;
595 foreach my $k ( keys %preferred_words ) {
597 next if $k eq 'file system'
598 and $contents =~ /Microsoft Encrypted File System/;
599 err($id, "Found '$k' should use '$preferred_words{$k}'")
600 if $contents =~ /\b\Q$k\E\b/i;
602 err($id, "Found 'epoch' should use 'Epoch'")
603 if $contents =~ /\bepoch\b/;
604 if ( $id =~ m@man1/@ ) {
605 err($id, "found 'tool' in NAME, should use 'command'")
606 if $contents =~ /=head1 NAME.*\btool\b.*=head1 SYNOPSIS/s;
607 err($id, "found 'utility' in NAME, should use 'command'")
608 if $contents =~ /NAME.*\butility\b.*=head1 SYNOPSIS/s;
613 # Perform all sorts of nit/error checks on a manpage
615 my $filename = shift;
616 my $dirname = basename(dirname($filename));
621 open POD, $filename or die "Couldn't open $filename, $!";
626 my $id = "${filename}:1:";
627 check_head_style($id, $contents);
629 # Check ordering of some sections in man3
630 if ( $filename =~ m|man3/| ) {
631 check_section_location($id, $contents, "RETURN VALUES", "EXAMPLES");
632 check_section_location($id, $contents, "SEE ALSO", "HISTORY");
633 check_section_location($id, $contents, "EXAMPLES", "SEE ALSO");
636 # Make sure every link has a section.
637 while ( $contents =~ /$markup_re/msg ) {
639 next unless $target =~ /^L<(.*)>$/; # Skip if not L<...>
640 $target = $1; # Peal away L< and >
641 $target =~ s/\/[^\/]*$//; # Peal away possible anchor
642 $target =~ s/.*\|//g; # Peal away possible link text
643 next if $target eq ''; # Skip if links within page, or
644 next if $target =~ /::/; # links to a Perl module, or
645 next if $target =~ /^https?:/; # is a URL link, or
646 next if $target =~ /\([1357]\)$/; # it has a section
647 err($id, "Section missing in $target")
649 # Check for proper links to commands.
650 while ( $contents =~ /L<([^>]*)\(1\)(?:\/.*)?>/g ) {
652 next if $target =~ /openssl-?/;
653 next if ( grep { basename($_) eq "$target.pod" }
654 files(TAGS => [ 'manual', 'man1' ]) );
655 # TODO: Filter out "foreign manual" links.
656 next if $target =~ /ps|apropos|sha1sum|procmail|perl/;
657 err($id, "Bad command link L<$target(1)>");
659 # Check for proper in-man-3 API links.
660 while ( $contents =~ /L<([^>]*)\(3\)(?:\/.*)?>/g ) {
662 err($id, "Bad L<$target>")
663 unless $target =~ /^[_[:alpha:]][_[:alnum:]]*$/
666 unless ( $contents =~ /=for openssl generic/ ) {
667 if ( $filename =~ m|man3/| ) {
668 name_synopsis($id, $filename, $contents);
669 functionname_check($id, $filename, $contents);
670 } elsif ( $filename =~ m|man1/| ) {
671 option_check($id, $filename, $contents)
675 wording($id, $contents);
677 err($id, "Doesn't start with =pod")
678 if $contents !~ /^=pod/;
679 err($id, "Doesn't end with =cut")
680 if $contents !~ /=cut\n$/;
681 err($id, "More than one cut line.")
682 if $contents =~ /=cut.*=cut/ms;
683 err($id, "EXAMPLE not EXAMPLES section.")
684 if $contents =~ /=head1 EXAMPLE[^S]/;
685 err($id, "WARNING not WARNINGS section.")
686 if $contents =~ /=head1 WARNING[^S]/;
687 err($id, "Missing copyright")
688 if $contents !~ /Copyright .* The OpenSSL Project Authors/;
689 err($id, "Copyright not last")
690 if $contents =~ /head1 COPYRIGHT.*=head/ms;
691 err($id, "head2 in All uppercase")
692 if $contents =~ /head2\s+[A-Z ]+\n/;
693 err($id, "Extra space after head")
694 if $contents =~ /=head\d\s\s+/;
695 err($id, "Period in NAME section")
696 if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms;
697 err($id, "Duplicate $1 in L<>")
698 if $contents =~ /L<([^>]*)\|([^>]*)>/ && $1 eq $2;
699 err($id, "Bad =over $1")
700 if $contents =~ /=over([^ ][^24])/;
701 err($id, "Possible version style issue")
702 if $contents =~ /OpenSSL version [019]/;
704 if ( $contents !~ /=for openssl multiple includes/ ) {
705 # Look for multiple consecutive openssl #include lines
706 # (non-consecutive lines are okay; see man3/MD5.pod).
707 if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) {
709 foreach my $line ( split /\n+/, $1 ) {
710 if ( $line =~ m@include <openssl/@ ) {
711 err($id, "Has multiple includes")
720 open my $OUT, '>', $temp
721 or die "Can't open $temp, $!";
722 podchecker($filename, $OUT);
724 open $OUT, '<', $temp
725 or die "Can't read $temp, $!";
727 next if /\(section\) in.*deprecated/;
731 unlink $temp || warn "Can't remove $temp, $!";
733 # Find what section this page is in; assume 3.
735 $section = $1 if $dirname =~ /man([1-9])/;
737 foreach ( (@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}}) ) {
738 err($id, "Missing $_ head1 section")
739 if $contents !~ /^=head1\s+${_}\s*$/m;
743 # Parse libcrypto.num, etc., and return sorted list of what's there.
748 open my $IN, '<', catfile($config{sourcedir}, $file)
749 or die "Can't open $file, $!, stopped";
753 next if /\bNOEXIST\b/;
754 my @fields = split();
755 die "Malformed line $. in $file: $_"
756 if scalar @fields != 2 && scalar @fields != 4;
757 push @apis, $fields[0];
765 # Parse all the manpages, getting return map of what they document
766 # (by looking at their NAME sections).
767 # Map of links in each POD file; filename => [ "foo(1)", "bar(3)", ... ]
769 # Map of names in each POD file; "name(s)" => filename
772 # Load file of symbol names that we know aren't documented.
775 my $missingfile = shift;
778 open FH, catfile($config{sourcedir}, $missingfile)
779 or die "Can't open $missingfile";
788 err("$missingfile:", "$_ is documented in $name_map{$_}")
789 if !$opt_o && exists $name_map{$_} && defined $name_map{$_};
795 # Check for undocumented macros; ignore those in the "missing" file
796 # and do simple check for #define in our header files.
803 @missing = loadmissing('util/missingmacro111.txt');
805 @missing = loadmissing('util/missingmacro.txt');
808 foreach my $f ( files(TAGS => 'public_header') ) {
809 # Skip some internals we don't want to document yet.
810 my $b = basename($f);
811 next if $b eq 'asn1.h';
812 next if $b eq 'asn1t.h';
813 next if $b eq 'err.h';
815 or die "Can't open $f, $!";
817 next unless /^#\s*define\s*(\S+)\(/;
818 my $macro = "$1(3)"; # We know they're all in section 3
819 next if exists $name_map{$macro} || defined $seen{$macro};
820 next if $macro =~ /^i2d_/
822 || $macro =~ /^DEPRECATEDIN/
823 || $macro =~ /\Q_fnsig(3)\E$/
824 || $macro =~ /^IMPLEMENT_/
825 || $macro =~ /^_?DECLARE_/;
827 # Skip macros known to be missing
828 next if $opt_v && grep( /^\Q$macro\E$/, @missing);
830 err("$f:", "macro $macro undocumented")
837 err("# $count macros undocumented (count is approximate)")
841 # Find out what is undocumented (filtering out the known missing ones)
846 my $missingfile = shift;
850 my @missing = loadmissing($missingfile) if $opt_v;
852 foreach my $func ( parsenum($numfile) ) {
853 $func .= '(3)'; # We know they're all in section 3
854 next if exists $name_map{$func} || defined $seen{$func};
856 # Skip functions known to be missing.
857 next if $opt_v && grep( /^\Q$func\E$/, @missing);
859 err("$libname:", "function $func undocumented")
864 err("# $count in $numfile are not documented")
868 # Collect all the names in a manpage.
870 my $filename = shift;
871 $filename =~ m|man(\d)/|;
873 my $simplename = basename($filename, ".pod");
874 my $id = "${filename}:1:";
875 my %podinfo = extract_pod_info($filename, { debug => $debug });
877 unless ( grep { $simplename eq $_ } @{$podinfo{names}} ) {
878 err($id, "$simplename not in NAME section");
879 push @{$podinfo{names}}, $simplename;
881 foreach my $name ( @{$podinfo{names}} ) {
883 err($id, "'$name' contains white space")
885 my $name_sec = "$name($section)";
886 if ( !exists $name_map{$name_sec} ) {
887 $name_map{$name_sec} = $filename;
888 } elsif ( $filename eq $name_map{$name_sec} ) {
889 err($id, "$name_sec duplicated in NAME section of",
890 $name_map{$name_sec});
892 err($id, "$name_sec also in NAME section of",
893 $name_map{$name_sec});
897 if ( $podinfo{contents} =~ /=for openssl foreign manual (.*)\n/ ) {
898 foreach my $f ( split / /, $1 ) {
899 $name_map{$f} = undef; # It still exists!
904 $podinfo{contents} =~ /L<
905 # if the link is of the form L<something|name(s)>,
906 # then remove 'something'. Note that 'something'
907 # may contain POD codes as well...
908 (?:(?:[^\|]|<[^>]*>)*\|)?
909 # we're only interested in references that have
910 # a one digit section number
913 $link_map{$filename} = [ @links ];
916 # Look for L<> ("link") references that point to files that do not exist.
918 foreach my $filename ( sort keys %link_map ) {
919 foreach my $link ( @{$link_map{$filename}} ) {
920 err("${filename}:1:", "reference to non-existing $link")
921 unless exists $name_map{$link};
926 # Load the public symbol/macro names
928 foreach my $name ( parsenum('util/libcrypto.num') ) {
931 foreach my $name ( parsenum('util/libssl.num') ) {
934 foreach my $name ( parsenum('util/other.syms') ) {
939 # Cipher/digests to skip if they show up as "not implemented"
940 # because they are, via the "-*" construct.
958 # Check the flags of a command and see if everything is in the manpage
966 # Get the list of options in the command.
967 open CFH, "$openssl list --options $cmd|"
968 or die "Can list options for $cmd, $!";
976 # Get the list of flags from the synopsis
978 or die "Can't open $doc, $!";
981 last if /DESCRIPTION/;
982 if ( /=for openssl ifdef (.*)/ ) {
983 foreach my $f ( split / /, $1 ) {
989 if ( /\[B<-([^ >]+)/ ) {
991 } elsif ( /^B<-([^ >]+)/ ) {
996 $opt = $1 if $opt =~ /I<(.*)/;
1001 # See what's in the command not the manpage.
1002 my @undocced = sort grep { !defined $docopts{$_} } keys %cmdopts;
1003 foreach ( @undocced ) {
1004 next if /-/; # Skip the -- end-of-flags marker
1005 err("$doc: undocumented option -$_");
1008 # See what's in the command not the manpage.
1009 my @unimpl = sort grep { !defined $cmdopts{$_} } keys %docopts;
1010 foreach ( @unimpl ) {
1011 next if defined $skips{$_} || defined $localskips{$_};
1012 err("$doc: $cmd does not implement -$_");
1018 ## Do the work requested by the various getopt flags.
1019 ## The flags are parsed in alphabetical order, just because we have
1020 ## to have *some way* of listing them.
1026 # Get list of commands.
1027 open FH, "$openssl list -1 -commands|"
1028 or die "Can't list commands, $!";
1035 # See if each has a manpage.
1036 foreach my $cmd ( @commands ) {
1037 next if $cmd eq 'help' || $cmd eq 'exit';
1038 my @doc = ( grep { basename($_) eq "openssl-$cmd.pod"
1039 # For "tsget" and "CA.pl" pod pages
1040 || basename($_) eq "$cmd.pod" }
1041 files(TAGS => [ 'manual', 'man1' ]) );
1042 my $num = scalar @doc;
1044 err("$num manuals for 'openssl $cmd': ".join(", ", @doc));
1045 } elsif ($num < 1) {
1046 err("no manual for 'openssl $cmd'");
1048 checkflags($cmd, @doc);
1052 # See what help is missing.
1053 open FH, "$openssl list --missing-help |"
1054 or die "Can't list missing help, $!";
1057 my ($cmd, $flag) = split;
1058 err("$cmd has no help for -$flag");
1065 # Preparation for some options, populate %name_map and %link_map
1066 if ( $opt_l || $opt_u || $opt_v ) {
1067 foreach ( files(TAGS => 'manual') ) {
1073 foreach my $func ( loadmissing("util/missingcrypto.txt") ) {
1074 $name_map{$func} = undef;
1081 foreach ( @ARGV ? @ARGV : files(TAGS => 'manual') ) {
1085 # If not given args, check that all man1 commands are named properly.
1086 if ( scalar @ARGV == 0 ) {
1087 foreach ( files(TAGS => [ 'public_manual', 'man1' ]) ) {
1088 next if /CA.pl/ || /openssl\.pod/ || /tsget\.pod/;
1089 err("$_ doesn't start with openssl-") unless /openssl-/;
1094 if ( $opt_u || $opt_v) {
1096 printem('crypto', 'util/libcrypto.num', 'util/missingcrypto111.txt');
1097 printem('ssl', 'util/libssl.num', 'util/missingssl111.txt');
1099 printem('crypto', 'util/libcrypto.num', 'util/missingcrypto.txt');
1100 printem('ssl', 'util/libssl.num', 'util/missingssl.txt');