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 26my @files = @ARGV; 27my $cfile = "test.c"; 28 29if($files[0] eq "-h") { 30 print "Usage: verify-synopsis [man pages]\n"; 31 exit; 32} 33 34sub testcompile { 35 my $rc = system("gcc -c test.c -DCURL_DISABLE_TYPECHECK -DCURL_ALLOW_OLD_MULTI_SOCKET -I include") >> 8; 36 return $rc; 37} 38 39 40sub extract { 41 my($f) = @_; 42 my $syn = 0; 43 my $l = 0; 44 my $iline = 0; 45 open(F, "<$f"); 46 open(O, ">$cfile"); 47 while(<F>) { 48 $iline++; 49 if(/^# SYNOPSIS/) { 50 $syn = 1 51 } 52 elsif($syn == 1) { 53 if(/^\~\~\~/) { 54 $syn++; 55 print O "#line $iline \"$f\"\n"; 56 } 57 } 58 elsif($syn == 2) { 59 if(/^\~\~\~/) { 60 last; 61 } 62 # turn the vararg argument into vararg 63 $_ =~ s/, parameter\)\;/, ...);/; 64 print O $_; 65 $l++; 66 } 67 } 68 close(F); 69 close(O); 70 71 if($syn < 2) { 72 print STDERR "Found no synopsis in $f\n"; 73 return 1; 74 } 75 76 return 0; 77} 78 79my $error; 80for my $m (@files) { 81 $error |= extract($m); 82 $error |= testcompile($m); 83} 84exit $error; 85