2 # Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (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
16 use File::Spec::Functions;
18 use lib catdir(dirname($0), "perl");
19 use OpenSSL::Util::Pod;
30 Find small errors (nits) in documentation. Options:
31 -n Print nits in POD pages
32 -s Also print missing sections in POD pages (implies -n)
33 -u List undocumented functions
34 -h Print this help message
39 my $temp = '/tmp/docnits.txt';
42 my %mandatory_sections =
43 ( '*' => [ 'NAME', 'DESCRIPTION', 'COPYRIGHT' ],
44 1 => [ 'SYNOPSIS', '(COMMAND\s+)?OPTIONS' ],
45 3 => [ 'SYNOPSIS', 'RETURN\s+VALUES' ],
49 # Cross-check functions in the NAME and SYNOPSIS section.
56 # Get NAME section and all words in it.
57 return unless $contents =~ /=head1 NAME(.*)=head1 SYNOPSIS/ms;
63 my $dirname = dirname($filename);
64 my $simplename = basename($filename);
65 $simplename =~ s/.pod$//;
66 my $foundfilename = 0;
67 my %foundfilenames = ();
69 foreach my $n ( split ' ', $tmp ) {
71 $foundfilename++ if $n eq $simplename;
72 $foundfilenames{$n} = 1
73 if -f "$dirname/$n.pod" && $n ne $simplename;
75 print "$id the following exist as other .pod files:\n",
76 join(" ", sort keys %foundfilenames), "\n"
78 print "$id $simplename (filename) missing from NAME section\n",
79 unless $foundfilename;
81 # Find all functions in SYNOPSIS
82 return unless $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms;
84 foreach my $line ( split /\n+/, $syn ) {
86 $line =~ s/STACK_OF\([^)]+\)/int/g;
87 $line =~ s/__declspec\([^)]+\)//;
88 if ( $line =~ /typedef.* (\S+);/ ) {
90 } elsif ( $line =~ /#define ([A-Za-z0-9_]+)/ ) {
92 } elsif ( $line =~ /([A-Za-z0-9_]+)\(/ ) {
98 print "$id $sym missing from NAME section\n"
99 unless defined $names{$sym};
102 # Do some sanity checks on the prototype.
103 print "$id prototype missing spaces around commas: $line\n"
104 if ( $line =~ /[a-z0-9],[^ ]/ );
107 foreach my $n ( keys %names ) {
108 next if $names{$n} == 2;
109 print "$id $n missing from SYNOPSIS\n";
115 my $filename = shift;
116 my $dirname = basename(dirname($filename));
121 open POD, $filename or die "Couldn't open $filename, $!";
126 my $id = "${filename}:1:";
128 &name_synopsis($id, $filename, $contents)
129 unless $contents =~ /=for comment generic/
130 or $filename =~ m@man[157]/@;
132 print "$id doesn't start with =pod\n"
133 if $contents !~ /^=pod/;
134 print "$id doesn't end with =cut\n"
135 if $contents !~ /=cut\n$/;
136 print "$id more than one cut line.\n"
137 if $contents =~ /=cut.*=cut/ms;
138 print "$id missing copyright\n"
139 if $contents !~ /Copyright .* The OpenSSL Project Authors/;
140 print "$id copyright not last\n"
141 if $contents =~ /head1 COPYRIGHT.*=head/ms;
142 print "$id head2 in All uppercase\n"
143 if $contents =~ /head2\s+[A-Z ]+\n/;
144 print "$id extra space after head\n"
145 if $contents =~ /=head\d\s\s+/;
146 print "$id period in NAME section\n"
147 if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms;
148 print "$id POD markup in NAME section\n"
149 if $contents =~ /=head1 NAME.*[<>].*=head1 SYNOPSIS/ms;
151 # Look for multiple consecutive openssl #include lines.
152 # Consecutive because of files like md5.pod. Sometimes it's okay
153 # or necessary, as in ssl/SSL_set1_host.pod
154 if ( $contents !~ /=for comment multiple includes/ ) {
155 if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) {
157 foreach my $line ( split /\n+/, $1 ) {
158 if ( $line =~ m@include <openssl/@ ) {
159 if ( ++$count == 2 ) {
160 print "$id has multiple includes\n";
169 return unless $opt_s;
171 # Find what section this page is in. If run from "." assume
174 $section = $1 if $dirname =~ /man([1-9])/;
176 foreach ((@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}})) {
177 print "$id doesn't have a head1 section matching $_\n"
178 if $contents !~ /^=head1\s+${_}\s*$/m;
181 open my $OUT, '>', $temp
182 or die "Can't open $temp, $!";
183 podchecker($filename, $OUT);
185 open $OUT, '<', $temp
186 or die "Can't read $temp, $!";
188 next if /\(section\) in.*deprecated/;
192 unlink $temp || warn "Can't remove $temp, $!";
202 open my $IN, '<', $file
203 or die "Can't open $file, $!, stopped";
206 next if /\bNOEXIST\b/;
207 next if /\bEXPORT_VAR_AS_FUNC\b/;
208 push @apis, $1 if /([^\s]+).\s/;
213 print "# Found ", scalar(@apis), " in $file\n";
222 foreach my $pod ( glob("$dir/*.pod") ) {
223 my %podinfo = extract_pod_info($pod);
224 foreach my $n ( @{$podinfo{names}} ) {
226 print "# Duplicate $n in $pod and $dups{$n}\n"
227 if defined $dups{$n} && $dups{$n} ne $pod;
243 foreach my $func ( &parsenum($numfile) ) {
244 next if $docced{$func};
246 # Skip ASN1 utilities
247 next if $func =~ /^ASN1_/;
249 print "$libname:$func\n";
252 print "# Found $count missing from $numfile\n\n";
258 &help() if ( $opt_h );
260 if ( $opt_n or $opt_s ) {
261 foreach (@ARGV ? @ARGV : glob('doc/*/*.pod')) {
266 my %temp = &getdocced('doc/man3');
267 foreach ( keys %temp ) {
268 $docced{$_} = $temp{$_};
270 &printem('crypto', 'util/libcrypto.num');
271 &printem('ssl', 'util/libssl.num');