2 # Copyright 2002-2020 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 internal macros that we currently don't document
95 my $ignored = qr/(?| ^i2d_
102 | ^SKM_DEFINE_STACK_OF_INTERNAL
104 | ^DEFINE_LHASH_OF_INTERNAL
107 # Collect all POD files, both internal and public, and regardless of location
108 # We collect them in a hash table with each file being a key, so we can attach
109 # tags to them. For example, internal docs will have the word "internal"
112 # We collect files names on the fly, on known tag basis
113 my %collected_tags = ();
114 # We cache results based on tags
115 my %collected_results = ();
121 # files(TAGS => 'manual');
122 # files(TAGS => [ 'manual', 'man1' ]);
124 # This function returns an array of files corresponding to a set of tags
125 # given with the options "TAGS". The value of this option can be a single
126 # word, or an array of several words, which work as inclusive or exclusive
127 # selectors. Inclusive selectors are used to add one more set of files to
128 # the returned array, while exclusive selectors limit the set of files added
129 # to the array. The recognised tag values are:
131 # 'public_manual' - inclusive selector, adds public manuals to the
132 # returned array of files.
133 # 'internal_manual' - inclusive selector, adds internal manuals to the
134 # returned array of files.
135 # 'manual' - inclusive selector, adds any manual to the returned
136 # array of files. This is really a shorthand for
137 # 'public_manual' and 'internal_manual' combined.
138 # 'public_header' - inclusive selector, adds public headers to the
139 # returned array of files.
140 # 'header' - inclusive selector, adds any header file to the
141 # returned array of files. Since we currently only
142 # care about public headers, this is exactly
143 # equivalent to 'public_header', but is present for
146 # 'man1', 'man3', 'man5', 'man7'
147 # - exclusive selectors, only applicable together with
148 # any of the manual selectors. If any of these are
149 # present, only the manuals from the given sections
150 # will be include. If none of these are present,
151 # the manuals from all sections will be returned.
153 # All returned manual files come from configdata.pm.
154 # All returned header files come from looking inside
155 # "$config{sourcedir}/include/openssl"
158 my %opts = ( @_ ); # Make a copy of the arguments
160 $opts{TAGS} = [ $opts{TAGS} ] if ref($opts{TAGS}) eq '';
162 croak "No tags given, or not an array"
163 unless exists $opts{TAGS} && ref($opts{TAGS}) eq 'ARRAY';
165 my %tags = map { $_ => 1 } @{$opts{TAGS}};
166 $tags{public_manual} = 1
167 if $tags{manual} && ($tags{public} // !$tags{internal});
168 $tags{internal_manual} = 1
169 if $tags{manual} && ($tags{internal} // !$tags{public});
170 $tags{public_header} = 1
171 if $tags{header} && ($tags{public} // !$tags{internal});
172 delete $tags{manual};
173 delete $tags{header};
174 delete $tags{public};
175 delete $tags{internal};
177 my $tags_as_key = join(':', sort keys %tags);
179 cluck "DEBUG[files]: This is how we got here!" if $debug;
180 print STDERR "DEBUG[files]: tags: $tags_as_key\n" if $debug;
182 my %tags_to_collect = ( map { $_ => 1 }
183 grep { !exists $collected_tags{$_} }
186 if ($tags_to_collect{public_manual}) {
187 print STDERR "DEBUG[files]: collecting public manuals\n"
190 # The structure in configdata.pm is that $unified_info{mandocs}
191 # contains lists of man files, and in turn, $unified_info{depends}
192 # contains hash tables showing which POD file each of those man
193 # files depend on. We use that information to find the POD files,
194 # and to attach the man section they belong to as tags
195 foreach my $mansect ( @sections ) {
196 foreach ( map { @{$unified_info{depends}->{$_}} }
197 @{$unified_info{mandocs}->{$mansect}} ) {
198 $files{$_} = { $mansect => 1, public_manual => 1 };
201 $collected_tags{public_manual} = 1;
204 if ($tags_to_collect{internal_manual}) {
205 print STDERR "DEBUG[files]: collecting internal manuals\n"
208 # We don't have the internal docs in configdata.pm. However, they
209 # are all in the source tree, so they're easy to find.
210 foreach my $mansect ( @sections ) {
211 foreach ( glob(catfile($config{sourcedir},
212 'doc', 'internal', $mansect, '*.pod')) ) {
213 $files{$_} = { $mansect => 1, internal_manual => 1 };
216 $collected_tags{internal_manual} = 1;
219 if ($tags_to_collect{public_header}) {
220 print STDERR "DEBUG[files]: collecting public headers\n"
223 foreach ( glob(catfile($config{sourcedir},
224 'include', 'openssl', '*.h')) ) {
225 $files{$_} = { public_header => 1 };
229 my @result = @{$collected_results{$tags_as_key} // []};
232 # Produce a result based on caller tags
233 foreach my $type ( ( 'public_manual', 'internal_manual' ) ) {
234 next unless $tags{$type};
236 # If caller asked for specific sections, we care about sections.
237 # Otherwise, we give back all of them.
238 my @selected_sections =
239 grep { $tags{$_} } @sections;
240 @selected_sections = @sections unless @selected_sections;
242 foreach my $section ( ( @selected_sections ) ) {
244 ( sort { basename($a) cmp basename($b) }
245 grep { $files{$_}->{$type} && $files{$_}->{$section} }
249 if ($tags{public_header}) {
251 ( sort { basename($a) cmp basename($b) }
252 grep { $files{$_}->{public_header} }
257 print STDERR "DEBUG[files]: result:\n";
258 print STDERR "DEBUG[files]: $_\n" foreach @result;
260 $collected_results{$tags_as_key} = [ @result ];
266 # Print error message, set $status.
268 print join(" ", @_), "\n";
272 # Cross-check functions in the NAME and SYNOPSIS section.
275 my $filename = shift;
276 my $contents = shift;
278 # Get NAME section and all words in it.
279 return unless $contents =~ /=head1 NAME(.*)=head1 SYNOPSIS/ms;
282 err($id, "Trailing comma before - in NAME")
285 err($id, "POD markup among the names in NAME")
288 err($id, "Missing comma in NAME")
291 my $dirname = dirname($filename);
292 my $section = basename($dirname);
293 my $simplename = basename($filename, ".pod");
294 my $foundfilename = 0;
295 my %foundfilenames = ();
297 foreach my $n ( split ',', $tmp ) {
300 err($id, "The name '$n' contains white-space")
303 $foundfilename++ if $n eq $simplename;
304 $foundfilenames{$n} = 1
305 if ( ( grep { basename($_) eq "$n.pod" }
306 files(TAGS => [ 'manual', $section ]) )
307 && $n ne $simplename );
309 err($id, "The following exist as other .pod files:",
310 sort keys %foundfilenames)
312 err($id, "$simplename (filename) missing from NAME section")
313 unless $foundfilename;
315 # Find all functions in SYNOPSIS
316 return unless $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms;
318 my $ignore_until = undef; # If defined, this is a regexp
319 # Remove all non-code lines
320 $syn =~ s/^(?:\s*?|\S.*?)$//msg;
321 # Remove all comments
322 $syn =~ s/\/\*.*?\*\///msg;
324 # "env" lines end at a newline.
325 # Preprocessor lines start with a # and end at a newline.
326 # Other lines end with a semicolon, and may cover more than
328 if ( $syn !~ /^ \s*(env .*?|#.*?|.*?;)\s*$/ms ) {
329 err($id, "Can't parse rest of synopsis:\n$syn\n(declarations not ending with a semicolon (;)?)");
335 print STDERR "DEBUG[name_synopsis] \$line = '$line'\n" if $debug;
337 # Special code to skip over documented structures
338 if ( defined $ignore_until) {
339 next if $line !~ /$ignore_until/;
340 $ignore_until = undef;
343 if ( $line =~ /^\s*(?:typedef\s+)?struct(?:\s+\S+)\s*\{/ ) {
344 $ignore_until = qr/\}.*?;/;
349 my $is_prototype = 1;
350 $line =~ s/STACK_OF\([^)]+\)/int/g;
351 $line =~ s/SPARSE_ARRAY_OF\([^)]+\)/int/g;
352 $line =~ s/__declspec\([^)]+\)//;
354 ## We don't prohibit that space, to allow typedefs looking like
357 ## typedef int (fantastically_long_name_breaks_80char_limit)
358 ## (fantastically_long_name_breaks_80char_limit *something);
360 #if ( $line =~ /typedef.*\(\*?\S+\)\s+\(/ ) {
361 # # a callback function with whitespace before the argument list:
362 # # typedef ... (*NAME) (...
363 # # typedef ... (NAME) (...
364 # err($id, "Function typedef has space before arg list: $line");
367 if ( $line =~ /env (\S*)=/ ) {
368 # environment variable env NAME=...
370 } elsif ( $line =~ /typedef.*\(\*?(\S+)\)\s*\(/ ) {
371 # a callback function pointer: typedef ... (*NAME)(...
372 # a callback function signature: typedef ... (NAME)(...
374 } elsif ( $line =~ /typedef.* (\S+)\s*\(/ ) {
375 # a callback function signature: typedef ... NAME(...
377 } elsif ( $line =~ /typedef.* (\S+);/ ) {
378 # a simple typedef: typedef ... NAME;
381 } elsif ( $line =~ /enum (\S*) \{/ ) {
382 # an enumeration: enum ... {
384 } elsif ( $line =~ /#\s*(?:define|undef) ([A-Za-z0-9_]+)/ ) {
387 } elsif ( $line =~ /^[^\(]*?\(\*([A-Za-z0-9_]+)\s*\(/ ) {
388 # a function returning a function pointer: TYPE (*NAME(args))(args)
390 } elsif ( $line =~ /^[^\(]*?([A-Za-z0-9_]+)\s*\(/ ) {
391 # a simple function declaration
398 print STDERR "DEBUG[name_synopsis] \$sym = '$sym'\n" if $debug;
400 err($id, "$sym missing from NAME section")
401 unless defined $names{$sym};
404 # Do some sanity checks on the prototype.
405 err($id, "Prototype missing spaces around commas: $line")
406 if $is_prototype && $line =~ /[a-z0-9],[^\s]/;
409 foreach my $n ( keys %names ) {
410 next if $names{$n} == 2;
411 err($id, "$n missing from SYNOPSIS")
415 # Check if SECTION ($3) is located before BEFORE ($4)
416 sub check_section_location {
418 my $contents = shift;
422 return unless $contents =~ /=head1 $section/
423 and $contents =~ /=head1 $before/;
424 err($id, "$section should appear before $before section")
425 if $contents =~ /=head1 $before.*=head1 $section/ms;
428 # Check if a =head1 is duplicated, or a =headX is duplicated within a
429 # =head1. Treats =head2 =head3 as equivalent -- it doesn't reset the head3
430 # sets if it finds a =head2 -- but that is good enough for now. Also check
431 # for proper capitalization, trailing periods, etc.
432 sub check_head_style {
434 my $contents = shift;
438 foreach my $line ( split /\n+/, $contents ) {
439 next unless $line =~ /^=head/;
440 if ( $line =~ /head1/ ) {
441 err($id, "Duplicate section $line")
442 if defined $head1{$line};
446 err($id, "Duplicate subsection $line")
447 if defined $subheads{$line};
448 $subheads{$line} = 1;
450 err($id, "Period in =head")
451 if $line =~ /\.[^\w]/ or $line =~ /\.$/;
452 err($id, "not all uppercase in =head1")
453 if $line =~ /head1.*[a-z]/;
454 err($id, "All uppercase in subhead")
455 if $line =~ /head[234][ A-Z0-9]+$/;
459 # Because we have options and symbols with extra markup, we need
460 # to take that into account, so we need a regexp that extracts
461 # markup chunks, including recursive markup.
462 # please read up on /(?R)/ in perlre(1)
463 # (note: order is important, (?R) needs to come before .)
464 # (note: non-greedy is important, or something like 'B<foo> and B<bar>'
465 # will be captured as one item)
468 [BIL]< # The start of what we recurse on
469 (?:(?-1)|.)*? # recurse the whole regexp (referring to
470 # the last opened capture group, i.e. the
471 # start of this regexp), or pick next
472 # character. Do NOT be greedy!
473 > # The end of what we recurse on
474 )/x; # (the x allows this sort of split up regexp)
476 # Options must start with a dash, followed by a letter, possibly
477 # followed by letters, digits, dashes and underscores, and the last
478 # character must be a letter or a digit.
479 # We do also accept the single -? or -n, where n is a digit
482 \? # Single question mark
488 [[:alpha:]](?:[-_[:alnum:]]*?[[:alnum:]])?
491 # Helper function to check if a given $thing is properly marked up
492 # option. It returns one of these values:
493 # undef if it's not an option
494 # "" if it's a malformed option
495 # $unwrapped the option with the outermost B<> wrapping removed.
496 sub normalise_option {
498 my $filename = shift;
501 my $unwrapped = $thing;
502 my $unmarked = $thing;
504 # $unwrapped is the option with the outer B<> markup removed
505 $unwrapped =~ s/^B<//;
506 $unwrapped =~ s/>$//;
507 # $unmarked is the option with *all* markup removed
508 $unmarked =~ s/[BIL]<|>//msg;
511 # If we found an option, check it, collect it
512 if ( $unwrapped =~ /^\s*-/ ) {
513 return $unwrapped # return option with outer B<> removed
514 if $unmarked =~ /^-${option_re}$/;
515 return ""; # Malformed option
517 return undef; # Something else
520 # Checks of command option (man1) formatting. The man1 checks are
521 # restricted to the SYNOPSIS and OPTIONS sections, the rest is too
522 # free form, we simply cannot be too strict there.
526 my $filename = shift;
527 my $contents = shift;
529 my $synopsis = ($contents =~ /=head1\s+SYNOPSIS(.*?)=head1/s, $1);
531 # Some pages have more than one OPTIONS section, let's make sure
534 while ( $contents =~ /=head1\s+[A-Z ]*?OPTIONS$(.*?)(?==head1)/msg ) {
538 # Look for options with no or incorrect markup
540 /(?<![-<[:alnum:]])-(?:$markup_re|.)*(?![->[:alnum:]])/msg ) {
541 err($id, "Malformed option [1] in SYNOPSIS: $&");
544 while ( $synopsis =~ /$markup_re/msg ) {
546 print STDERR "$id:DEBUG[option_check] SYNOPSIS: found $found\n"
548 my $option_uw = normalise_option($id, $filename, $found);
549 err($id, "Malformed option [2] in SYNOPSIS: $found")
550 if defined $option_uw && $option_uw eq '';
553 # In OPTIONS, we look for =item paragraphs.
554 # (?=^\s*$) detects an empty line.
555 while ( $options =~ /=item\s+(.*?)(?=^\s*$)/msg ) {
558 while ( $item =~ /(\[\s*)?($markup_re)/msg ) {
560 print STDERR "$id:DEBUG[option_check] OPTIONS: found $&\n"
562 err($id, "Unexpected bracket in OPTIONS =item: $item")
563 if ($1 // '') ne '' && $found =~ /^B<\s*-/;
565 my $option_uw = normalise_option($id, $filename, $found);
566 err($id, "Malformed option in OPTIONS: $found")
567 if defined $option_uw && $option_uw eq '';
573 my $symbol_re = qr/[[:alpha:]_][_[:alnum:]]*?/;
575 # Checks of function name (man3) formatting. The man3 checks are
576 # easier than the man1 checks, we only check the names followed by (),
577 # and only the names that have POD markup.
578 sub functionname_check {
580 my $filename = shift;
581 my $contents = shift;
583 while ( $contents =~ /($markup_re)\(\)/msg ) {
584 print STDERR "$id:DEBUG[functionname_check] SYNOPSIS: found $&\n"
588 my $unmarked = $symbol;
589 $unmarked =~ s/[BIL]<|>//msg;
591 err($id, "Malformed symbol: $symbol")
592 unless $symbol =~ /^B<.*?>$/ && $unmarked =~ /^${symbol_re}$/
595 # We can't do the kind of collecting coolness that option_check()
596 # does, because there are too many things that can't be found in
597 # name repositories like the NAME sections, such as symbol names
598 # with a variable part (typically marked up as B<foo_I<TYPE>_bar>
601 # This is from http://man7.org/linux/man-pages/man7/man-pages.7.html
602 my %preferred_words = (
605 'bitmask' => 'bit mask',
606 'builtin' => 'built-in',
607 #'epoch' => 'Epoch', # handled specially, below
608 'file name' => 'filename',
609 'file system' => 'filesystem',
610 'host name' => 'hostname',
612 'lower case' => 'lowercase',
613 'lower-case' => 'lowercase',
614 'manpage' => 'man page',
615 'non-blocking' => 'nonblocking',
616 'non-default' => 'nondefault',
617 'non-empty' => 'nonempty',
618 'non-negative' => 'nonnegative',
619 'non-zero' => 'nonzero',
620 'path name' => 'pathname',
621 'pre-allocated' => 'preallocated',
622 'pseudo-terminal' => 'pseudoterminal',
623 'real time' => 'real-time',
624 'realtime' => 'real-time',
625 'reserved port' => 'privileged port',
626 'runtime' => 'run time',
627 'saved group ID'=> 'saved set-group-ID',
628 'saved set-GID' => 'saved set-group-ID',
629 'saved set-UID' => 'saved set-user-ID',
630 'saved user ID' => 'saved set-user-ID',
631 'set-GID' => 'set-group-ID',
632 'set-UID' => 'set-user-ID',
633 'setgid' => 'set-group-ID',
634 'setuid' => 'set-user-ID',
635 'sub-system' => 'subsystem',
636 'super block' => 'superblock',
637 'super-block' => 'superblock',
638 'super user' => 'superuser',
639 'super-user' => 'superuser',
640 'system port' => 'privileged port',
641 'time stamp' => 'timestamp',
642 'time zone' => 'timezone',
643 'upper case' => 'uppercase',
644 'upper-case' => 'uppercase',
645 'useable' => 'usable',
646 'user name' => 'username',
647 'userspace' => 'user space',
651 # Search manpage for words that have a different preferred use.
654 my $contents = shift;
656 foreach my $k ( keys %preferred_words ) {
658 next if $k eq 'file system'
659 and $contents =~ /Microsoft Encrypted File System/;
660 err($id, "Found '$k' should use '$preferred_words{$k}'")
661 if $contents =~ /\b\Q$k\E\b/i;
663 err($id, "Found 'epoch' should use 'Epoch'")
664 if $contents =~ /\bepoch\b/;
665 if ( $id =~ m@man1/@ ) {
666 err($id, "found 'tool' in NAME, should use 'command'")
667 if $contents =~ /=head1 NAME.*\btool\b.*=head1 SYNOPSIS/s;
668 err($id, "found 'utility' in NAME, should use 'command'")
669 if $contents =~ /NAME.*\butility\b.*=head1 SYNOPSIS/s;
674 # Perform all sorts of nit/error checks on a manpage
677 my $filename = $podinfo{filename};
678 my $dirname = basename(dirname($filename));
679 my $contents = $podinfo{contents};
681 my $id = "${filename}:1:";
682 check_head_style($id, $contents);
684 # Check ordering of some sections in man3
685 if ( $filename =~ m|man3/| ) {
686 check_section_location($id, $contents, "RETURN VALUES", "EXAMPLES");
687 check_section_location($id, $contents, "SEE ALSO", "HISTORY");
688 check_section_location($id, $contents, "EXAMPLES", "SEE ALSO");
691 # Make sure every link has a section.
692 while ( $contents =~ /$markup_re/msg ) {
694 next unless $target =~ /^L<(.*)>$/; # Skip if not L<...>
695 $target = $1; # Peal away L< and >
696 $target =~ s/\/[^\/]*$//; # Peal away possible anchor
697 $target =~ s/.*\|//g; # Peal away possible link text
698 next if $target eq ''; # Skip if links within page, or
699 next if $target =~ /::/; # links to a Perl module, or
700 next if $target =~ /^https?:/; # is a URL link, or
701 next if $target =~ /\([1357]\)$/; # it has a section
702 err($id, "Section missing in $target")
704 # Check for proper links to commands.
705 while ( $contents =~ /L<([^>]*)\(1\)(?:\/.*)?>/g ) {
707 next if $target =~ /openssl-?/;
708 next if ( grep { basename($_) eq "$target.pod" }
709 files(TAGS => [ 'manual', 'man1' ]) );
710 # TODO: Filter out "foreign manual" links.
711 next if $target =~ /ps|apropos|sha1sum|procmail|perl/;
712 err($id, "Bad command link L<$target(1)>");
714 # Check for proper in-man-3 API links.
715 while ( $contents =~ /L<([^>]*)\(3\)(?:\/.*)?>/g ) {
717 err($id, "Bad L<$target>")
718 unless $target =~ /^[_[:alpha:]][_[:alnum:]]*$/
721 unless ( $contents =~ /^=for openssl generic/ms ) {
722 if ( $filename =~ m|man3/| ) {
723 name_synopsis($id, $filename, $contents);
724 functionname_check($id, $filename, $contents);
725 } elsif ( $filename =~ m|man1/| ) {
726 option_check($id, $filename, $contents)
730 wording($id, $contents);
732 err($id, "Doesn't start with =pod")
733 if $contents !~ /^=pod/;
734 err($id, "Doesn't end with =cut")
735 if $contents !~ /=cut\n$/;
736 err($id, "More than one cut line.")
737 if $contents =~ /=cut.*=cut/ms;
738 err($id, "EXAMPLE not EXAMPLES section.")
739 if $contents =~ /=head1 EXAMPLE[^S]/;
740 err($id, "WARNING not WARNINGS section.")
741 if $contents =~ /=head1 WARNING[^S]/;
742 err($id, "Missing copyright")
743 if $contents !~ /Copyright .* The OpenSSL Project Authors/;
744 err($id, "Copyright not last")
745 if $contents =~ /head1 COPYRIGHT.*=head/ms;
746 err($id, "head2 in All uppercase")
747 if $contents =~ /head2\s+[A-Z ]+\n/;
748 err($id, "Extra space after head")
749 if $contents =~ /=head\d\s\s+/;
750 err($id, "Period in NAME section")
751 if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms;
752 err($id, "Duplicate $1 in L<>")
753 if $contents =~ /L<([^>]*)\|([^>]*)>/ && $1 eq $2;
754 err($id, "Bad =over $1")
755 if $contents =~ /=over([^ ][^24])/;
756 err($id, "Possible version style issue")
757 if $contents =~ /OpenSSL version [019]/;
759 if ( $contents !~ /=for openssl multiple includes/ ) {
760 # Look for multiple consecutive openssl #include lines
761 # (non-consecutive lines are okay; see man3/MD5.pod).
762 if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) {
764 foreach my $line ( split /\n+/, $1 ) {
765 if ( $line =~ m@include <openssl/@ ) {
766 err($id, "Has multiple includes")
775 open my $OUT, '>', $temp
776 or die "Can't open $temp, $!";
777 podchecker($filename, $OUT);
779 open $OUT, '<', $temp
780 or die "Can't read $temp, $!";
782 next if /\(section\) in.*deprecated/;
786 unlink $temp || warn "Can't remove $temp, $!";
788 # Find what section this page is in; assume 3.
790 $section = $1 if $dirname =~ /man([1-9])/;
792 foreach ( (@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}}) ) {
793 err($id, "Missing $_ head1 section")
794 if $contents !~ /^=head1\s+${_}\s*$/m;
798 # Information database ###############################################
800 # Map of links in each POD file; filename => [ "foo(1)", "bar(3)", ... ]
802 # Map of names in each POD file or from "missing" files; possible values are:
803 # If found in a POD files, "name(s)" => filename
804 # If found in a "missing" file or external, "name(s)" => ''
807 # State of man-page names.
808 # %state is affected by loading util/*.num and util/*.syms
809 # Values may be one of:
810 # 'crypto' : belongs in libcrypto (loaded from libcrypto.num)
811 # 'ssl' : belongs in libssl (loaded from libssl.num)
812 # 'other' : belongs in libcrypto or libssl (loaded from other.syms)
813 # 'internal' : Internal
814 # 'public' : Public (generic name or external documentation)
815 # Any of these values except 'public' may be prefixed with 'missing_'
816 # to indicate that they are known to be missing.
818 # %missing is affected by loading util/missing*.txt. Values may be one of:
819 # 'crypto' : belongs in libcrypto (loaded from libcrypto.num)
820 # 'ssl' : belongs in libssl (loaded from libssl.num)
821 # 'other' : belongs in libcrypto or libssl (loaded from other.syms)
822 # 'internal' : Internal
825 # Parse libcrypto.num, etc., and return sorted list of what's there.
831 open my $IN, '<', catfile($config{sourcedir}, $file)
832 or die "Can't open $file, $!, stopped";
836 next if /\bNOEXIST\b/;
837 my @fields = split();
838 die "Malformed line $. in $file: $_"
839 if scalar @fields != 2 && scalar @fields != 4;
840 $state{$fields[0].'(3)'} = $type // 'internal';
845 # Load file of symbol names that we know aren't documented.
848 my $missingfile = shift;
851 open FH, catfile($config{sourcedir}, $missingfile)
852 or die "Can't open $missingfile";
856 $missing{$_} = $type // 'internal';
861 # Check that we have consistent public / internal documentation and declaration
863 # Collect all known names, no matter where they come from
864 my %names = map { $_ => 1 } (keys %name_map, keys %state, keys %missing);
866 # Check section 3, i.e. functions and macros
867 foreach ( grep { $_ =~ /\(3\)$/ } sort keys %names ) {
868 next if ( $name_map{$_} // '') eq '' || $_ =~ /$ignored/;
870 # If a man-page isn't recorded public or if it's recorded missing
871 # and internal, it's declared to be internal.
872 my $declared_internal =
873 ($state{$_} // 'internal') eq 'internal'
874 || ($missing{$_} // '') eq 'internal';
875 # If a man-page isn't recorded internal or if it's recorded missing
876 # and not internal, it's declared to be public
877 my $declared_public =
878 ($state{$_} // 'internal') ne 'internal'
879 || ($missing{$_} // 'internal') ne 'internal';
881 err("$_ is supposedly public but is documented as internal")
882 if ( $declared_public && $name_map{$_} =~ /\/internal\// );
883 err("$_ is supposedly internal but is documented as public")
884 if ( $declared_internal && $name_map{$_} !~ /\/internal\// );
888 # Check for undocumented macros; ignore those in the "missing" file
889 # and do simple check for #define in our header files.
894 foreach my $f ( files(TAGS => 'public_header') ) {
895 # Skip some internals we don't want to document yet.
896 my $b = basename($f);
897 next if $b eq 'asn1.h';
898 next if $b eq 'asn1t.h';
899 next if $b eq 'err.h';
901 or die "Can't open $f, $!";
903 next unless /^#\s*define\s*(\S+)\(/;
904 my $macro = "$1(3)"; # We know they're all in section 3
905 next if defined $name_map{$macro}
906 || defined $missing{$macro}
907 || defined $seen{$macro}
908 || $macro =~ /$ignored/;
910 err("$f:", "macro $macro undocumented")
917 err("# $count macros undocumented (count is approximate)")
921 # Find out what is undocumented (filtering out the known missing ones)
927 foreach my $func ( grep { $state{$_} eq $type } sort keys %state ) {
928 next if defined $name_map{$func}
929 || defined $missing{$func};
931 err("$type:", "function $func undocumented")
935 err("# $count lib$type names are not documented")
939 # Collect all the names in a manpage.
942 my $filename = $podinfo{filename};
943 $filename =~ m|man(\d)/|;
945 my $simplename = basename($filename, ".pod");
946 my $id = "${filename}:1:";
947 my $is_generic = $podinfo{contents} =~ /^=for openssl generic/ms;
949 unless ( grep { $simplename eq $_ } @{$podinfo{names}} ) {
950 err($id, "$simplename not in NAME section");
951 push @{$podinfo{names}}, $simplename;
953 foreach my $name ( @{$podinfo{names}} ) {
955 err($id, "'$name' contains whitespace")
957 my $name_sec = "$name($section)";
958 if ( !defined $name_map{$name_sec} ) {
959 $name_map{$name_sec} = $filename;
960 $state{$name_sec} //=
961 ( $filename =~ /\/internal\// ? 'internal' : 'public' )
963 } elsif ( $filename eq $name_map{$name_sec} ) {
964 err($id, "$name_sec duplicated in NAME section of",
965 $name_map{$name_sec});
966 } elsif ( $name_map{$name_sec} ne '' ) {
967 err($id, "$name_sec also in NAME section of",
968 $name_map{$name_sec});
972 if ( $podinfo{contents} =~ /=for openssl foreign manual (.*)\n/ ) {
973 foreach my $f ( split / /, $1 ) {
974 $name_map{$f} = ''; # It still exists!
975 $state{$f} = 'public'; # We assume!
980 $podinfo{contents} =~ /L<
981 # if the link is of the form L<something|name(s)>,
982 # then remove 'something'. Note that 'something'
983 # may contain POD codes as well...
984 (?:(?:[^\|]|<[^>]*>)*\|)?
985 # we're only interested in references that have
986 # a one digit section number
989 $link_map{$filename} = [ @links ];
992 # Look for L<> ("link") references that point to files that do not exist.
994 foreach my $filename ( sort keys %link_map ) {
995 foreach my $link ( @{$link_map{$filename}} ) {
996 err("${filename}:1:", "reference to non-existing $link")
997 unless defined $name_map{$link} || defined $missing{$link};
998 err("${filename}:1:", "reference of internal $link in public documentation $filename")
999 if ( ( ($state{$link} // '') eq 'internal'
1000 || ($missing{$link} // '') eq 'internal' )
1001 && $filename !~ /\/internal\// );
1006 # Cipher/digests to skip if they show up as "not implemented"
1007 # because they are, via the "-*" construct.
1025 # Check the flags of a command and see if everything is in the manpage
1033 # Get the list of options in the command.
1034 open CFH, "$openssl list --options $cmd|"
1035 or die "Can list options for $cmd, $!";
1043 # Get the list of flags from the synopsis
1045 or die "Can't open $doc, $!";
1048 last if /DESCRIPTION/;
1049 if ( /=for openssl ifdef (.*)/ ) {
1050 foreach my $f ( split / /, $1 ) {
1051 $localskips{$f} = 1;
1056 if ( /\[B<-([^ >]+)/ ) {
1058 } elsif ( /^B<-([^ >]+)/ ) {
1063 $opt = $1 if $opt =~ /I<(.*)/;
1068 # See what's in the command not the manpage.
1069 my @undocced = sort grep { !defined $docopts{$_} } keys %cmdopts;
1070 foreach ( @undocced ) {
1071 next if /-/; # Skip the -- end-of-flags marker
1072 err("$doc: undocumented option -$_");
1075 # See what's in the command not the manpage.
1076 my @unimpl = sort grep { !defined $cmdopts{$_} } keys %docopts;
1077 foreach ( @unimpl ) {
1078 next if defined $skips{$_} || defined $localskips{$_};
1079 err("$doc: $cmd does not implement -$_");
1085 ## Do the work requested by the various getopt flags.
1086 ## The flags are parsed in alphabetical order, just because we have
1087 ## to have *some way* of listing them.
1093 # Get list of commands.
1094 open FH, "$openssl list -1 -commands|"
1095 or die "Can't list commands, $!";
1102 # See if each has a manpage.
1103 foreach my $cmd ( @commands ) {
1104 next if $cmd eq 'help' || $cmd eq 'exit';
1105 my @doc = ( grep { basename($_) eq "openssl-$cmd.pod"
1106 # For "tsget" and "CA.pl" pod pages
1107 || basename($_) eq "$cmd.pod" }
1108 files(TAGS => [ 'manual', 'man1' ]) );
1109 my $num = scalar @doc;
1111 err("$num manuals for 'openssl $cmd': ".join(", ", @doc));
1112 } elsif ($num < 1) {
1113 err("no manual for 'openssl $cmd'");
1115 checkflags($cmd, @doc);
1119 # See what help is missing.
1120 open FH, "$openssl list --missing-help |"
1121 or die "Can't list missing help, $!";
1124 my ($cmd, $flag) = split;
1125 err("$cmd has no help for -$flag");
1133 loadnum('util/libcrypto.num', 'crypto');
1134 loadnum('util/libssl.num', 'ssl');
1135 loadnum('util/other.syms', 'other');
1136 loadnum('util/other-internal.syms');
1138 loadmissing('util/missingmacro111.txt', 'crypto');
1139 loadmissing('util/missingcrypto111.txt', 'crypto');
1140 loadmissing('util/missingssl111.txt', 'ssl');
1141 } elsif ( !$opt_u ) {
1142 loadmissing('util/missingmacro.txt', 'crypto');
1143 loadmissing('util/missingcrypto.txt', 'crypto');
1144 loadmissing('util/missingssl.txt', 'ssl');
1145 loadmissing('util/missingcrypto-internal.txt');
1146 loadmissing('util/missingssl-internal.txt');
1149 if ( $opt_n || $opt_l || $opt_u || $opt_v ) {
1150 my @files_to_read = ( $opt_n && @ARGV ) ? @ARGV : files(TAGS => 'manual');
1152 foreach (@files_to_read) {
1153 my %podinfo = extract_pod_info($_, { debug => $debug });
1155 collectnames(%podinfo)
1156 if ( $opt_l || $opt_u || $opt_v );
1168 # If not given args, check that all man1 commands are named properly.
1169 if ( scalar @ARGV == 0 ) {
1170 foreach ( files(TAGS => [ 'public_manual', 'man1' ]) ) {
1171 next if /CA.pl/ || /openssl\.pod/ || /tsget\.pod/;
1172 err("$_ doesn't start with openssl-") unless /openssl-/;
1179 if ( $opt_u || $opt_v) {