test1140.pl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 manpages to find basic syntactic problems such as unbalanced \f
  27. # codes or references to non-existing curl manpages.
  28. my $docsroot = $ARGV[0];
  29. if(!$docsroot || ($docsroot eq "-g")) {
  30. print "Usage: test1140.pl <docs root dir> [manpages]\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 "test1140.pl could not open $f";
  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. $man =~ s/\\//g; # cut off backslashes
  70. if(!manpresent($man)) {
  71. print "error: $f:$line: referring to non-existing manpage $man\n";
  72. $errors++;
  73. }
  74. if($pre ne "I") {
  75. print "error: $f:$line: use \\fI before $str\n";
  76. $errors++;
  77. }
  78. }
  79. }
  80. if($l =~ /(curl([^ ]*)\(3\))/i) {
  81. print "error: $f:$line: non-referencing $1\n";
  82. $errors++;
  83. }
  84. if($l =~ /^\.BR (.*)/) {
  85. my $i= $1;
  86. while($i =~ s/((lib|)curl([^ ]*)) *\"\(3\)(,|) *\" *//i ) {
  87. my $man = "$1.3";
  88. $man =~ s/\\//g; # cut off backslashes
  89. if(!manpresent($man)) {
  90. print "error: $f:$line: referring to non-existing manpage $man\n";
  91. $errors++;
  92. }
  93. }
  94. }
  95. $line++;
  96. }
  97. close($fh);
  98. }
  99. foreach my $f (@f) {
  100. file($f);
  101. }
  102. print "OK\n" if(!$errors);
  103. exit $errors?1:0;