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 # If it's a generic page (all lowercase), or apps, skip it.
42 return if $filename =~ /[a-z]+\.pod/;
43 return if $filename =~ m@/apps/@;
45 # Get NAME section and all words in it.
46 return unless $contents =~ /=head1 NAME(.*)=head1 SYNOPSIS/ms;
52 foreach my $n ( split ' ', $tmp ) {
56 # Find all functions in SYNOPSIS
57 return unless $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms;
59 foreach my $line ( split /\n+/, $syn ) {
60 next if $line =~ /typedef/;
61 next if $line =~ /STACK_OF/;
62 next unless $line =~ /([A-Za-z0-9_]+)\(/;
63 print "$id $1 missing from NAME section\n"
64 unless defined $names{$1};
68 foreach my $n ( keys %names ) {
69 next if $names{$n} == 2;
70 print "$id $n missing from SYNOPSIS\n";
77 my $dirname = basename(dirname($filename));
82 open POD, $filename or die "Couldn't open $filename, $!";
87 my $id = "${filename}:1:";
89 &name_synopsis($id, $filename, $contents);
91 print "$id doesn't start with =pod\n"
92 if $contents !~ /^=pod/;
93 print "$id doesn't end with =cut\n"
94 if $contents !~ /=cut\n$/;
95 print "$id more than one cut line.\n"
96 if $contents =~ /=cut.*=cut/ms;
97 print "$id missing copyright\n"
98 if $contents !~ /Copyright .* The OpenSSL Project Authors/;
99 print "$id copyright not last\n"
100 if $contents =~ /head1 COPYRIGHT.*=head/ms;
101 print "$id head2 in All uppercase\n"
102 if $contents =~ /head2\s+[A-Z ]+\n/;
103 print "$id extra space after head\n"
104 if $contents =~ /=head\d\s\s+/;
105 print "$id period in NAME section\n"
106 if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms;
107 print "$id POD markup in NAME section\n"
108 if $contents =~ /=head1 NAME.*[<>].*=head1 SYNOPSIS/ms;
110 # Look for multiple consecutive openssl #include lines.
111 # Consecutive because of files like md5.pod. Sometimes it's okay
112 # or necessary, as in ssl/SSL_set1_host.pod
113 if ( $contents !~ /=for comment multiple includes/ ) {
114 if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) {
116 foreach my $line ( split /\n+/, $1 ) {
117 if ( $line =~ m@include <openssl/@ ) {
118 if ( ++$count == 2 ) {
119 print "$id has multiple includes\n";
128 return unless $opt_s;
130 # Find what section this page is in. If run from "." assume
132 my $section = $default_sections{$dirname} || 3;
133 if ($contents =~ /^=for\s+comment\s+openssl_manual_section:\s*(\d+)\s*$/m) {
137 foreach ((@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}})) {
138 print "$id doesn't have a head1 section matching $_\n"
139 if $contents !~ /^=head1\s+${_}\s*$/m;
142 open my $OUT, '>', $temp
143 or die "Can't open $temp, $!";
144 podchecker($filename, $OUT);
146 open $OUT, '<', $temp
147 or die "Can't read $temp, $!";
149 next if /\(section\) in.*deprecated/;
153 unlink $temp || warn "Can't remove $temp, $!";
158 foreach (@ARGV ? @ARGV : glob('doc/*/*.pod')) {