2023-12-04 17:50:42 +08:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#***************************************************************************
|
|
|
|
# _ _ ____ _
|
|
|
|
# Project ___| | | | _ \| |
|
|
|
|
# / __| | | | |_) | |
|
|
|
|
# | (__| |_| | _ <| |___
|
|
|
|
# \___|\___/|_| \_\_____|
|
|
|
|
#
|
|
|
|
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
|
|
#
|
|
|
|
# This software is licensed as described in the file COPYING, which
|
|
|
|
# you should have received as part of this distribution. The terms
|
|
|
|
# are also available at https://curl.se/docs/copyright.html.
|
|
|
|
#
|
|
|
|
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
# copies of the Software, and permit persons to whom the Software is
|
|
|
|
# furnished to do so, under the terms of the COPYING file.
|
|
|
|
#
|
|
|
|
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, either express or implied.
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: curl
|
|
|
|
#
|
|
|
|
###########################################################################
|
|
|
|
|
|
|
|
my @files = @ARGV;
|
|
|
|
my $cfile = "test.c";
|
|
|
|
my $check = "./scripts/checksrc.pl";
|
2023-12-24 05:45:53 +08:00
|
|
|
my $error;
|
2023-12-04 17:50:42 +08:00
|
|
|
|
|
|
|
if($files[0] eq "-h") {
|
|
|
|
print "Usage: verify-synopsis [man pages]\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub testcompile {
|
|
|
|
my $rc = system("gcc -c test.c -DCURL_DISABLE_TYPECHECK -DCURL_ALLOW_OLD_MULTI_SOCKET -DCURL_DISABLE_DEPRECATION -Wunused -Werror -Wno-unused-but-set-variable -I include") >> 8;
|
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub checksrc {
|
|
|
|
my $rc = system("$check test.c") >> 8;
|
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub extract {
|
|
|
|
my($f) = @_;
|
|
|
|
my $syn = 0;
|
|
|
|
my $l = 0;
|
|
|
|
my $iline = 0;
|
2023-12-24 05:45:53 +08:00
|
|
|
my $fail = 0;
|
|
|
|
open(F, "<$f") or die "failed opening input file $f : $!";
|
|
|
|
open(O, ">$cfile") or die "failed opening output file $cfile : $!";
|
2023-12-04 17:50:42 +08:00
|
|
|
print O "#include <curl/curl.h>\n";
|
|
|
|
while(<F>) {
|
|
|
|
$iline++;
|
|
|
|
if(/^.SH EXAMPLE/) {
|
|
|
|
$syn = 1
|
|
|
|
}
|
|
|
|
elsif($syn == 1) {
|
|
|
|
if(/^.nf/) {
|
|
|
|
$syn++;
|
|
|
|
print O "/* !checksrc! disable UNUSEDIGNORE all */\n";
|
|
|
|
print O "/* !checksrc! disable COPYRIGHT all */\n";
|
|
|
|
print O "/* !checksrc! disable FOPENMODE all */\n";
|
|
|
|
printf O "#line %d \"$f\"\n", $iline+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif($syn == 2) {
|
|
|
|
if(/^.fi/) {
|
|
|
|
last;
|
|
|
|
}
|
2023-12-24 05:45:53 +08:00
|
|
|
if(/(?<!\\)(?:\\{2})*\\(?!\\)/) {
|
|
|
|
print STDERR
|
|
|
|
"Error while processing file $f line $iline:\n$_" .
|
|
|
|
"Error: Single backslashes \\ are not properly shown in " .
|
|
|
|
"manpage EXAMPLE output unless they are escaped \\\\.\n";
|
|
|
|
$fail = 1;
|
|
|
|
$error = 1;
|
|
|
|
last;
|
|
|
|
}
|
2023-12-04 17:50:42 +08:00
|
|
|
# two backslashes become one
|
|
|
|
$_ =~ s/\\\\/\\/g;
|
|
|
|
print O $_;
|
|
|
|
$l++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(F);
|
|
|
|
close(O);
|
|
|
|
|
2023-12-24 05:45:53 +08:00
|
|
|
return ($fail ? 0 : $l);
|
2023-12-04 17:50:42 +08:00
|
|
|
}
|
|
|
|
|
2024-01-17 18:32:44 +08:00
|
|
|
my $count;
|
2023-12-04 17:50:42 +08:00
|
|
|
for my $m (@files) {
|
2024-01-17 18:32:44 +08:00
|
|
|
#print "Verify $m\n";
|
2023-12-04 17:50:42 +08:00
|
|
|
my $out = extract($m);
|
|
|
|
if($out) {
|
|
|
|
$error |= testcompile($m);
|
|
|
|
$error |= checksrc($m);
|
|
|
|
}
|
2024-01-17 18:32:44 +08:00
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
if(!$error) {
|
|
|
|
print "Verified $count man pages ok\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print "Detected problems\n";
|
2023-12-04 17:50:42 +08:00
|
|
|
}
|
|
|
|
exit $error;
|