Do not have duplicate section heads
[openssl.git] / util / find-doc-nits
index 1b9a2333a3d5678af29889f20e6ad94b2367f73b..9126e73586b4b2fe0cb5474fdd4152f4a9feca93 100755 (executable)
@@ -159,12 +159,44 @@ sub check_section_location()
     my $section = shift;
     my $before = shift;
 
-    return
-        unless $contents =~ /=head1 $section/ and $contents =~ /=head1 $before/;
-    print "$id $section should be placed before $before section\n"
+    return unless $contents =~ /=head1 $section/
+        and $contents =~ /=head1 $before/;
+    print "$id $section should appear before $before section\n"
         if $contents =~ /=head1 $before.*=head1 $section/ms;
 }
 
+# Check if a =head1 is duplicated, or a =headX is duplicated within a
+# =head1.  Treats =head2 =head3 as equivalent -- it doesn't reset the head3
+# sets if it finds a =head2 -- but that is good enough for now. Also check
+# for proper capitalization, trailing periods, etc.
+sub check_head_style()
+{
+    my $id = shift;
+    my $contents = shift;
+    my %head1;
+    my %subheads;
+
+    foreach my $line ( split /\n+/, $contents ) {
+        next unless $line =~ /^=head/;
+        if ( $line =~ /head1/ ) {
+            print "$id duplicate section $line\n"
+                if defined $head1{$line};
+            $head1{$line} = 1;
+            %subheads = ();
+        } else {
+            print "$id duplicate subsection $line\n"
+                if defined $subheads{$line};
+            $subheads{$line} = 1;
+        }
+        print "$id period in =head\n"
+            if $line =~ /\.[^\w]/ or $line =~ /\.$/;
+        print "$id not all uppercase in =head1\n"
+            if $line =~ /head1.*[a-z]/;
+        print "$id all uppercase in subhead\n"
+            if $line =~ /head[234][ A-Z0-9]+$/;
+    }
+}
+
 sub check()
 {
     my $filename = shift;
@@ -179,6 +211,7 @@ sub check()
     }
 
     my $id = "${filename}:1:";
+    &check_head_style($id, $contents);
 
     # Check ordering of some sections in man3
     if ( $filename =~ m|man3/| ) {