manpage-syntax.pl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.haxx.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. ###########################################################################
  23. #
  24. # Scan man page(s) and detect some simple and yet common formatting mistakes.
  25. #
  26. # Output all deviances to stderr.
  27. use strict;
  28. use warnings;
  29. # we may get the dir roots pointed out
  30. my @manpages=@ARGV;
  31. my $errors = 0;
  32. sub scanmanpage {
  33. my ($file) = @_;
  34. print "Check $file\n";
  35. open(M, "<$file") || die "no such file: $file";
  36. my $line = 1;
  37. while(<M>) {
  38. if($_ =~ /^\'/) {
  39. print STDERR "$file:$line line starts with single quote!\n";
  40. $errors++;
  41. }
  42. if($_ =~ /\\f([BI])(.*)/) {
  43. my ($format, $rest) = ($1, $2);
  44. if($rest !~ /\\fP/) {
  45. print STDERR "$file:$line missing \\f${format} terminator!\n";
  46. $errors++;
  47. }
  48. }
  49. $line++;
  50. }
  51. close(M);
  52. }
  53. for my $m (@manpages) {
  54. scanmanpage($m);
  55. }
  56. exit $errors;