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