Rename "private" file, doc doc changes in CHANGES
[openssl.git] / util / find-doc-nits
index 9c5826d05fba7916476197addc8bbfb7f8e855a6..c1e33fcfe455a0eae08660d1c45a601db856141d 100755 (executable)
@@ -33,24 +33,39 @@ our($opt_u);
 our($opt_v);
 our($opt_c);
 
+# Print usage message and exit.
 sub help {
     print <<EOF;
 Find small errors (nits) in documentation.  Options:
+    -c List undocumented commands and options
     -d Detailed list of undocumented (implies -u)
     -e Detailed list of new undocumented (implies -v)
-    -s Same as -e except no output is generated if nothing is undocumented
-    -o Causes -e/-v to count symbols added since 1.1.1 as new (implies -v)
+    -h Print this help message
     -l Print bogus links
     -n Print nits in POD pages
-    -p Warn if non-public name documented (implies -n)
+    -o Causes -e/-v to count symbols added since 1.1.1 as new (implies -v)
     -u Count undocumented functions
     -v Count new undocumented functions
-    -h Print this help message
-    -c List undocumented commands and options
 EOF
     exit;
 }
 
+getopts('cdehlnouv');
+
+help() if $opt_h;
+$opt_u = 1 if $opt_d;
+$opt_v = 1 if $opt_o || $opt_e;
+die "Cannot use both -u and -v"
+    if $opt_u && $opt_v;
+die "Cannot use both -d and -e"
+    if $opt_d && $opt_e;
+
+# We only need to check c, l, n, u and v.
+# Options d, e, o imply one of the above.
+die "Need one of -[cdehlnouv] flags.\n"
+    unless $opt_c or $opt_l or $opt_n or $opt_u or $opt_v;
+
+
 my $temp = '/tmp/docnits.txt';
 my $OUT;
 my %public;
@@ -109,9 +124,11 @@ sub name_synopsis {
         if %foundfilenames;
     err($id, "$simplename (filename) missing from NAME section")
         unless $foundfilename;
-    foreach my $n ( keys %names ) {
-        err($id, "$n is not public")
-            if $opt_p and !defined $public{$n};
+    if ( $filename !~ /internal/ ) {
+        foreach my $n ( keys %names ) {
+            err($id, "$n is not public")
+                if !defined $public{$n};
+        }
     }
 
     # Find all functions in SYNOPSIS
@@ -349,6 +366,62 @@ sub functionname_check {
     # with a variable part (typically marked up as B<foo_I<TYPE>_bar>
 }
 
+# This is from http://man7.org/linux/man-pages/man7/man-pages.7.html
+my %preferred_words = (
+    'bitmask'       => 'bit mask',
+    'builtin'       => 'built-in',
+   #'epoch'         => 'Epoch', # handled specially, below
+    'file name'     => 'filename',
+    'file system'   => 'filesystem',
+    'host name'     => 'hostname',
+    'i-node'        => 'inode',
+    'lower case'    => 'lowercase',
+    'lower-case'    => 'lowercase',
+    'non-zero'      => 'nonzero',
+    'path name'     => 'pathname',
+    'pseudo-terminal' => 'pseudoterminal',
+    'reserved port' => 'privileged port',
+    'system port'   => 'privileged port',
+    'realtime'      => 'real-time',
+    'real time'     => 'real-time',
+    'runtime'       => 'run time',
+    'saved group ID'=> 'saved set-group-ID',
+    'saved set-GID' => 'saved set-group-ID',
+    'saved user ID' => 'saved set-user-ID',
+    'saved set-UID' => 'saved set-user-ID',
+    'set-GID'       => 'set-group-ID',
+    'setgid'        => 'set-group-ID',
+    'set-UID'       => 'set-user-ID',
+    'setuid'        => 'set-user-ID',
+    'super user'    => 'superuser',
+    'super-user'    => 'superuser',
+    'super block'   => 'superblock',
+    'super-block'   => 'superblock',
+    'time stamp'    => 'timestamp',
+    'time zone'     => 'timezone',
+    'upper case'    => 'uppercase',
+    'upper-case'    => 'uppercase',
+    'useable'       => 'usable',
+    'userspace'     => 'user space',
+    'user name'     => 'username',
+    'zeroes'        => 'zeros'
+);
+
+sub wording {
+    my $id = shift;
+    my $contents = shift;
+
+    foreach my $k ( keys %preferred_words ) {
+        # Sigh, trademark
+        next if $k eq 'file system'
+            and $contents =~ /Microsoft Encrypted File System/;
+        err($id, "found '$k' should use '$preferred_words{$k}'")
+            if $contents =~ /\b\Q$k\E\b/i;
+    }
+    err($id, "found 'epoch' should use 'Epoch'")
+        if $contents =~ /\bepoch\b/;
+}
+
 sub check {
     my $filename = shift;
     my $dirname = basename(dirname($filename));
@@ -380,6 +453,8 @@ sub check {
         }
     }
 
+    wording($id, $contents);
+
     err($id, "doesn't start with =pod")
         if $contents !~ /^=pod/;
     err($id, "doesn't end with =cut")
@@ -467,7 +542,6 @@ sub parsenum {
 
     close $IN;
 
-    print "# Found ", scalar(@apis), " in $file\n" unless $opt_p;
     return sort @apis;
 }
 
@@ -480,7 +554,7 @@ sub getdocced
         my %podinfo = extract_pod_info($pod);
         foreach my $n ( @{$podinfo{names}} ) {
             $return{$n} = $pod;
-            print "# Duplicate $n in $pod and $dups{$n}\n"
+            err("# Duplicate $n in $pod and $dups{$n}")
                 if defined $dups{$n} && $dups{$n} ne $pod;
             $dups{$n} = $pod;
         }
@@ -519,8 +593,6 @@ sub checkmacros {
         @missing = loadmissing('util/missingmacro.txt');
     }
 
-    print "# Checking macros (approximate)\n"
-        if !$opt_s;
     foreach my $f ( glob('include/openssl/*.h') ) {
         # Skip some internals we don't want to document yet.
         next if $f eq 'include/openssl/asn1.h';
@@ -540,15 +612,15 @@ sub checkmacros {
             # Skip macros known to be missing
             next if $opt_v && grep( /^$macro$/, @missing);
     
-            print "$f:$macro\n"
+            err("$f:", "macro $macro undocumented")
                 if $opt_d || $opt_e;
             $count++;
             $seen{$macro} = 1;
         }
         close(IN);
     }
-    print "# Found $count macros missing\n"
-        if !$opt_s || $count > 0;
+    err("# $count macros undocumented (count is approximate)")
+        if $count > 0;
 }
 
 sub printem {
@@ -569,13 +641,13 @@ sub printem {
         # Skip functions known to be missing
         next if $opt_v && grep( /^$func$/, @missing);
 
-        print "$libname:$func\n"
+        err("$libname:", "function $func undocumented")
             if $opt_d || $opt_e;
         $count++;
         $seen{$func} = 1;
     }
-    print "# Found $count missing from $numfile\n\n"
-        if !$opt_s || $count > 0;
+    err("# $count in $numfile are not documented")
+        if $count > 0;
 }
 
 
@@ -663,6 +735,7 @@ sub checklinks {
     }
 }
 
