blob: 161721ffa11c39c9d17eea18582bdeaeef21221e [file] [log] [blame]
xf.li6c8fc1e2023-08-12 00:11:09 -07001#!/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
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($post ne "P") {
68 print "error: $f:$line: missing \\fP after $str\n";
69 $errors++;
70 }
71 if($str =~ /((libcurl|curl)([^ ]*))\(3\)/i) {
72 my $man = "$1.3";
73 if(!manpresent($man)) {
74 print "error: $f:$line: referring to non-existing man page $man\n";
75 $errors++;
76 }
77 if($pre ne "I") {
78 print "error: $f:$line: use \\fI before $str\n";
79 $errors++;
80 }
81 }
82 }
83 if($l =~ /(curl([^ ]*)\(3\))/i) {
84 print "error: $f:$line: non-referencing $1\n";
85 $errors++;
86 }
87 if($l =~ /^\.BR (.*)/) {
88 my $i= $1;
89 while($i =~ s/((lib|)curl([^ ]*)) *\"\(3\)(,|) *\" *//i ) {
90 my $man = "$1.3";
91 if(!manpresent($man)) {
92 print "error: $f:$line: referring to non-existing man page $man\n";
93 $errors++;
94 }
95 }
96 }
97 $line++;
98 }
99 close(F);
100}
101
102foreach my $f (@f) {
103 file($f);
104}
105
106print "OK\n" if(!$errors);
107
108exit $errors?1:0;