my $docsroot = $ARGV[0];
if(!$docsroot || ($docsroot eq "-g")) {
print "Usage: test1140.pl <docs root dir> [manpages]\n";
exit;
}
shift @ARGV;
my @f = @ARGV;
my %manp;
sub manpresent {
my ($man) = @_;
if($manp{$man}) {
return 1;
}
elsif(-r "$docsroot/$man" ||
-r "$docsroot/libcurl/$man" ||
-r "$docsroot/libcurl/opts/$man") {
$manp{$man}=1;
return 1;
}
return 0;
}
sub file {
my ($f) = @_;
open(my $fh, "<", "$f") ||
die "test1140.pl could not open $f";
my $line = 1;
while(<$fh>) {
chomp;
my $l = $_;
while($l =~ s/\\f(.)([^ ]*)\\f(.)//) {
my ($pre, $str, $post)=($1, $2, $3);
if($str =~ /^\\f[ib]/i) {
print "error: $f:$line: double-highlight\n";
$errors++;
}
if($post ne "P") {
print "error: $f:$line: missing \\fP after $str\n";
$errors++;
}
if($str =~ /((libcurl|curl)([^ ]*))\(3\)/i) {
my $man = "$1.3";
$man =~ s/\\//g;
if(!manpresent($man)) {
print "error: $f:$line: referring to non-existing manpage $man\n";
$errors++;
}
if($pre ne "I") {
print "error: $f:$line: use \\fI before $str\n";
$errors++;
}
}
}
if($l =~ /(curl([^ ]*)\(3\))/i) {
print "error: $f:$line: non-referencing $1\n";
$errors++;
}
if($l =~ /^\.BR (.*)/) {
my $i= $1;
while($i =~ s/((lib|)curl([^ ]*)) *\"\(3\)(,|) *\" *//i ) {
my $man = "$1.3";
$man =~ s/\\//g;
if(!manpresent($man)) {
print "error: $f:$line: referring to non-existing manpage $man\n";
$errors++;
}
}
}
$line++;
}
close($fh);
}
foreach my $f (@f) {
file($f);
}
print "OK\n" if(!$errors);
exit $errors?1:0;