2016-05-20 12:11:46 +00:00
|
|
|
#! /usr/bin/env perl
|
2016-05-21 00:52:46 +00:00
|
|
|
# Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
# this file except in compliance with the License. You can obtain a copy
|
|
|
|
# in the file LICENSE in the source distribution or at
|
|
|
|
# https://www.openssl.org/source/license.html
|
|
|
|
|
2016-05-20 12:11:46 +00:00
|
|
|
|
|
|
|
require 5.10.0;
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use Pod::Checker;
|
|
|
|
use File::Find;
|
2016-05-21 23:26:45 +00:00
|
|
|
use File::Basename;
|
2016-11-13 06:00:44 +00:00
|
|
|
use File::Spec::Functions;
|
2016-06-01 17:10:24 +00:00
|
|
|
use Getopt::Std;
|
2016-11-13 06:00:44 +00:00
|
|
|
use lib catdir(dirname($0), "perl");
|
|
|
|
use OpenSSL::Util::Pod;
|
2016-06-01 17:10:24 +00:00
|
|
|
|
2016-11-13 06:00:44 +00:00
|
|
|
# Options.
|
2016-06-01 17:10:24 +00:00
|
|
|
our($opt_s);
|
2016-11-13 06:00:44 +00:00
|
|
|
our($opt_u);
|
|
|
|
our($opt_h);
|
|
|
|
our($opt_n);
|
|
|
|
|
|
|
|
sub help()
|
|
|
|
{
|
|
|
|
print <<EOF;
|
|
|
|
Find small errors (nits) in documentation. Options:
|
|
|
|
-n Print nits in POD pages
|
|
|
|
-s Also print missing sections in POD pages (implies -n)
|
|
|
|
-u List undocumented functions
|
|
|
|
-h Print this help message
|
|
|
|
EOF
|
|
|
|
exit;
|
|
|
|
}
|
2016-05-20 12:11:46 +00:00
|
|
|
|
2016-05-21 00:52:46 +00:00
|
|
|
my $temp = '/tmp/docnits.txt';
|
|
|
|
my $OUT;
|
|
|
|
|
2016-05-21 23:26:45 +00:00
|
|
|
my %mandatory_sections =
|
|
|
|
( '*' => [ 'NAME', 'DESCRIPTION', 'COPYRIGHT' ],
|
2016-12-12 16:14:40 +00:00
|
|
|
1 => [ 'SYNOPSIS', 'OPTIONS' ],
|
|
|
|
3 => [ 'SYNOPSIS', 'RETURN VALUES' ],
|
2016-05-21 23:26:45 +00:00
|
|
|
5 => [ ],
|
|
|
|
7 => [ ] );
|
|
|
|
|
2016-06-01 17:10:24 +00:00
|
|
|
# Cross-check functions in the NAME and SYNOPSIS section.
|
|
|
|
sub name_synopsis()
|
|
|
|
{
|
|
|
|
my $id = shift;
|
|
|
|
my $filename = shift;
|
|
|
|
my $contents = shift;
|
|
|
|
|
|
|
|
# Get NAME section and all words in it.
|
|
|
|
return unless $contents =~ /=head1 NAME(.*)=head1 SYNOPSIS/ms;
|
|
|
|
my $tmp = $1;
|
|
|
|
$tmp =~ tr/\n/ /;
|
|
|
|
$tmp =~ s/-.*//g;
|
|
|
|
$tmp =~ s/,//g;
|
2016-06-07 17:08:20 +00:00
|
|
|
|
|
|
|
my $dirname = dirname($filename);
|
|
|
|
my $simplename = basename($filename);
|
|
|
|
$simplename =~ s/.pod$//;
|
|
|
|
my $foundfilename = 0;
|
|
|
|
my %foundfilenames = ();
|
2016-06-01 17:10:24 +00:00
|
|
|
my %names;
|
|
|
|
foreach my $n ( split ' ', $tmp ) {
|
|
|
|
$names{$n} = 1;
|
2016-06-07 17:08:20 +00:00
|
|
|
$foundfilename++ if $n eq $simplename;
|
|
|
|
$foundfilenames{$n} = 1
|
|
|
|
if -f "$dirname/$n.pod" && $n ne $simplename;
|
2016-06-01 17:10:24 +00:00
|
|
|
}
|
2016-06-07 17:08:20 +00:00
|
|
|
print "$id the following exist as other .pod files:\n",
|
|
|
|
join(" ", sort keys %foundfilenames), "\n"
|
|
|
|
if %foundfilenames;
|
|
|
|
print "$id $simplename (filename) missing from NAME section\n",
|
|
|
|
unless $foundfilename;
|
2016-06-01 17:10:24 +00:00
|
|
|
|
|
|
|
# Find all functions in SYNOPSIS
|
|
|
|
return unless $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms;
|
|
|
|
my $syn = $1;
|
|
|
|
foreach my $line ( split /\n+/, $syn ) {
|
2016-06-09 21:02:59 +00:00
|
|
|
my $sym;
|
2016-06-21 11:03:34 +00:00
|
|
|
$line =~ s/STACK_OF\([^)]+\)/int/g;
|
|
|
|
$line =~ s/__declspec\([^)]+\)//;
|
2016-06-09 21:02:59 +00:00
|
|
|
if ( $line =~ /typedef.* (\S+);/ ) {
|
|
|
|
$sym = $1;
|
2016-06-21 11:03:34 +00:00
|
|
|
} elsif ( $line =~ /#define ([A-Za-z0-9_]+)/ ) {
|
2016-06-09 21:02:59 +00:00
|
|
|
$sym = $1;
|
|
|
|
} elsif ( $line =~ /([A-Za-z0-9_]+)\(/ ) {
|
|
|
|
$sym = $1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
print "$id $sym missing from NAME section\n"
|
|
|
|
unless defined $names{$sym};
|
|
|
|
$names{$sym} = 2;
|
2016-07-19 13:27:53 +00:00
|
|
|
|
|
|
|
# Do some sanity checks on the prototype.
|
|
|
|
print "$id prototype missing spaces around commas: $line\n"
|
|
|
|
if ( $line =~ /[a-z0-9],[^ ]/ );
|
2016-06-01 17:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $n ( keys %names ) {
|
|
|
|
next if $names{$n} == 2;
|
|
|
|
print "$id $n missing from SYNOPSIS\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 12:11:46 +00:00
|
|
|
sub check()
|
|
|
|
{
|
2016-05-21 23:26:45 +00:00
|
|
|
my $filename = shift;
|
|
|
|
my $dirname = basename(dirname($filename));
|
2016-06-03 18:49:20 +00:00
|
|
|
|
2016-05-20 12:11:46 +00:00
|
|
|
my $contents = '';
|
|
|
|
{
|
|
|
|
local $/ = undef;
|
2016-05-21 23:26:45 +00:00
|
|
|
open POD, $filename or die "Couldn't open $filename, $!";
|
2016-05-20 12:11:46 +00:00
|
|
|
$contents = <POD>;
|
|
|
|
close POD;
|
|
|
|
}
|
2016-06-03 18:49:20 +00:00
|
|
|
|
|
|
|
my $id = "${filename}:1:";
|
2016-06-01 17:10:24 +00:00
|
|
|
|
2016-06-07 19:49:08 +00:00
|
|
|
&name_synopsis($id, $filename, $contents)
|
2016-06-09 21:02:59 +00:00
|
|
|
unless $contents =~ /=for comment generic/
|
2016-10-26 17:56:48 +00:00
|
|
|
or $filename =~ m@man[157]/@;
|
2016-06-01 17:10:24 +00:00
|
|
|
|
|
|
|
print "$id doesn't start with =pod\n"
|
2016-05-21 00:52:46 +00:00
|
|
|
if $contents !~ /^=pod/;
|
2016-06-01 17:10:24 +00:00
|
|
|
print "$id doesn't end with =cut\n"
|
2016-05-21 00:52:46 +00:00
|
|
|
if $contents !~ /=cut\n$/;
|
2016-06-01 17:10:24 +00:00
|
|
|
print "$id more than one cut line.\n"
|
2016-05-21 00:52:46 +00:00
|
|
|
if $contents =~ /=cut.*=cut/ms;
|
2016-06-01 17:10:24 +00:00
|
|
|
print "$id missing copyright\n"
|
2016-05-21 00:52:46 +00:00
|
|
|
if $contents !~ /Copyright .* The OpenSSL Project Authors/;
|
2016-06-01 17:10:24 +00:00
|
|
|
print "$id copyright not last\n"
|
2016-05-21 00:52:46 +00:00
|
|
|
if $contents =~ /head1 COPYRIGHT.*=head/ms;
|
2016-06-01 17:10:24 +00:00
|
|
|
print "$id head2 in All uppercase\n"
|
2016-06-03 18:49:20 +00:00
|
|
|
if $contents =~ /head2\s+[A-Z ]+\n/;
|
2016-06-01 17:10:24 +00:00
|
|
|
print "$id extra space after head\n"
|
|
|
|
if $contents =~ /=head\d\s\s+/;
|
|
|
|
print "$id period in NAME section\n"
|
|
|
|
if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms;
|
|
|
|
print "$id POD markup in NAME section\n"
|
|
|
|
if $contents =~ /=head1 NAME.*[<>].*=head1 SYNOPSIS/ms;
|
2016-06-03 18:49:20 +00:00
|
|
|
|
|
|
|
# Look for multiple consecutive openssl #include lines.
|
|
|
|
# Consecutive because of files like md5.pod. Sometimes it's okay
|
|
|
|
# or necessary, as in ssl/SSL_set1_host.pod
|
|
|
|
if ( $contents !~ /=for comment multiple includes/ ) {
|
|
|
|
if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) {
|
|
|
|
my $count = 0;
|
|
|
|
foreach my $line ( split /\n+/, $1 ) {
|
|
|
|
if ( $line =~ m@include <openssl/@ ) {
|
|
|
|
if ( ++$count == 2 ) {
|
2016-06-01 17:10:24 +00:00
|
|
|
print "$id has multiple includes\n";
|
2016-06-03 18:49:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-21 00:52:46 +00:00
|
|
|
|
2016-06-01 17:10:24 +00:00
|
|
|
return unless $opt_s;
|
|
|
|
|
2016-06-03 18:49:20 +00:00
|
|
|
# Find what section this page is in. If run from "." assume
|
|
|
|
# section 3.
|
2016-10-26 17:56:48 +00:00
|
|
|
my $section = 3;
|
|
|
|
$section = $1 if $dirname =~ /man([1-9])/;
|
2016-05-21 23:26:45 +00:00
|
|
|
|
|
|
|
foreach ((@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}})) {
|
2016-12-12 16:14:40 +00:00
|
|
|
print "$id: missing $_ head1 section\n"
|
2016-05-21 23:26:45 +00:00
|
|
|
if $contents !~ /^=head1\s+${_}\s*$/m;
|
|
|
|
}
|
|
|
|
|
2016-06-01 17:10:24 +00:00
|
|
|
open my $OUT, '>', $temp
|
|
|
|
or die "Can't open $temp, $!";
|
2016-05-21 23:26:45 +00:00
|
|
|
podchecker($filename, $OUT);
|
2016-06-01 17:10:24 +00:00
|
|
|
close $OUT;
|
|
|
|
open $OUT, '<', $temp
|
|
|
|
or die "Can't read $temp, $!";
|
|
|
|
while ( <$OUT> ) {
|
|
|
|
next if /\(section\) in.*deprecated/;
|
|
|
|
print;
|
|
|
|
}
|
|
|
|
close $OUT;
|
|
|
|
unlink $temp || warn "Can't remove $temp, $!";
|
2016-05-21 00:52:46 +00:00
|
|
|
}
|
2016-05-20 12:11:46 +00:00
|
|
|
|
2016-11-13 06:00:44 +00:00
|
|
|
my %dups;
|
|
|
|
|
|
|
|
sub parsenum()
|
|
|
|
{
|
|
|
|
my $file = shift;
|
|
|
|
my @apis;
|
|
|
|
|
|
|
|
open my $IN, '<', $file
|
|
|
|
or die "Can't open $file, $!, stopped";
|
|
|
|
|
|
|
|
while ( <$IN> ) {
|
|
|
|
next if /\bNOEXIST\b/;
|
|
|
|
next if /\bEXPORT_VAR_AS_FUNC\b/;
|
|
|
|
push @apis, $1 if /([^\s]+).\s/;
|
|
|
|
}
|
|
|
|
|
|
|
|
close $IN;
|
|
|
|
|
|
|
|
print "# Found ", scalar(@apis), " in $file\n";
|
|
|
|
return sort @apis;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getdocced()
|
|
|
|
{
|
|
|
|
my $dir = shift;
|
|
|
|
my %return;
|
|
|
|
|
|
|
|
foreach my $pod ( glob("$dir/*.pod") ) {
|
|
|
|
my %podinfo = extract_pod_info($pod);
|
|
|
|
foreach my $n ( @{$podinfo{names}} ) {
|
|
|
|
$return{$n} = $pod;
|
|
|
|
print "# Duplicate $n in $pod and $dups{$n}\n"
|
|
|
|
if defined $dups{$n} && $dups{$n} ne $pod;
|
|
|
|
$dups{$n} = $pod;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return %return;
|
|
|
|
}
|
|
|
|
|
|
|
|
my %docced;
|
|
|
|
|
|
|
|
sub printem()
|
|
|
|
{
|
|
|
|
my $libname = shift;
|
|
|
|
my $numfile = shift;
|
|
|
|
my $count = 0;
|
|
|
|
|
|
|
|
foreach my $func ( &parsenum($numfile) ) {
|
|
|
|
next if $docced{$func};
|
|
|
|
|
|
|
|
# Skip ASN1 utilities
|
|
|
|
next if $func =~ /^ASN1_/;
|
|
|
|
|
|
|
|
print "$libname:$func\n";
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
print "# Found $count missing from $numfile\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getopts('nshu');
|
2016-06-01 17:10:24 +00:00
|
|
|
|
2016-11-13 06:00:44 +00:00
|
|
|
&help() if ( $opt_h );
|
|
|
|
|
2016-12-12 16:14:40 +00:00
|
|
|
die "Need one of -n -s or -u flags.\n"
|
|
|
|
unless $opt_n or $opt_s or $opt_u;
|
|
|
|
|
2016-11-13 06:00:44 +00:00
|
|
|
if ( $opt_n or $opt_s ) {
|
|
|
|
foreach (@ARGV ? @ARGV : glob('doc/*/*.pod')) {
|
|
|
|
&check($_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $opt_u ) {
|
|
|
|
my %temp = &getdocced('doc/man3');
|
|
|
|
foreach ( keys %temp ) {
|
|
|
|
$docced{$_} = $temp{$_};
|
|
|
|
}
|
|
|
|
&printem('crypto', 'util/libcrypto.num');
|
|
|
|
&printem('ssl', 'util/libssl.num');
|
2016-05-20 12:11:46 +00:00
|
|
|
}
|
2016-05-21 00:52:46 +00:00
|
|
|
|
2016-06-01 17:10:24 +00:00
|
|
|
exit;
|