Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | # Detect comment blocks that are likely meant to be doxygen blocks but aren't. |
| 4 | # |
| 5 | # More precisely, look for normal comment block containing '\'. |
| 6 | # Of course one could use doxygen warnings, eg with: |
| 7 | # sed -e '/EXTRACT/s/YES/NO/' doxygen/polarssl.doxyfile | doxygen - |
| 8 | # but that would warn about any undocumented item, while our goal is to find |
| 9 | # items that are documented, but not marked as such by mistake. |
| 10 | |
| 11 | use warnings; |
| 12 | use strict; |
| 13 | use File::Basename; |
| 14 | |
| 15 | # header files in the following directories will be checked |
| 16 | my @directories = qw(include/polarssl library doxygen/input); |
| 17 | |
| 18 | # very naive pattern to find directives: |
Manuel Pégourié-Gonnard | ef009ff | 2013-09-16 13:40:25 +0200 | [diff] [blame] | 19 | # everything with a backslach except '\0' and backslash at EOL |
| 20 | my $doxy_re = qr/\\(?!0|\n)/; |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 21 | |
| 22 | sub check_file { |
| 23 | my ($fname) = @_; |
| 24 | open my $fh, '<', $fname or die "Failed to open '$fname': $!\n"; |
| 25 | |
| 26 | # first line of the last normal comment block, |
| 27 | # or 0 if not in a normal comment block |
| 28 | my $block_start = 0; |
| 29 | while (my $line = <$fh>) { |
| 30 | $block_start = $. if $line =~ m/\/\*(?![*!])/; |
| 31 | $block_start = 0 if $line =~ m/\*\//; |
| 32 | if ($block_start and $line =~ m/$doxy_re/) { |
| 33 | print "$fname:$block_start: directive on line $.\n"; |
| 34 | $block_start = 0; # report only one directive per block |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | close $fh; |
| 39 | } |
| 40 | |
| 41 | sub check_dir { |
| 42 | my ($dirname) = @_; |
| 43 | for my $file (<$dirname/*.[ch]>) { |
| 44 | check_file($file); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | # locate root directory based on invocation name |
| 49 | my $root = dirname($0) . '/..'; |
| 50 | chdir $root or die "Can't chdir to '$root': $!\n"; |
| 51 | |
| 52 | # just do it |
| 53 | for my $dir (@directories) { |
| 54 | check_dir($dir) |
| 55 | } |
| 56 | |
| 57 | __END__ |