1#!/usr/bin/env perl 2#*************************************************************************** 3# _ _ ____ _ 4# Project ___| | | | _ \| | 5# / __| | | | |_) | | 6# | (__| |_| | _ <| |___ 7# \___|\___/|_| \_\_____| 8# 9# Copyright (C) 2010-2020, 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.haxx.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########################################################################### 23# 24# This script grew out of help from Przemyslaw Iskra and Balint Szilakszi 25# a late evening in the #curl IRC channel on freenode. 26# 27 28use strict; 29use warnings; 30use vars qw($Cpreprocessor); 31 32# 33# configurehelp perl module is generated by configure script 34# 35my $rc = eval { 36 require configurehelp; 37 configurehelp->import(qw( 38 $Cpreprocessor 39 )); 40 1; 41}; 42# Set default values if configure has not generated a configurehelp.pm file. 43# This is the case with cmake. 44if (!$rc) { 45 $Cpreprocessor = 'cpp'; 46} 47 48# we may get the dir root pointed out 49my $root=$ARGV[0] || "."; 50 51# need an include directory when building out-of-tree 52my $i = ($ARGV[1]) ? "-I$ARGV[1] " : ''; 53 54my $incdir = "$root/include/curl"; 55 56my $verbose=0; 57my $summary=0; 58my $misses=0; 59 60my @syms; 61my %doc; 62my %rem; 63 64sub scanenums { 65 my ($file)=@_; 66 my $skipit = 0; 67 68 open H_IN, "-|", "$Cpreprocessor $i$file" || die "Cannot preprocess $file"; 69 while ( <H_IN> ) { 70 if( /^#(line|) (\d+) \"(.*)\"/) { 71 # if the included file isn't in our incdir, then we skip this section 72 # until next #line 73 # 74 if($3 !~ /^$incdir/) { 75 $skipit = 1; 76 next; 77 } 78 # parse this! 79 $skipit = 0; 80 next; 81 } 82 if($skipit) { 83 next; 84 } 85 if ( /enum\s+(\S+\s+)?{/ .. /}/ ) { 86 s/^\s+//; 87 chomp; 88 s/[,\s].*//; 89 if(($_ !~ /\}(;|)/) && 90 ($_ ne "typedef") && 91 ($_ ne "enum") && 92 ($_ !~ /^[ \t]*$/)) { 93 push @syms, $_; 94 } 95 } 96 } 97 close H_IN || die "Error preprocessing $file"; 98} 99 100sub scanheader { 101 my ($f)=@_; 102 scanenums($f); 103 open H, "<$f"; 104 while(<H>) { 105 if (/^#define +([^ \n]*)/) { 106 push @syms, $1; 107 } 108 } 109 close H; 110} 111 112 113opendir(my $dh, $incdir) || die "Can't opendir: $!"; 114my @hfiles = grep { /\.h$/ } readdir($dh); 115closedir $dh; 116 117for(@hfiles) { 118 scanheader("$incdir/$_"); 119} 120 121my $errors = 0; 122for my $s (@syms) { 123 if($s !~ /^(lib|)curl/i) { 124 print "Bad symbols in public header files:\n" if(!$errors); 125 $errors++; 126 print " $s\n"; 127 } 128} 129if($errors) { 130 exit 1; 131} 132printf "%d fine symbols found\n", scalar(@syms); 133