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 29my $docsroot = $ARGV[0]; 30 31if(!$docsroot || ($docsroot eq "-g")) { 32 print "Usage: nroff-scan.pl <docs root dir> [nroff files]\n"; 33 exit; 34} 35 36 37shift @ARGV; 38 39my @f = @ARGV; 40 41my %manp; 42 43sub manpresent { 44 my ($man) = @_; 45 if($manp{$man}) { 46 return 1; 47 } 48 elsif(-r "$docsroot/$man" || 49 -r "$docsroot/libcurl/$man" || 50 -r "$docsroot/libcurl/opts/$man") { 51 $manp{$man}=1; 52 return 1; 53 } 54 return 0; 55} 56 57sub file { 58 my ($f) = @_; 59 open(F, "<$f") || 60 die "no file"; 61 my $line = 1; 62 while(<F>) { 63 chomp; 64 my $l = $_; 65 while($l =~ s/\\f(.)([^ ]*)\\f(.)//) { 66 my ($pre, $str, $post)=($1, $2, $3); 67 if($str =~ /^\\f[ib]/i) { 68 print "error: $f:$line: double-highlight\n"; 69 $errors++; 70 } 71 if($post ne "P") { 72 print "error: $f:$line: missing \\fP after $str\n"; 73 $errors++; 74 } 75 if($str =~ /((libcurl|curl)([^ ]*))\(3\)/i) { 76 my $man = "$1.3"; 77 if(!manpresent($man)) { 78 print "error: $f:$line: referring to non-existing man page $man\n"; 79 $errors++; 80 } 81 if($pre ne "I") { 82 print "error: $f:$line: use \\fI before $str\n"; 83 $errors++; 84 } 85 } 86 } 87 if($l =~ /(curl([^ ]*)\(3\))/i) { 88 print "error: $f:$line: non-referencing $1\n"; 89 $errors++; 90 } 91 if($l =~ /^\.BR (.*)/) { 92 my $i= $1; 93 while($i =~ s/((lib|)curl([^ ]*)) *\"\(3\)(,|) *\" *//i ) { 94 my $man = "$1.3"; 95 if(!manpresent($man)) { 96 print "error: $f:$line: referring to non-existing man page $man\n"; 97 $errors++; 98 } 99 } 100 } 101 $line++; 102 } 103 close(F); 104} 105 106foreach my $f (@f) { 107 file($f); 108} 109 110print "OK\n" if(!$errors); 111 112exit $errors?1:0; 113