Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/test1167.pl
2066 views
1
#!/usr/bin/env perl
2
#***************************************************************************
3
# _ _ ____ _
4
# Project ___| | | | _ \| |
5
# / __| | | | |_) | |
6
# | (__| |_| | _ <| |___
7
# \___|\___/|_| \_\_____|
8
#
9
# Copyright (C) Daniel Stenberg, <[email protected]>, 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
# This script grew out of help from Przemyslaw Iskra and Balint Szilakszi
27
# a late evening in the #curl IRC channel.
28
#
29
30
use strict;
31
use warnings;
32
use vars qw($Cpreprocessor);
33
34
#
35
# configurehelp perl module is generated by configure script
36
#
37
my $rc = eval {
38
require configurehelp;
39
configurehelp->import(qw(
40
$Cpreprocessor
41
));
42
1;
43
};
44
# Set default values if configure has not generated a configurehelp.pm file.
45
# This is the case with cmake.
46
if (!$rc) {
47
$Cpreprocessor = 'cpp';
48
}
49
50
my $verbose=0;
51
52
# verbose mode when -v is the first argument
53
if($ARGV[0] eq "-v") {
54
$verbose=1;
55
shift;
56
}
57
58
# we may get the dir root pointed out
59
my $root=$ARGV[0] || ".";
60
61
# need an include directory when building out-of-tree
62
my $i = ($ARGV[1]) ? "-I$ARGV[1] " : '';
63
64
my $incdir = "$root/include/curl";
65
66
my $summary=0;
67
my $misses=0;
68
69
my @syms;
70
71
sub scanenums {
72
my ($file)=@_;
73
my $skipit = 0;
74
75
open H_IN, "-|", "$Cpreprocessor -DCURL_DISABLE_DEPRECATION $i$file" ||
76
die "Cannot preprocess $file";
77
while ( <H_IN> ) {
78
my ($line, $linenum) = ($_, $.);
79
if( /^#(line|) (\d+) \"(.*)\"/) {
80
# if the included file isn't in our incdir, then we skip this section
81
# until next #line
82
#
83
if($3 !~ /^$incdir/) {
84
$skipit = 1;
85
next;
86
}
87
# parse this!
88
$skipit = 0;
89
next;
90
}
91
if($skipit) {
92
next;
93
}
94
if (/^#/) {
95
next;
96
}
97
if ( /enum\s+(\S+\s+)?{/ .. /}/ ) {
98
s/^\s+//;
99
chomp;
100
s/[,\s].*//;
101
if(($_ !~ /\}(;|)/) &&
102
($_ ne "typedef") &&
103
($_ ne "enum") &&
104
($_ ne "=") &&
105
($_ !~ /^\d+$/) &&
106
($_ !~ /^[ \t]*$/)) {
107
if($verbose) {
108
print "Source: $Cpreprocessor $i$file\n";
109
print "Symbol: $_\n";
110
print "Line #$linenum: $line\n\n";
111
}
112
push @syms, $_;
113
}
114
}
115
}
116
close H_IN || die "Error preprocessing $file";
117
}
118
119
sub scanheader {
120
my ($f)=@_;
121
scanenums($f);
122
open H, "<$f";
123
while(<H>) {
124
my ($line, $linenum) = ($_, $.);
125
if (/^ *# *define +([^ \n]*)/) {
126
if($verbose) {
127
print "Source: $f\n";
128
print "Symbol: $1\n";
129
print "Line #$linenum: $line\n\n";
130
}
131
push @syms, $1;
132
}
133
}
134
close H;
135
}
136
137
138
opendir(my $dh, $incdir) || die "Can't opendir $incdir: $!";
139
my @hfiles = grep { /\.h$/ } readdir($dh);
140
closedir $dh;
141
142
for(@hfiles) {
143
scanheader("$incdir/$_");
144
}
145
146
my $errors = 0;
147
for my $s (@syms) {
148
if($s !~ /^(lib|)curl/i) {
149
print "Bad symbols in public header files:\n" if(!$errors);
150
$errors++;
151
print " $s\n";
152
}
153
}
154
if($errors) {
155
exit 1;
156
}
157
printf "%d fine symbols found\n", scalar(@syms);
158
159