nroff-scan.pl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 2016 - 2022, 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(F, "<$f") ||
  52. die "no file";
  53. my $line = 1;
  54. while(<F>) {
  55. chomp;
  56. my $l = $_;
  57. while($l =~ s/\\f(.)([^ ]*)\\f(.)//) {
  58. my ($pre, $str, $post)=($1, $2, $3);
  59. if($post ne "P") {
  60. print "error: $f:$line: missing \\fP after $str\n";
  61. $errors++;
  62. }
  63. if($str =~ /((libcurl|curl)([^ ]*))\(3\)/i) {
  64. my $man = "$1.3";
  65. if(!manpresent($man)) {
  66. print "error: $f:$line: referring to non-existing man page $man\n";
  67. $errors++;
  68. }
  69. if($pre ne "I") {
  70. print "error: $f:$line: use \\fI before $str\n";
  71. $errors++;
  72. }
  73. }
  74. }
  75. if($l =~ /(curl([^ ]*)\(3\))/i) {
  76. print "error: $f:$line: non-referencing $1\n";
  77. $errors++;
  78. }
  79. if($l =~ /^\.BR (.*)/) {
  80. my $i= $1;
  81. while($i =~ s/((lib|)curl([^ ]*)) *\"\(3\)(,|) *\" *//i ) {
  82. my $man = "$1.3";
  83. if(!manpresent($man)) {
  84. print "error: $f:$line: referring to non-existing man page $man\n";
  85. $errors++;
  86. }
  87. }
  88. }
  89. $line++;
  90. }
  91. close(F);
  92. }
  93. foreach my $f (@f) {
  94. file($f);
  95. }
  96. print "OK\n" if(!$errors);
  97. exit $errors?1:0;