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
20 my $temp = '/tmp/docnits.txt';
23 my %mandatory_sections =
24 ( '*' => [ 'NAME', 'DESCRIPTION', 'COPYRIGHT' ],
25 1 => [ 'SYNOPSIS', '(COMMAND\s+)?OPTIONS' ],
26 3 => [ 'SYNOPSIS', 'RETURN\s+VALUES' ],
29 my %default_sections =
34 # Cross-check functions in the NAME and SYNOPSIS section.
41 # Get NAME section and all words in it.
42 return unless $contents =~ /=head1 NAME(.*)=head1 SYNOPSIS/ms;
48 my $dirname = dirname($filename);
49 my $simplename = basename($filename);
50 $simplename =~ s/.pod$//;
51 my $foundfilename = 0;
52 my %foundfilenames = ();
54 foreach my $n ( split ' ', $tmp ) {
56 $foundfilename++ if $n eq $simplename;
57 $foundfilenames{$n} = 1
58 if -f "$dirname/$n.pod" && $n ne $simplename;
60 print "$id the following exist as other .pod files:\n",
61 join(" ", sort keys %foundfilenames), "\n"
63 print "$id $simplename (filename) missing from NAME section\n",
64 unless $foundfilename;
66 # Find all functions in SYNOPSIS
67 return unless $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms;
69 foreach my $line ( split /\n+/, $syn ) {
71 $line =~ s/STACK_OF\([^)]+\)/int/g;
72 $line =~ s/__declspec\([^)]+\)//;
73 if ( $line =~ /typedef.* (\S+);/ ) {
75 } elsif ( $line =~ /#define ([A-Za-z0-9_]+)/ ) {
77 } elsif ( $line =~ /([A-Za-z0-9_]+)\(/ ) {
83 print "$id $sym missing from NAME section\n"
84 unless defined $names{$sym};
87 # Do some sanity checks on the prototype.
88 print "$id prototype missing spaces around commas: $line\n"
89 if ( $line =~ /[a-z0-9],[^ ]/ );
92 foreach my $n ( keys %names ) {
93 next if $names{$n} == 2;
94 print "$id $n missing from SYNOPSIS\n";
100 my $filename = shift;
101 my $dirname = basename(dirname($filename));
106 open POD, $filename or die "Couldn't open $filename, $!";
111 my $id = "${filename}:1:";
113 &name_synopsis($id, $filename, $contents)
114 unless $contents =~ /=for comment generic/
115 or $contents =~ /=for comment openssl_manual_section:7/
116 or $filename =~ m@/apps/@;
118 print "$id doesn't start with =pod\n"
119 if $contents !~ /^=pod/;
120 print "$id doesn't end with =cut\n"
121 if $contents !~ /=cut\n$/;
122 print "$id more than one cut line.\n"
123 if $contents =~ /=cut.*=cut/ms;
124 print "$id missing copyright\n"
125 if $contents !~ /Copyright .* The OpenSSL Project Authors/;
126 print "$id copyright not last\n"
127 if $contents =~ /head1 COPYRIGHT.*=head/ms;
128 print "$id head2 in All uppercase\n"
129 if $contents =~ /head2\s+[A-Z ]+\n/;
130 print "$id extra space after head\n"
131 if $contents =~ /=head\d\s\s+/;
132 print "$id period in NAME section\n"
133 if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms;
134 print "$id POD markup in NAME section\n"
135 if $contents =~ /=head1 NAME.*[<>].*=head1 SYNOPSIS/ms;
137 # Look for multiple consecutive openssl #include lines.
138 # Consecutive because of files like md5.pod. Sometimes it's okay
139 # or necessary, as in ssl/SSL_set1_host.pod
140 if ( $contents !~ /=for comment multiple includes/ ) {
141 if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) {
143 foreach my $line ( split /\n+/, $1 ) {
144 if ( $line =~ m@include <openssl/@ ) {
145 if ( ++$count == 2 ) {
146 print "$id has multiple includes\n";
155 return unless $opt_s;
157 # Find what section this page is in. If run from "." assume
159 my $section = $default_sections{$dirname} || 3;
160 if ($contents =~ /^=for\s+comment\s+openssl_manual_section:\s*(\d+)\s*$/m) {
164 foreach ((@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}})) {
165 print "$id doesn't have a head1 section matching $_\n"
166 if $contents !~ /^=head1\s+${_}\s*$/m;
169 open my $OUT, '>', $temp
170 or die "Can't open $temp, $!";
171 podchecker($filename, $OUT);
173 open $OUT, '<', $temp
174 or die "Can't read $temp, $!";
176 next if /\(section\) in.*deprecated/;
180 unlink $temp || warn "Can't remove $temp, $!";
185 foreach (@ARGV ? @ARGV : glob('doc/*/*.pod')) {