check-doxy-blocks.pl 1.6 KB

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