3cf260bd28fd75e79cc8d2269407e5c5d1f25bd8
[openssl.git] / util / doc-nit-check.pl
1 #! /usr/bin/env perl
2 # Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
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
8
9
10 require 5.10.0;
11 use warnings;
12 use strict;
13 use Pod::Checker;
14 use File::Find;
15
16 my $temp = '/tmp/docnits.txt';
17 my $OUT;
18
19 sub check()
20 {
21     my $contents = '';
22     {
23         local $/ = undef;
24         open POD, $_ or die "Couldn't open $_, $!";
25         $contents = <POD>;
26         close POD;
27     }
28     print $OUT "$_ doesn't start with =pod\n"
29         if $contents !~ /^=pod/;
30     print $OUT "$_ doesn't end with =cut\n"
31         if $contents !~ /=cut\n$/;
32     print $OUT "$_ more than one cut line.\n"
33         if $contents =~ /=cut.*=cut/ms;
34     print $OUT "$_ missing copyright\n"
35         if $contents !~ /Copyright .* The OpenSSL Project Authors/;
36     print $OUT "$_ copyright not last\n"
37         if $contents =~ /head1 COPYRIGHT.*=head/ms;
38     print $OUT "$_ head2 in All uppercase\n"
39         if $contents =~ /head2.*[A-Z ]+\n/;
40
41     podchecker($_, $OUT);
42 }
43
44 open $OUT, '>', $temp
45     or die "Can't open $temp, $!";
46 foreach (@ARGV ? @ARGV : glob('*/*.pod')) {
47     &check($_);
48 }
49 close $OUT;
50
51 my $count = 0;
52 open $OUT, '<', $temp
53     or die "Can't read $temp, $!";
54 while ( <$OUT> ) {
55     next if /\(section\) in.*deprecated/;
56     $count++;
57     print;
58 }
59 close $OUT;
60 unlink $temp || warn "Can't remove $temp, $!";
61
62 exit $count;