nroff-scan.pl 3.1 KB

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