X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=util%2Ffind-doc-nits.pl;h=e90b3d7d0761cfdd8398dfd7fea1651f37fd1d01;hb=697958313ba48c8ebc832ab8f9f2b845fb7acfd4;hp=69d7c93521363fc1cd3356c3de681b1cdea0268f;hpb=8162f6f58aa784e242941d1168fb8fc0618cf0a2;p=openssl.git diff --git a/util/find-doc-nits.pl b/util/find-doc-nits.pl index 69d7c93521..e90b3d7d07 100755 --- a/util/find-doc-nits.pl +++ b/util/find-doc-nits.pl @@ -13,23 +13,38 @@ use strict; use Pod::Checker; use File::Find; use File::Basename; +use File::Spec::Functions; use Getopt::Std; +use lib catdir(dirname($0), "perl"); +use OpenSSL::Util::Pod; +# Options. our($opt_s); +our($opt_u); +our($opt_h); +our($opt_n); + +sub help() +{ + print < [ 'NAME', 'DESCRIPTION', 'COPYRIGHT' ], - 1 => [ 'SYNOPSIS', '(COMMAND\s+)?OPTIONS' ], - 3 => [ 'SYNOPSIS', 'RETURN\s+VALUES' ], + 1 => [ 'SYNOPSIS', 'OPTIONS' ], + 3 => [ 'SYNOPSIS', 'RETURN VALUES' ], 5 => [ ], 7 => [ ] ); -my %default_sections = - ( apps => 1, - crypto => 3, - ssl => 3 ); # Cross-check functions in the NAME and SYNOPSIS section. sub name_synopsis() @@ -68,10 +83,18 @@ sub name_synopsis() my $syn = $1; foreach my $line ( split /\n+/, $syn ) { my $sym; - $line =~ s/STACK_OF\([^)]+\)//; - if ( $line =~ /typedef.* (\S+);/ ) { + $line =~ s/STACK_OF\([^)]+\)/int/g; + $line =~ s/__declspec\([^)]+\)//; + if ( $line =~ /env (\S*)=/ ) { + # environment variable env NAME=... + $sym = $1; + } elsif ( $line =~ /typedef.*\(\*(\S+)\)\(.*/ ) { + # a callback function: typedef ... (*NAME)(... + $sym = $1; + } elsif ( $line =~ /typedef.* (\S+);/ ) { + # a simple typedef: typedef ... NAME; $sym = $1; - } elsif ( $line =~ /#define (\S+)/ ) { + } elsif ( $line =~ /#define ([A-Za-z0-9_]+)/ ) { $sym = $1; } elsif ( $line =~ /([A-Za-z0-9_]+)\(/ ) { $sym = $1; @@ -82,6 +105,10 @@ sub name_synopsis() print "$id $sym missing from NAME section\n" unless defined $names{$sym}; $names{$sym} = 2; + + # Do some sanity checks on the prototype. + print "$id prototype missing spaces around commas: $line\n" + if ( $line =~ /[a-z0-9],[^ ]/ ); } foreach my $n ( keys %names ) { @@ -107,8 +134,7 @@ sub check() &name_synopsis($id, $filename, $contents) unless $contents =~ /=for comment generic/ - or $contents =~ /=for comment openssl_manual_section:7/ - or $filename =~ m@/apps/@; + or $filename =~ m@man[157]/@; print "$id doesn't start with =pod\n" if $contents !~ /^=pod/; @@ -151,13 +177,11 @@ sub check() # Find what section this page is in. If run from "." assume # section 3. - my $section = $default_sections{$dirname} || 3; - if ($contents =~ /^=for\s+comment\s+openssl_manual_section:\s*(\d+)\s*$/m) { - $section = $1; - } + my $section = 3; + $section = $1 if $dirname =~ /man([1-9])/; foreach ((@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}})) { - print "$id doesn't have a head1 section matching $_\n" + print "$id: missing $_ head1 section\n" if $contents !~ /^=head1\s+${_}\s*$/m; } @@ -175,10 +199,86 @@ sub check() unlink $temp || warn "Can't remove $temp, $!"; } -getopts('s'); +my %dups; + +sub parsenum() +{ + my $file = shift; + my @apis; + + open my $IN, '<', $file + or die "Can't open $file, $!, stopped"; -foreach (@ARGV ? @ARGV : glob('doc/*/*.pod')) { - &check($_); + 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'); + +&help() if ( $opt_h ); + +die "Need one of -n -s or -u flags.\n" + unless $opt_n or $opt_s or $opt_u; + +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'); } exit;