]>
git.ipfire.org Git - thirdparty/openssl.git/blob - util/find-doc-nits
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/;
606 # Perform all sorts of nit/error checks on a manpage
608 my $filename = shift;
609 my $dirname = basename
(dirname
($filename));
614 open POD
, $filename or die "Couldn't open $filename, $!";
619 my $id = "${filename}:1:";
620 check_head_style
($id, $contents);
622 # Check ordering of some sections in man3
623 if ( $filename =~ m
|man3
/| ) {
624 check_section_location
($id, $contents, "RETURN VALUES", "EXAMPLES");
625 check_section_location
($id, $contents, "SEE ALSO", "HISTORY");
626 check_section_location
($id, $contents, "EXAMPLES", "SEE ALSO");
629 # Make sure every link has a section.
630 while ( $contents =~ /$markup_re/msg ) {
632 next unless $target =~ /^L<(.*)>$/; # Skip if not L<...>
633 $target = $1; # Peal away L< and >
634 $target =~ s/\/[^\/]*$//; # Peal away possible anchor
635 $target =~ s/.*\|//g; # Peal away possible link text
636 next if $target eq ''; # Skip if links within page, or
637 next if $target =~ /::/; # links to a Perl module, or
638 next if $target =~ /^https?:/; # is a URL link, or
639 next if $target =~ /\([1357]\)$/; # it has a section
640 err
($id, "Section missing in $target")
642 # Check for proper links to commands.
643 while ( $contents =~ /L<([^>]*)\(1\)(?:\/.*)?
>/g
) {
645 next if $target =~ /openssl-?/;
646 next if ( grep { basename
($_) eq "$target.pod" }
647 files
(TAGS
=> [ 'manual', 'man1' ]) );
648 # TODO: Filter out "foreign manual" links.
649 next if $target =~ /ps|apropos|sha1sum|procmail|perl/;
650 err
($id, "Bad command link L<$target(1)>");
652 # Check for proper in-man-3 API links.
653 while ( $contents =~ /L<([^>]*)\(3\)(?:\/.*)?
>/g
) {
655 err
($id, "Bad L<$target>")
656 unless $target =~ /^[_[:alpha:]][_[:alnum:]]*$/
659 unless ( $contents =~ /=for openssl generic/ ) {
660 if ( $filename =~ m
|man3
/| ) {
661 name_synopsis
($id, $filename, $contents);
662 functionname_check
($id, $filename, $contents);
663 } elsif ( $filename =~ m
|man1
/| ) {
664 option_check
($id, $filename, $contents)
668 wording
($id, $contents);
670 err
($id, "doesn't start with =pod")
671 if $contents !~ /^=pod/;
672 err
($id, "doesn't end with =cut")
673 if $contents !~ /=cut\n$/;
674 err
($id, "more than one cut line.")
675 if $contents =~ /=cut.*=cut/ms;
676 err
($id, "EXAMPLE not EXAMPLES section.")
677 if $contents =~ /=head1 EXAMPLE[^S]/;
678 err
($id, "WARNING not WARNINGS section.")
679 if $contents =~ /=head1 WARNING[^S]/;
680 err
($id, "missing copyright")
681 if $contents !~ /Copyright .* The OpenSSL Project Authors/;
682 err
($id, "copyright not last")
683 if $contents =~ /head1 COPYRIGHT.*=head/ms;
684 err
($id, "head2 in All uppercase")
685 if $contents =~ /head2\s+[A-Z ]+\n/;
686 err
($id, "extra space after head")
687 if $contents =~ /=head\d\s\s+/;
688 err
($id, "period in NAME section")
689 if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms;
690 err
($id, "Duplicate $1 in L<>")
691 if $contents =~ /L<([^>]*)\|([^>]*)>/ && $1 eq $2;
692 err
($id, "Bad =over $1")
693 if $contents =~ /=over([^ ][^24])/;
694 err
($id, "Possible version style issue")
695 if $contents =~ /OpenSSL version [019]/;
697 if ( $contents !~ /=for openssl multiple includes/ ) {
698 # Look for multiple consecutive openssl #include lines
699 # (non-consecutive lines are okay; see man3/MD5.pod).
700 if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) {
702 foreach my $line ( split /\n+/, $1 ) {
703 if ( $line =~ m
@include <openssl
/@
) {
704 err
($id, "has multiple includes")
713 open my $OUT, '>', $temp
714 or die "Can't open $temp, $!";
715 podchecker
($filename, $OUT);
717 open $OUT, '<', $temp
718 or die "Can't read $temp, $!";
720 next if /\(section\) in.*deprecated/;
724 unlink $temp || warn "Can't remove $temp, $!";
726 # Find what section this page is in; assume 3.
728 $section = $1 if $dirname =~ /man([1-9])/;
730 foreach ( (@
{$mandatory_sections{'*'}}, @
{$mandatory_sections{$section}}) ) {
731 err
($id, "missing $_ head1 section")
732 if $contents !~ /^=head1\s+${_}\s*$/m;
736 # Parse libcrypto.num, etc., and return sorted list of what's there.
741 open my $IN, '<', catfile
($config{sourcedir
}, $file)
742 or die "Can't open $file, $!, stopped";
746 next if /\bNOEXIST\b/;
747 my @fields = split();
748 die "Malformed line $_"
749 if scalar @fields != 2 && scalar @fields != 4;
750 push @apis, $fields[0];
758 # Parse all the manpages, getting return map of what they document
759 # (by looking at their NAME sections).
760 # Map of links in each POD file; filename => [ "foo(1)", "bar(3)", ... ]
762 # Map of names in each POD file; "name(s)" => filename
765 # Load file of symbol names that we know aren't documented.
768 my $missingfile = shift;
771 open FH
, catfile
($config{sourcedir
}, $missingfile)
772 or die "Can't open $missingfile";
781 err
("$missingfile:", "$_ is documented in $name_map{$_}")
782 if !$opt_o && exists $name_map{$_} && defined $name_map{$_};
788 # Check for undocumented macros; ignore those in the "missing" file
789 # and do simple check for #define in our header files.
796 @missing = loadmissing
('util/missingmacro111.txt');
798 @missing = loadmissing
('util/missingmacro.txt');
801 foreach my $f ( files
(TAGS
=> 'public_header') ) {
802 # Skip some internals we don't want to document yet.
803 my $b = basename
($f);
804 next if $b eq 'asn1.h';
805 next if $b eq 'asn1t.h';
806 next if $b eq 'err.h';
808 or die "Can't open $f, $!";
810 next unless /^#\s*define\s*(\S+)\(/;
811 my $macro = "$1(3)"; # We know they're all in section 3
812 next if exists $name_map{$macro} || defined $seen{$macro};
813 next if $macro =~ /^i2d_/
815 || $macro =~ /^DEPRECATEDIN/
816 || $macro =~ /\Q_fnsig(3)\E$/
817 || $macro =~ /^IMPLEMENT_/
818 || $macro =~ /^_?DECLARE_/;
820 # Skip macros known to be missing
821 next if $opt_v && grep( /^\Q$macro\E$/, @missing);
823 err
("$f:", "macro $macro undocumented")
830 err
("# $count macros undocumented (count is approximate)")
834 # Find out what is undocumented (filtering out the known missing ones)
839 my $missingfile = shift;
843 my @missing = loadmissing
($missingfile) if $opt_v;
845 foreach my $func ( parsenum
($numfile) ) {
846 $func .= '(3)'; # We know they're all in section 3
847 next if exists $name_map{$func} || defined $seen{$func};
849 # Skip functions known to be missing.
850 next if $opt_v && grep( /^\Q$func\E$/, @missing);
852 err
("$libname:", "function $func undocumented")
857 err
("# $count in $numfile are not documented")
861 # Collect all the names in a manpage.
863 my $filename = shift;
864 $filename =~ m
|man
(\d
)/|;
866 my $simplename = basename
($filename, ".pod");
867 my $id = "${filename}:1:";
868 my %podinfo = extract_pod_info
($filename, { debug
=> $debug });
870 unless ( grep { $simplename eq $_ } @
{$podinfo{names
}} ) {
871 err
($id, "$simplename not in NAME section");
872 push @
{$podinfo{names
}}, $simplename;
874 foreach my $name ( @
{$podinfo{names
}} ) {
876 err
($id, "'$name' contains white space")
878 my $name_sec = "$name($section)";
879 if ( !exists $name_map{$name_sec} ) {
880 $name_map{$name_sec} = $filename;
881 } elsif ( $filename eq $name_map{$name_sec} ) {
882 err
($id, "$name_sec duplicated in NAME section of",
883 $name_map{$name_sec});
885 err
($id, "$name_sec also in NAME section of",
886 $name_map{$name_sec});
890 if ( $podinfo{contents
} =~ /=for openssl foreign manual (.*)\n/ ) {
891 foreach my $f ( split / /, $1 ) {
892 $name_map{$f} = undef; # It still exists!
897 $podinfo{contents
} =~ /L
<
898 # if the link is of the form L<something|name(s)>,
899 # then remove 'something'. Note that 'something'
900 # may contain POD codes as well...
901 (?
:(?
:[^\
|]|<[^>]*>)*\
|)?
902 # we're only interested in references that have
903 # a one digit section number
906 $link_map{$filename} = [ @links ];
909 # Look for L<> ("link") references that point to files that do not exist.
911 foreach my $filename ( sort keys %link_map ) {
912 foreach my $link ( @
{$link_map{$filename}} ) {
913 err
("${filename}:1:", "reference to non-existing $link")
914 unless exists $name_map{$link};
919 # Load the public symbol/macro names
921 foreach my $name ( parsenum
('util/libcrypto.num') ) {
924 foreach my $name ( parsenum
('util/libssl.num') ) {
927 foreach my $name ( parsenum
('util/other.syms') ) {
932 # Cipher/digests to skip if they show up as "not implemented"
933 # because they are, via the "-*" construct.
951 # Check the flags of a command and see if everything is in the manpage
959 # Get the list of options in the command.
960 open CFH
, "$openssl list --options $cmd|"
961 or die "Can list options for $cmd, $!";
969 # Get the list of flags from the synopsis
971 or die "Can't open $doc, $!";
974 last if /DESCRIPTION/;
975 if ( /=for openssl ifdef (.*)/ ) {
976 foreach my $f ( split / /, $1 ) {
982 if ( /\[B<-([^ >]+)/ ) {
984 } elsif ( /^B<-([^ >]+)/ ) {
989 $opt = $1 if $opt =~ /I<(.*)/;
994 # See what's in the command not the manpage.
995 my @undocced = sort grep { !defined $docopts{$_} } keys %cmdopts;
996 foreach ( @undocced ) {
997 next if /-/; # Skip the -- end-of-flags marker
998 err
("$doc: undocumented option -$_");
1001 # See what's in the command not the manpage.
1002 my @unimpl = sort grep { !defined $cmdopts{$_} } keys %docopts;
1003 foreach ( @unimpl ) {
1004 next if defined $skips{$_} || defined $localskips{$_};
1005 err
("$doc: $cmd does not implement -$_");
1011 ## Do the work requested by the various getopt flags.
1012 ## The flags are parsed in alphabetical order, just because we have
1013 ## to have *some way* of listing them.
1019 # Get list of commands.
1020 open FH
, "$openssl list -1 -commands|"
1021 or die "Can't list commands, $!";
1028 # See if each has a manpage.
1029 foreach my $cmd ( @commands ) {
1030 next if $cmd eq 'help' || $cmd eq 'exit';
1031 my @doc = ( grep { basename
($_) eq "openssl-$cmd.pod"
1032 # For "tsget" and "CA.pl" pod pages
1033 || basename
($_) eq "$cmd.pod" }
1034 files
(TAGS
=> [ 'manual', 'man1' ]) );
1035 my $num = scalar @doc;
1037 err
("$num manuals for 'openssl $cmd': ".join(", ", @doc));
1038 } elsif ($num < 1) {
1039 err
("no manual for 'openssl $cmd'");
1041 checkflags
($cmd, @doc);
1045 # See what help is missing.
1046 open FH
, "$openssl list --missing-help |"
1047 or die "Can't list missing help, $!";
1050 my ($cmd, $flag) = split;
1051 err
("$cmd has no help for -$flag");
1058 # Preparation for some options, populate %name_map and %link_map
1059 if ( $opt_l || $opt_u || $opt_v ) {
1060 foreach ( files
(TAGS
=> 'manual') ) {
1066 foreach my $func ( loadmissing
("util/missingcrypto.txt") ) {
1067 $name_map{$func} = undef;
1074 foreach ( @ARGV ?
@ARGV : files
(TAGS
=> 'manual') ) {
1078 # If not given args, check that all man1 commands are named properly.
1079 if ( scalar @ARGV == 0 ) {
1080 foreach ( files
(TAGS
=> [ 'public_manual', 'man1' ]) ) {
1081 next if /CA.pl/ || /openssl\.pod/ || /tsget\.pod/;
1082 err
("$_ doesn't start with openssl-") unless /openssl-/;
1087 if ( $opt_u || $opt_v) {
1089 printem
('crypto', 'util/libcrypto.num', 'util/missingcrypto111.txt');
1090 printem
('ssl', 'util/libssl.num', 'util/missingssl111.txt');
1092 printem
('crypto', 'util/libcrypto.num', 'util/missingcrypto.txt');
1093 printem
('ssl', 'util/libssl.num', 'util/missingssl.txt');