nroff-scan.pl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 2016, 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 nroff pages to find basic syntactic problems such as unbalanced \f
  25. # codes or references to non-existing curl man pages.
  26. my $docsroot = $ARGV[0];
  27. if(!$docsroot || ($docsroot eq "-g")) {
  28. print "Usage: nroff-scan.pl <docs root dir> [nroff files]\n";
  29. exit;
  30. }
  31. shift @ARGV;
  32. my @f = @ARGV;
  33. my %manp;
  34. sub manpresent {
  35. my ($man) = @_;
  36. if($manp{$man}) {
  37. return 1;
  38. }
  39. elsif(-r "$docsroot/$man" ||
  40. -r "$docsroot/libcurl/$man" ||
  41. -r "$docsroot/libcurl/opts/$man") {
  42. $manp{$man}=1;
  43. return 1;
  44. }
  45. return 0;
  46. }
  47. sub file {
  48. my ($f) = @_;
  49. open(F, "<$f") ||
  50. die "no file";
  51. my $line = 1;
  52. while(<F>) {
  53. chomp;
  54. my $l = $_;
  55. while($l =~ s/\\f(.)([^ ]*)\\f(.)//) {
  56. my ($pre, $str, $post)=($1, $2, $3);
  57. if($post ne "P") {
  58. print STDERR "error: $f:$line: missing \\fP after $str\n";
  59. $errors++;
  60. }
  61. if($str =~ /((libcurl|curl)([^ ]*))\(3\)/i) {
  62. my $man = "$1.3";
  63. if(!manpresent($man)) {
  64. print STDERR "error: $f:$line: refering to non-existing man page $man\n";
  65. $errors++;
  66. }
  67. if($pre ne "I") {
  68. print STDERR "error: $f:$line: use \\fI before $str\n";
  69. $errors++;
  70. }
  71. }
  72. }
  73. if($l =~ /(curl([^ ]*)\(3\))/i) {
  74. print STDERR "error: $f:$line: non-referencing $1\n";
  75. $errors++;
  76. }
  77. if($l =~ /^\.BR (.*)/) {
  78. my $i= $1;
  79. while($i =~ s/((lib|)curl([^ ]*)) *\"\(3\)(,|) *\" *//i ) {
  80. my $man = "$1.3";
  81. if(!manpresent($man)) {
  82. print STDERR "error: $f:$line: refering to non-existing man page $man\n";
  83. $errors++;
  84. }
  85. }
  86. }
  87. $line++;
  88. }
  89. close(F);
  90. }
  91. foreach my $f (@f) {
  92. file($f);
  93. }
  94. exit $errors?1:0;