2 # Copyright 2002-2021 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';
84 my @sections = ( 'man1', 'man3', 'man5', 'man7' );
85 my %mandatory_sections = (
86 '*' => [ 'NAME', 'DESCRIPTION', 'COPYRIGHT' ],
87 1 => [ 'SYNOPSIS', 'OPTIONS' ],
88 3 => [ 'SYNOPSIS', 'RETURN VALUES' ],
93 # Symbols that we ignored.
94 # They are reserved macros that we currently don't document
95 my $ignored = qr/(?| ^i2d_
103 | ^SKM_DEFINE_STACK_OF_INTERNAL
105 | ^DEFINE_LHASH_OF_INTERNAL
108 # A common regexp for C symbol names
109 my $C_symbol = qr/\b[[:alpha:]][_[:alnum:]]*\b/;
111 # Collect all POD files, both internal and public, and regardless of location
112 # We collect them in a hash table with each file being a key, so we can attach
113 # tags to them. For example, internal docs will have the word "internal"
116 # We collect files names on the fly, on known tag basis
117 my %collected_tags = ();
118 # We cache results based on tags
119 my %collected_results = ();
125 # files(TAGS => 'manual');
126 # files(TAGS => [ 'manual', 'man1' ]);
128 # This function returns an array of files corresponding to a set of tags
129 # given with the options "TAGS". The value of this option can be a single
130 # word, or an array of several words, which work as inclusive or exclusive
131 # selectors. Inclusive selectors are used to add one more set of files to
132 # the returned array, while exclusive selectors limit the set of files added
133 # to the array. The recognised tag values are:
135 # 'public_manual' - inclusive selector, adds public manuals to the
136 # returned array of files.
137 # 'internal_manual' - inclusive selector, adds internal manuals to the
138 # returned array of files.
139 # 'manual' - inclusive selector, adds any manual to the returned
140 # array of files. This is really a shorthand for
141 # 'public_manual' and 'internal_manual' combined.
142 # 'public_header' - inclusive selector, adds public headers to the
143 # returned array of files.
144 # 'header' - inclusive selector, adds any header file to the
145 # returned array of files. Since we currently only
146 # care about public headers, this is exactly
147 # equivalent to 'public_header', but is present for
150 # 'man1', 'man3', 'man5', 'man7'
151 # - exclusive selectors, only applicable together with
152 # any of the manual selectors. If any of these are
153 # present, only the manuals from the given sections
154 # will be include. If none of these are present,
155 # the manuals from all sections will be returned.
157 # All returned manual files come from configdata.pm.
158 # All returned header files come from looking inside
159 # "$config{sourcedir}/include/openssl"
162 my %opts = ( @_ ); # Make a copy of the arguments
164 $opts{TAGS} = [ $opts{TAGS} ] if ref($opts{TAGS}) eq '';
166 croak "No tags given, or not an array"
167 unless exists $opts{TAGS} && ref($opts{TAGS}) eq 'ARRAY';
169 my %tags = map { $_ => 1 } @{$opts{TAGS}};
170 $tags{public_manual} = 1
171 if $tags{manual} && ($tags{public} // !$tags{internal});
172 $tags{internal_manual} = 1
173 if $tags{manual} && ($tags{internal} // !$tags{public});
174 $tags{public_header} = 1
175 if $tags{header} && ($tags{public} // !$tags{internal});
176 delete $tags{manual};
177 delete $tags{header};
178 delete $tags{public};
179 delete $tags{internal};
181 my $tags_as_key = join(':', sort keys %tags);
183 cluck "DEBUG[files]: This is how we got here!" if $debug;
184 print STDERR "DEBUG[files]: tags: $tags_as_key\n" if $debug;
186 my %tags_to_collect = ( map { $_ => 1 }
187 grep { !exists $collected_tags{$_} }
190 if ($tags_to_collect{public_manual}) {
191 print STDERR "DEBUG[files]: collecting public manuals\n"
194 # The structure in configdata.pm is that $unified_info{mandocs}
195 # contains lists of man files, and in turn, $unified_info{depends}
196 # contains hash tables showing which POD file each of those man
197 # files depend on. We use that information to find the POD files,
198 # and to attach the man section they belong to as tags
199 foreach my $mansect ( @sections ) {
200 foreach ( map { @{$unified_info{depends}->{$_}} }
201 @{$unified_info{mandocs}->{$mansect}} ) {
202 $files{$_} = { $mansect => 1, public_manual => 1 };
205 $collected_tags{public_manual} = 1;
208 if ($tags_to_collect{internal_manual}) {
209 print STDERR "DEBUG[files]: collecting internal manuals\n"
212 # We don't have the internal docs in configdata.pm. However, they
213 # are all in the source tree, so they're easy to find.
214 foreach my $mansect ( @sections ) {
215 foreach ( glob(catfile($config{sourcedir},
216 'doc', 'internal', $mansect, '*.pod')) ) {
217 $files{$_} = { $mansect => 1, internal_manual => 1 };
220 $collected_tags{internal_manual} = 1;
223 if ($tags_to_collect{public_header}) {
224 print STDERR "DEBUG[files]: collecting public headers\n"
227 foreach ( glob(catfile($config{sourcedir},
228 'include', 'openssl', '*.h')) ) {
229 $files{$_} = { public_header => 1 };
233 my @result = @{$collected_results{$tags_as_key} // []};
236 # Produce a result based on caller tags
237 foreach my $type ( ( 'public_manual', 'internal_manual' ) ) {
238 next unless $tags{$type};
240 # If caller asked for specific sections, we care about sections.
241 # Otherwise, we give back all of them.
242 my @selected_sections =
243 grep { $tags{$_} } @sections;
244 @selected_sections = @sections unless @selected_sections;
246 foreach my $section ( ( @selected_sections ) ) {
248 ( sort { basename($a) cmp basename($b) }
249 grep { $files{$_}->{$type} && $files{$_}->{$section} }
253 if ($tags{public_header}) {
255 ( sort { basename($a) cmp basename($b) }
256 grep { $files{$_}->{public_header} }
261 print STDERR "DEBUG[files]: result:\n";
262 print STDERR "DEBUG[files]: $_\n" foreach @result;
264 $collected_results{$tags_as_key} = [ @result ];
270 # Print error message, set $status.
272 print join(" ", @_), "\n";
276 # Cross-check functions in the NAME and SYNOPSIS section.
279 my $filename = shift;
280 my $contents = shift;
282 # Get NAME section and all words in it.
283 return unless $contents =~ /=head1 NAME(.*)=head1 SYNOPSIS/ms;
286 err($id, "Trailing comma before - in NAME")
289 err($id, "POD markup among the names in NAME")
292 err($id, "Missing comma in NAME")
295 my $dirname = dirname($filename);
296 my $section = basename($dirname);
297 my $simplename = basename($filename, ".pod");
298 my $foundfilename = 0;
299 my %foundfilenames = ();
301 foreach my $n ( split ',', $tmp ) {
304 err($id, "The name '$n' contains white-space")
307 $foundfilename++ if $n eq $simplename;
308 $foundfilenames{$n} = 1
309 if ( ( grep { basename($_) eq "$n.pod" }
310 files(TAGS => [ 'manual', $section ]) )
311 && $n ne $simplename );
313 err($id, "The following exist as other .pod files:",
314 sort keys %foundfilenames)
316 err($id, "$simplename (filename) missing from NAME section")
317 unless $foundfilename;
319 # Find all functions in SYNOPSIS
320 return unless $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms;
322 my $ignore_until = undef; # If defined, this is a regexp
323 # Remove all non-code lines
324 $syn =~ s/^(?:\s*?|\S.*?)$//msg;
325 # Remove all comments
326 $syn =~ s/\/\*.*?\*\///msg;
328 # "env" lines end at a newline.
329 # Preprocessor lines start with a # and end at a newline.
330 # Other lines end with a semicolon, and may cover more than
332 if ( $syn !~ /^ \s*(env .*?|#.*?|.*?;)\s*$/ms ) {
333 err($id, "Can't parse rest of synopsis:\n$syn\n(declarations not ending with a semicolon (;)?)");
339 print STDERR "DEBUG[name_synopsis] \$line = '$line'\n" if $debug;
341 # Special code to skip over documented structures
342 if ( defined $ignore_until) {
343 next if $line !~ /$ignore_until/;
344 $ignore_until = undef;
347 if ( $line =~ /^\s*(?:typedef\s+)?struct(?:\s+\S+)\s*\{/ ) {
348 $ignore_until = qr/\}.*?;/;
353 my $is_prototype = 1;
354 $line =~ s/STACK_OF\([^)]+\)/int/g;
355 $line =~ s/SPARSE_ARRAY_OF\([^)]+\)/int/g;
356 $line =~ s/__declspec\([^)]+\)//;
358 ## We don't prohibit that space, to allow typedefs looking like
361 ## typedef int (fantastically_long_name_breaks_80char_limit)
362 ## (fantastically_long_name_breaks_80char_limit *something);
364 #if ( $line =~ /typedef.*\(\*?\S+\)\s+\(/ ) {
365 # # a callback function with whitespace before the argument list:
366 # # typedef ... (*NAME) (...
367 # # typedef ... (NAME) (...
368 # err($id, "Function typedef has space before arg list: $line");
371 if ( $line =~ /env (\S*)=/ ) {
372 # environment variable env NAME=...
374 } elsif ( $line =~ /typedef.*\(\*?($C_symbol)\)\s*\(/ ) {
375 # a callback function pointer: typedef ... (*NAME)(...
376 # a callback function signature: typedef ... (NAME)(...
378 } elsif ( $line =~ /typedef.*($C_symbol)\s*\(/ ) {
379 # a callback function signature: typedef ... NAME(...
381 } elsif ( $line =~ /typedef.*($C_symbol);/ ) {
382 # a simple typedef: typedef ... NAME;
385 } elsif ( $line =~ /enum ($C_symbol) \{/ ) {
386 # an enumeration: enum ... {
388 } elsif ( $line =~ /#\s*(?:define|undef) ($C_symbol)/ ) {
391 } elsif ( $line =~ /^[^\(]*?\(\*($C_symbol)\s*\(/ ) {
392 # a function returning a function pointer: TYPE (*NAME(args))(args)
394 } elsif ( $line =~ /^[^\(]*?($C_symbol)\s*\(/ ) {
395 # a simple function declaration
402 print STDERR "DEBUG[name_synopsis] \$sym = '$sym'\n" if $debug;
404 err($id, "$sym missing from NAME section")
405 unless defined $names{$sym};
408 # Do some sanity checks on the prototype.
409 err($id, "Prototype missing spaces around commas: $line")
410 if $is_prototype && $line =~ /[a-z0-9],[^\s]/;
413 foreach my $n ( keys %names ) {
414 next if $names{$n} == 2;
415 err($id, "$n missing from SYNOPSIS")
419 # Check if SECTION ($3) is located before BEFORE ($4)
420 sub check_section_location {
422 my $contents = shift;
426 return unless $contents =~ /=head1 $section/
427 and $contents =~ /=head1 $before/;
428 err($id, "$section should appear before $before section")
429 if $contents =~ /=head1 $before.*=head1 $section/ms;
432 # Check if a =head1 is duplicated, or a =headX is duplicated within a
433 # =head1. Treats =head2 =head3 as equivalent -- it doesn't reset the head3
434 # sets if it finds a =head2 -- but that is good enough for now. Also check
435 # for proper capitalization, trailing periods, etc.
436 sub check_head_style {
438 my $contents = shift;
442 foreach my $line ( split /\n+/, $contents ) {
443 next unless $line =~ /^=head/;
444 if ( $line =~ /head1/ ) {
445 err($id, "Duplicate section $line")
446 if defined $head1{$line};
450 err($id, "Duplicate subsection $line")
451 if defined $subheads{$line};
452 $subheads{$line} = 1;
454 err($id, "Period in =head")
455 if $line =~ /\.[^\w]/ or $line =~ /\.$/;
456 err($id, "not all uppercase in =head1")
457 if $line =~ /head1.*[a-z]/;
458 err($id, "All uppercase in subhead")
459 if $line =~ /head[234][ A-Z0-9]+$/;
463 # Because we have options and symbols with extra markup, we need
464 # to take that into account, so we need a regexp that extracts
465 # markup chunks, including recursive markup.
466 # please read up on /(?R)/ in perlre(1)
467 # (note: order is important, (?R) needs to come before .)
468 # (note: non-greedy is important, or something like 'B<foo> and B<bar>'
469 # will be captured as one item)
472 [BIL]< # The start of what we recurse on
473 (?:(?-1)|.)*? # recurse the whole regexp (referring to
474 # the last opened capture group, i.e. the
475 # start of this regexp), or pick next
476 # character. Do NOT be greedy!
477 > # The end of what we recurse on
478 )/x; # (the x allows this sort of split up regexp)
480 # Options must start with a dash, followed by a letter, possibly
481 # followed by letters, digits, dashes and underscores, and the last
482 # character must be a letter or a digit.
483 # We do also accept the single -? or -n, where n is a digit
486 \? # Single question mark
492 [[:alpha:]](?:[-_[:alnum:]]*?[[:alnum:]])?
495 # Helper function to check if a given $thing is properly marked up
496 # option. It returns one of these values:
497 # undef if it's not an option
498 # "" if it's a malformed option
499 # $unwrapped the option with the outermost B<> wrapping removed.
500 sub normalise_option {
502 my $filename = shift;
505 my $unwrapped = $thing;
506 my $unmarked = $thing;
508 # $unwrapped is the option with the outer B<> markup removed
509 $unwrapped =~ s/^B<//;
510 $unwrapped =~ s/>$//;
511 # $unmarked is the option with *all* markup removed
512 $unmarked =~ s/[BIL]<|>//msg;
515 # If we found an option, check it, collect it
516 if ( $unwrapped =~ /^\s*-/ ) {
517 return $unwrapped # return option with outer B<> removed
518 if $unmarked =~ /^-${option_re}$/;
519 return ""; # Malformed option
521 return undef; # Something else
524 # Checks of command option (man1) formatting. The man1 checks are
525 # restricted to the SYNOPSIS and OPTIONS sections, the rest is too
526 # free form, we simply cannot be too strict there.
530 my $filename = shift;
531 my $contents = shift;
533 my $synopsis = ($contents =~ /=head1\s+SYNOPSIS(.*?)=head1/s, $1);
535 # Some pages have more than one OPTIONS section, let's make sure
538 while ( $contents =~ /=head1\s+[A-Z ]*?OPTIONS$(.*?)(?==head1)/msg ) {
542 # Look for options with no or incorrect markup
544 /(?<![-<[:alnum:]])-(?:$markup_re|.)*(?![->[:alnum:]])/msg ) {
545 err($id, "Malformed option [1] in SYNOPSIS: $&");
548 while ( $synopsis =~ /$markup_re/msg ) {
550 print STDERR "$id:DEBUG[option_check] SYNOPSIS: found $found\n"
552 my $option_uw = normalise_option($id, $filename, $found);
553 err($id, "Malformed option [2] in SYNOPSIS: $found")
554 if defined $option_uw && $option_uw eq '';
557 # In OPTIONS, we look for =item paragraphs.
558 # (?=^\s*$) detects an empty line.
559 while ( $options =~ /=item\s+(.*?)(?=^\s*$)/msg ) {
562 while ( $item =~ /(\[\s*)?($markup_re)/msg ) {
564 print STDERR "$id:DEBUG[option_check] OPTIONS: found $&\n"
566 err($id, "Unexpected bracket in OPTIONS =item: $item")
567 if ($1 // '') ne '' && $found =~ /^B<\s*-/;
569 my $option_uw = normalise_option($id, $filename, $found);
570 err($id, "Malformed option in OPTIONS: $found")
571 if defined $option_uw && $option_uw eq '';
577 my $symbol_re = qr/[[:alpha:]_][_[:alnum:]]*?/;
579 # Checks of function name (man3) formatting. The man3 checks are
580 # easier than the man1 checks, we only check the names followed by (),
581 # and only the names that have POD markup.
582 sub functionname_check {
584 my $filename = shift;
585 my $contents = shift;
587 while ( $contents =~ /($markup_re)\(\)/msg ) {
588 print STDERR "$id:DEBUG[functionname_check] SYNOPSIS: found $&\n"
592 my $unmarked = $symbol;
593 $unmarked =~ s/[BIL]<|>//msg;
595 err($id, "Malformed symbol: $symbol")
596 unless $symbol =~ /^B<.*?>$/ && $unmarked =~ /^${symbol_re}$/
599 # We can't do the kind of collecting coolness that option_check()
600 # does, because there are too many things that can't be found in
601 # name repositories like the NAME sections, such as symbol names
602 # with a variable part (typically marked up as B<foo_I<TYPE>_bar>
605 # This is from http://man7.org/linux/man-pages/man7/man-pages.7.html
606 my %preferred_words = (
609 'bitmask' => 'bit mask',
610 'builtin' => 'built-in',
611 #'epoch' => 'Epoch', # handled specially, below
612 'fall-back' => 'fallback',
613 'file name' => 'filename',
614 'file system' => 'filesystem',
615 'host name' => 'hostname',
617 'lower case' => 'lowercase',
618 'lower-case' => 'lowercase',
619 'manpage' => 'man page',
620 'non-blocking' => 'nonblocking',
621 'non-default' => 'nondefault',
622 'non-empty' => 'nonempty',
623 'non-negative' => 'nonnegative',
624 'non-zero' => 'nonzero',
625 'path name' => 'pathname',
626 'pre-allocated' => 'preallocated',
627 'pseudo-terminal' => 'pseudoterminal',
628 'real time' => 'real-time',
629 'realtime' => 'real-time',
630 'reserved port' => 'privileged port',
631 'runtime' => 'run time',
632 'saved group ID'=> 'saved set-group-ID',
633 'saved set-GID' => 'saved set-group-ID',
634 'saved set-UID' => 'saved set-user-ID',
635 'saved user ID' => 'saved set-user-ID',
636 'set-GID' => 'set-group-ID',
637 'set-UID' => 'set-user-ID',
638 'setgid' => 'set-group-ID',
639 'setuid' => 'set-user-ID',
640 'sub-system' => 'subsystem',
641 'super block' => 'superblock',
642 'super-block' => 'superblock',
643 'super user' => 'superuser',
644 'super-user' => 'superuser',
645 'system port' => 'privileged port',
646 'time stamp' => 'timestamp',
647 'time zone' => 'timezone',
648 'upper case' => 'uppercase',
649 'upper-case' => 'uppercase',
650 'useable' => 'usable',
651 'user name' => 'username',
652 'userspace' => 'user space',
656 # Search manpage for words that have a different preferred use.
659 my $contents = shift;
661 foreach my $k ( keys %preferred_words ) {
663 next if $k eq 'file system'
664 and $contents =~ /Microsoft Encrypted File System/;
665 err($id, "Found '$k' should use '$preferred_words{$k}'")
666 if $contents =~ /\b\Q$k\E\b/i;
668 err($id, "Found 'epoch' should use 'Epoch'")
669 if $contents =~ /\bepoch\b/;
670 if ( $id =~ m@man1/@ ) {
671 err($id, "found 'tool' in NAME, should use 'command'")
672 if $contents =~ /=head1 NAME.*\btool\b.*=head1 SYNOPSIS/s;
673 err($id, "found 'utility' in NAME, should use 'command'")
674 if $contents =~ /NAME.*\butility\b.*=head1 SYNOPSIS/s;
679 # Perform all sorts of nit/error checks on a manpage
682 my $filename = $podinfo{filename};
683 my $dirname = basename(dirname($filename));
684 my $contents = $podinfo{contents};
686 my $id = "${filename}:1:";
687 check_head_style($id, $contents);
689 # Check ordering of some sections in man3
690 if ( $filename =~ m|man3/| ) {
691 check_section_location($id, $contents, "RETURN VALUES", "EXAMPLES");
692 check_section_location($id, $contents, "SEE ALSO", "HISTORY");
693 check_section_location($id, $contents, "EXAMPLES", "SEE ALSO");
696 # Make sure every link has a section.
697 while ( $contents =~ /$markup_re/msg ) {
699 next unless $target =~ /^L<(.*)>$/; # Skip if not L<...>
700 $target = $1; # Peal away L< and >
701 $target =~ s/\/[^\/]*$//; # Peal away possible anchor
702 $target =~ s/.*\|//g; # Peal away possible link text
703 next if $target eq ''; # Skip if links within page, or
704 next if $target =~ /::/; # links to a Perl module, or
705 next if $target =~ /^https?:/; # is a URL link, or
706 next if $target =~ /\([1357]\)$/; # it has a section
707 err($id, "Section missing in $target")
709 # Check for proper links to commands.
710 while ( $contents =~ /L<([^>]*)\(1\)(?:\/.*)?>/g ) {
712 next if $target =~ /openssl-?/;
713 next if ( grep { basename($_) eq "$target.pod" }
714 files(TAGS => [ 'manual', 'man1' ]) );
715 # TODO: Filter out "foreign manual" links.
716 next if $target =~ /ps|apropos|sha1sum|procmail|perl/;
717 err($id, "Bad command link L<$target(1)>");
719 # Check for proper in-man-3 API links.
720 while ( $contents =~ /L<([^>]*)\(3\)(?:\/.*)?>/g ) {
722 err($id, "Bad L<$target>")
723 unless $target =~ /^[_[:alpha:]][_[:alnum:]]*$/
726 unless ( $contents =~ /^=for openssl generic/ms ) {
727 if ( $filename =~ m|man3/| ) {
728 name_synopsis($id, $filename, $contents);
729 functionname_check($id, $filename, $contents);
730 } elsif ( $filename =~ m|man1/| ) {
731 option_check($id, $filename, $contents)
735 wording($id, $contents);
737 err($id, "Doesn't start with =pod")
738 if $contents !~ /^=pod/;
739 err($id, "Doesn't end with =cut")
740 if $contents !~ /=cut\n$/;
741 err($id, "More than one cut line.")
742 if $contents =~ /=cut.*=cut/ms;
743 err($id, "EXAMPLE not EXAMPLES section.")
744 if $contents =~ /=head1 EXAMPLE[^S]/;
745 err($id, "WARNING not WARNINGS section.")
746 if $contents =~ /=head1 WARNING[^S]/;
747 err($id, "Missing copyright")
748 if $contents !~ /Copyright .* The OpenSSL Project Authors/;
749 err($id, "Copyright not last")
750 if $contents =~ /head1 COPYRIGHT.*=head/ms;
751 err($id, "head2 in All uppercase")
752 if $contents =~ /head2\s+[A-Z ]+\n/;
753 err($id, "Extra space after head")
754 if $contents =~ /=head\d\s\s+/;
755 err($id, "Period in NAME section")
756 if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms;
757 err($id, "Duplicate $1 in L<>")
758 if $contents =~ /L<([^>]*)\|([^>]*)>/ && $1 eq $2;
759 err($id, "Bad =over $1")
760 if $contents =~ /=over([^ ][^24])/;
761 err($id, "Possible version style issue")
762 if $contents =~ /OpenSSL version [019]/;
764 if ( $contents !~ /=for openssl multiple includes/ ) {
765 # Look for multiple consecutive openssl #include lines
766 # (non-consecutive lines are okay; see man3/MD5.pod).
767 if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) {
769 foreach my $line ( split /\n+/, $1 ) {
770 if ( $line =~ m@include <openssl/@ ) {
771 err($id, "Has multiple includes")
780 open my $OUT, '>', $temp
781 or die "Can't open $temp, $!";
782 err($id, "POD errors")
783 if podchecker($filename, $OUT) != 0;
785 open $OUT, '<', $temp
786 or die "Can't read $temp, $!";
788 next if /\(section\) in.*deprecated/;
792 unlink $temp || warn "Can't remove $temp, $!";
794 # Find what section this page is in; assume 3.
796 $section = $1 if $dirname =~ /man([1-9])/;
798 foreach ( (@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}}) ) {
799 err($id, "Missing $_ head1 section")
800 if $contents !~ /^=head1\s+${_}\s*$/m;
804 # Information database ###############################################
806 # Map of links in each POD file; filename => [ "foo(1)", "bar(3)", ... ]
808 # Map of names in each POD file or from "missing" files; possible values are:
809 # If found in a POD files, "name(s)" => filename
810 # If found in a "missing" file or external, "name(s)" => ''
813 # State of man-page names.
814 # %state is affected by loading util/*.num and util/*.syms
815 # Values may be one of:
816 # 'crypto' : belongs in libcrypto (loaded from libcrypto.num)
817 # 'ssl' : belongs in libssl (loaded from libssl.num)
818 # 'other' : belongs in libcrypto or libssl (loaded from other.syms)
819 # 'internal' : Internal
820 # 'public' : Public (generic name or external documentation)
821 # Any of these values except 'public' may be prefixed with 'missing_'
822 # to indicate that they are known to be missing.
824 # %missing is affected by loading util/missing*.txt. Values may be one of:
825 # 'crypto' : belongs in libcrypto (loaded from libcrypto.num)
826 # 'ssl' : belongs in libssl (loaded from libssl.num)
827 # 'other' : belongs in libcrypto or libssl (loaded from other.syms)
828 # 'internal' : Internal
831 # Parse libcrypto.num, etc., and return sorted list of what's there.
837 open my $IN, '<', catfile($config{sourcedir}, $file)
838 or die "Can't open $file, $!, stopped";
842 next if /\bNOEXIST\b/;
843 my @fields = split();
844 die "Malformed line $. in $file: $_"
845 if scalar @fields != 2 && scalar @fields != 4;
846 $state{$fields[0].'(3)'} = $type // 'internal';
851 # Load file of symbol names that we know aren't documented.
854 my $missingfile = shift;
857 open FH, catfile($config{sourcedir}, $missingfile)
858 or die "Can't open $missingfile";
862 $missing{$_} = $type // 'internal';
867 # Check that we have consistent public / internal documentation and declaration
869 # Collect all known names, no matter where they come from
870 my %names = map { $_ => 1 } (keys %name_map, keys %state, keys %missing);
872 # Check section 3, i.e. functions and macros
873 foreach ( grep { $_ =~ /\(3\)$/ } sort keys %names ) {
874 next if ( $name_map{$_} // '') eq '' || $_ =~ /$ignored/;
876 # If a man-page isn't recorded public or if it's recorded missing
877 # and internal, it's declared to be internal.
878 my $declared_internal =
879 ($state{$_} // 'internal') eq 'internal'
880 || ($missing{$_} // '') eq 'internal';
881 # If a man-page isn't recorded internal or if it's recorded missing
882 # and not internal, it's declared to be public
883 my $declared_public =
884 ($state{$_} // 'internal') ne 'internal'
885 || ($missing{$_} // 'internal') ne 'internal';
887 err("$_ is supposedly public but is documented as internal")
888 if ( $declared_public && $name_map{$_} =~ /\/internal\// );
889 err("$_ is supposedly internal (maybe missing from other.syms) but is documented as public")
890 if ( $declared_internal && $name_map{$_} !~ /\/internal\// );
894 # Check for undocumented macros; ignore those in the "missing" file
895 # and do simple check for #define in our header files.
900 foreach my $f ( files(TAGS => 'public_header') ) {
901 # Skip some internals we don't want to document yet.
902 my $b = basename($f);
903 next if $b eq 'asn1.h';
904 next if $b eq 'asn1t.h';
905 next if $b eq 'err.h';
907 or die "Can't open $f, $!";
909 next unless /^#\s*define\s*(\S+)\(/;
910 my $macro = "$1(3)"; # We know they're all in section 3
911 next if defined $name_map{$macro}
912 || defined $missing{$macro}
913 || defined $seen{$macro}
914 || $macro =~ /$ignored/;
916 err("$f:", "macro $macro undocumented")
923 err("# $count macros undocumented (count is approximate)")
927 # Find out what is undocumented (filtering out the known missing ones)
933 foreach my $func ( grep { $state{$_} eq $type } sort keys %state ) {
934 next if defined $name_map{$func}
935 || defined $missing{$func};
937 err("$type:", "function $func undocumented")
941 err("# $count lib$type names are not documented")
945 # Collect all the names in a manpage.
948 my $filename = $podinfo{filename};
949 $filename =~ m|man(\d)/|;
951 my $simplename = basename($filename, ".pod");
952 my $id = "${filename}:1:";
953 my $is_generic = $podinfo{contents} =~ /^=for openssl generic/ms;
955 unless ( grep { $simplename eq $_ } @{$podinfo{names}} ) {
956 err($id, "$simplename not in NAME section");
957 push @{$podinfo{names}}, $simplename;
959 foreach my $name ( @{$podinfo{names}} ) {
961 err($id, "'$name' contains whitespace")
963 my $name_sec = "$name($section)";
964 if ( !defined $name_map{$name_sec} ) {
965 $name_map{$name_sec} = $filename;
966 $state{$name_sec} //=
967 ( $filename =~ /\/internal\// ? 'internal' : 'public' )
969 } elsif ( $filename eq $name_map{$name_sec} ) {
970 err($id, "$name_sec duplicated in NAME section of",
971 $name_map{$name_sec});
972 } elsif ( $name_map{$name_sec} ne '' ) {
973 err($id, "$name_sec also in NAME section of",
974 $name_map{$name_sec});
978 if ( $podinfo{contents} =~ /=for openssl foreign manual (.*)\n/ ) {
979 foreach my $f ( split / /, $1 ) {
980 $name_map{$f} = ''; # It still exists!
981 $state{$f} = 'public'; # We assume!
986 $podinfo{contents} =~ /L<
987 # if the link is of the form L<something|name(s)>,
988 # then remove 'something'. Note that 'something'
989 # may contain POD codes as well...
990 (?:(?:[^\|]|<[^>]*>)*\|)?
991 # we're only interested in references that have
992 # a one digit section number
995 $link_map{$filename} = [ @links ];
998 # Look for L<> ("link") references that point to files that do not exist.
1000 foreach my $filename ( sort keys %link_map ) {
1001 foreach my $link ( @{$link_map{$filename}} ) {
1002 err("${filename}:1:", "reference to non-existing $link")
1003 unless defined $name_map{$link} || defined $missing{$link};
1004 err("${filename}:1:", "reference of internal $link in public documentation $filename")
1005 if ( ( ($state{$link} // '') eq 'internal'
1006 || ($missing{$link} // '') eq 'internal' )
1007 && $filename !~ /\/internal\// );
1012 # Cipher/digests to skip if they show up as "not implemented"
1013 # because they are, via the "-*" construct.
1031 # Check the flags of a command and see if everything is in the manpage
1039 # Get the list of options in the command.
1040 open CFH, "$openssl list --options $cmd|"
1041 or die "Can list options for $cmd, $!";
1049 # Get the list of flags from the synopsis
1051 or die "Can't open $doc, $!";
1054 last if /DESCRIPTION/;
1055 if ( /=for openssl ifdef (.*)/ ) {
1056 foreach my $f ( split / /, $1 ) {
1057 $localskips{$f} = 1;
1062 if ( /\[B<-([^ >]+)/ ) {
1064 } elsif ( /^B<-([^ >]+)/ ) {
1069 $opt = $1 if $opt =~ /I<(.*)/;
1074 # See what's in the command not the manpage.
1075 my @undocced = sort grep { !defined $docopts{$_} } keys %cmdopts;
1076 foreach ( @undocced ) {
1077 next if /-/; # Skip the -- end-of-flags marker
1078 err("$doc: undocumented option -$_");
1081 # See what's in the command not the manpage.
1082 my @unimpl = sort grep { !defined $cmdopts{$_} } keys %docopts;
1083 foreach ( @unimpl ) {
1084 next if defined $skips{$_} || defined $localskips{$_};
1085 err("$doc: $cmd does not implement -$_");
1091 ## Do the work requested by the various getopt flags.
1092 ## The flags are parsed in alphabetical order, just because we have
1093 ## to have *some way* of listing them.
1099 # Get list of commands.
1100 open FH, "$openssl list -1 -commands|"
1101 or die "Can't list commands, $!";
1108 # See if each has a manpage.
1109 foreach my $cmd ( @commands ) {
1110 next if $cmd eq 'help' || $cmd eq 'exit';
1111 my @doc = ( grep { basename($_) eq "openssl-$cmd.pod"
1112 # For "tsget" and "CA.pl" pod pages
1113 || basename($_) eq "$cmd.pod" }
1114 files(TAGS => [ 'manual', 'man1' ]) );
1115 my $num = scalar @doc;
1117 err("$num manuals for 'openssl $cmd': ".join(", ", @doc));
1118 } elsif ($num < 1) {
1119 err("no manual for 'openssl $cmd'");
1121 checkflags($cmd, @doc);
1125 # See what help is missing.
1126 open FH, "$openssl list --missing-help |"
1127 or die "Can't list missing help, $!";
1130 my ($cmd, $flag) = split;
1131 err("$cmd has no help for -$flag");
1139 loadnum('util/libcrypto.num', 'crypto');
1140 loadnum('util/libssl.num', 'ssl');
1141 loadnum('util/other.syms', 'other');
1142 loadnum('util/other-internal.syms');
1144 loadmissing('util/missingmacro111.txt', 'crypto');
1145 loadmissing('util/missingcrypto111.txt', 'crypto');
1146 loadmissing('util/missingssl111.txt', 'ssl');
1147 } elsif ( !$opt_u ) {
1148 loadmissing('util/missingmacro.txt', 'crypto');
1149 loadmissing('util/missingcrypto.txt', 'crypto');
1150 loadmissing('util/missingssl.txt', 'ssl');
1151 loadmissing('util/missingcrypto-internal.txt');
1152 loadmissing('util/missingssl-internal.txt');
1155 if ( $opt_n || $opt_l || $opt_u || $opt_v ) {
1156 my @files_to_read = ( $opt_n && @ARGV ) ? @ARGV : files(TAGS => 'manual');
1158 foreach (@files_to_read) {
1159 my %podinfo = extract_pod_info($_, { debug => $debug });
1161 collectnames(%podinfo)
1162 if ( $opt_l || $opt_u || $opt_v );
1174 # If not given args, check that all man1 commands are named properly.
1175 if ( scalar @ARGV == 0 ) {
1176 foreach ( files(TAGS => [ 'public_manual', 'man1' ]) ) {
1177 next if /openssl\.pod/
1178 || /CA\.pl/ || /tsget\.pod/; # these commands are special cases
1179 err("$_ doesn't start with openssl-") unless /openssl-/;
1186 if ( $opt_u || $opt_v) {