Annotation of embedaddon/curl/tests/badsymbols.pl, revision 1.1

1.1     ! misho       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: 
        !            28: use strict;
        !            29: use warnings;
        !            30: use vars qw($Cpreprocessor);
        !            31: 
        !            32: #
        !            33: # configurehelp perl module is generated by configure script
        !            34: #
        !            35: my $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.
        !            44: if (!$rc) {
        !            45:     $Cpreprocessor = 'cpp';
        !            46: }
        !            47: 
        !            48: # we may get the dir root pointed out
        !            49: my $root=$ARGV[0] || ".";
        !            50: 
        !            51: # need an include directory when building out-of-tree
        !            52: my $i = ($ARGV[1]) ? "-I$ARGV[1] " : '';
        !            53: 
        !            54: my $incdir = "$root/include/curl";
        !            55: 
        !            56: my $verbose=0;
        !            57: my $summary=0;
        !            58: my $misses=0;
        !            59: 
        !            60: my @syms;
        !            61: my %doc;
        !            62: my %rem;
        !            63: 
        !            64: sub 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:         }
        !            81:         if($skipit) {
        !            82:             next;
        !            83:         }
        !            84:         if ( /enum\s+(\S+\s+)?{/ .. /}/ ) {
        !            85:             s/^\s+//;
        !            86:             chomp;
        !            87:             s/[,\s].*//;
        !            88:             if(($_ !~ /\}(;|)/) &&
        !            89:                ($_ ne "typedef") &&
        !            90:                ($_ ne "enum") &&
        !            91:                ($_ !~ /^[ \t]*$/) &&
        !            92:                ($_ ne "#")) {
        !            93:                 push @syms, $_;
        !            94:             }
        !            95:         }
        !            96:     }
        !            97:     close H_IN || die "Error preprocessing $file";
        !            98: }
        !            99: 
        !           100: sub 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: 
        !           113: opendir(my $dh, $incdir) || die "Can't opendir: $!";
        !           114: my @hfiles = grep { /\.h$/ } readdir($dh);
        !           115: closedir $dh;
        !           116: 
        !           117: for(@hfiles) {
        !           118:     scanheader("$incdir/$_");
        !           119: }
        !           120: 
        !           121: my $errors = 0;
        !           122: for 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: }
        !           129: if($errors) {
        !           130:     exit 1;
        !           131: }
        !           132: printf "%d fine symbols found\n", scalar(@syms);

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>