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 my $dirname = dirname($filename);
53 my $simplename = basename($filename);
54 $simplename =~ s/.pod$//;
55 my $foundfilename = 0;
56 my %foundfilenames = ();
58 foreach my $n ( split ' ', $tmp ) {
60 $foundfilename++ if $n eq $simplename;
61 $foundfilenames{$n} = 1
62 if -f "$dirname/$n.pod" && $n ne $simplename;
64 print "$id the following exist as other .pod files:\n",
65 join(" ", sort keys %foundfilenames), "\n"
67 print "$id $simplename (filename) missing from NAME section\n",
68 unless $foundfilename;
70 # Find all functions in SYNOPSIS
71 return unless $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms;
73 foreach my $line ( split /\n+/, $syn ) {
74 next if $line =~ /typedef/;
75 next if $line =~ /STACK_OF/;
76 next unless $line =~ /([A-Za-z0-9_]+)\(/;
77 print "$id $1 missing from NAME section\n"
78 unless defined $names{$1};
82 foreach my $n ( keys %names ) {
83 next if $names{$n} == 2;
84 print "$id $n missing from SYNOPSIS\n";
91 my $dirname = basename(dirname($filename));
96 open POD, $filename or die "Couldn't open $filename, $!";
101 my $id = "${filename}:1:";
103 &name_synopsis($id, $filename, $contents)
104 unless $contents =~ /=for comment generic/;
106 print "$id doesn't start with =pod\n"
107 if $contents !~ /^=pod/;
108 print "$id doesn't end with =cut\n"
109 if $contents !~ /=cut\n$/;
110 print "$id more than one cut line.\n"
111 if $contents =~ /=cut.*=cut/ms;
112 print "$id missing copyright\n"
113 if $contents !~ /Copyright .* The OpenSSL Project Authors/;
114 print "$id copyright not last\n"
115 if $contents =~ /head1 COPYRIGHT.*=head/ms;
116 print "$id head2 in All uppercase\n"
117 if $contents =~ /head2\s+[A-Z ]+\n/;
118 print "$id extra space after head\n"
119 if $contents =~ /=head\d\s\s+/;
120 print "$id period in NAME section\n"
121 if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms;
122 print "$id POD markup in NAME section\n"
123 if $contents =~ /=head1 NAME.*[<>].*=head1 SYNOPSIS/ms;
125 # Look for multiple consecutive openssl #include lines.
126 # Consecutive because of files like md5.pod. Sometimes it's okay
127 # or necessary, as in ssl/SSL_set1_host.pod
128 if ( $contents !~ /=for comment multiple includes/ ) {
129 if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) {
131 foreach my $line ( split /\n+/, $1 ) {
132 if ( $line =~ m@include <openssl/@ ) {
133 if ( ++$count == 2 ) {
134 print "$id has multiple includes\n";
143 return unless $opt_s;
145 # Find what section this page is in. If run from "." assume
147 my $section = $default_sections{$dirname} || 3;
148 if ($contents =~ /^=for\s+comment\s+openssl_manual_section:\s*(\d+)\s*$/m) {
152 foreach ((@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}})) {
153 print "$id doesn't have a head1 section matching $_\n"
154 if $contents !~ /^=head1\s+${_}\s*$/m;
157 open my $OUT, '>', $temp
158 or die "Can't open $temp, $!";
159 podchecker($filename, $OUT);
161 open $OUT, '<', $temp
162 or die "Can't read $temp, $!";
164 next if /\(section\) in.*deprecated/;
168 unlink $temp || warn "Can't remove $temp, $!";
173 foreach (@ARGV ? @ARGV : glob('doc/*/*.pod')) {