+# Load the public symbol/macro names
 sub publicize {
     foreach my $name ( parsenum('util/libcrypto.num') ) {
         $public{$name} = 1;
@@ -670,7 +743,7 @@ sub publicize {
     foreach my $name ( parsenum('util/libssl.num') ) {
         $public{$name} = 1;
     }
-    foreach my $name ( parsenum('util/private.num') ) {
+    foreach my $name ( parsenum('util/other.syms') ) {
         $public{$name} = 1;
     }
 }
@@ -753,25 +826,6 @@ sub checkflags {
     }
 }
 
-getopts('cdesolnphuv');
-
-help() if $opt_h;
-
-$opt_n = 1 if $opt_p;
-$opt_u = 1 if $opt_d;
-$opt_e = 1 if $opt_s;
-$opt_v = 1 if $opt_o || $opt_e;
-
-die "Cannot use both -u and -v"
-    if $opt_u && $opt_v;
-die "Cannot use both -d and -e"
-    if $opt_d && $opt_e;
-
-# We only need to check c, l, n, u and v.
-# Options d, e, s, o and p imply one of the above.
-die "Need one of -[cdesolnpuv] flags.\n"
-    unless $opt_c or $opt_l or $opt_n or $opt_u or $opt_v;
-
 if ( $opt_c ) {
     my @commands = ();
 
@@ -818,15 +872,12 @@ if ( $opt_l ) {
 }
 
 if ( $opt_n ) {
-    publicize() if $opt_p;
+    publicize();
     foreach (@ARGV ? @ARGV : (glob('doc/*/*.pod'), glob('doc/*/*.pod.in'))) {
         check($_);
     }
-    {
-        local $opt_p = undef;
-        foreach (@ARGV ? @ARGV : glob('doc/internal/*/*.pod')) {
-            check($_);
-        }
+    foreach (@ARGV ? @ARGV : glob('doc/internal/*/*.pod')) {
+        check($_);
     }
 
     # If not given args, check that all man1 commands are named properly.