test1167.pl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. #
  26. # This script grew out of help from Przemyslaw Iskra and Balint Szilakszi
  27. # a late evening in the #curl IRC channel.
  28. #
  29. use strict;
  30. use warnings;
  31. use vars qw($Cpreprocessor);
  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. my $verbose=0;
  48. # verbose mode when -v is the first argument
  49. if($ARGV[0] eq "-v") {
  50. $verbose=1;
  51. shift;
  52. }
  53. # we may get the dir root pointed out
  54. my $root=$ARGV[0] || ".";
  55. # need an include directory when building out-of-tree
  56. my $i = ($ARGV[1]) ? "-I$ARGV[1] " : '';
  57. my $incdir = "$root/include/curl";
  58. my $summary=0;
  59. my $misses=0;
  60. my @syms;
  61. my %doc;
  62. my %rem;
  63. sub scanenums {
  64. my ($file)=@_;
  65. my $skipit = 0;
  66. open H_IN, "-|", "$Cpreprocessor -DCURL_DISABLE_DEPRECATION $i$file" ||
  67. die "Cannot preprocess $file";
  68. while ( <H_IN> ) {
  69. my ($line, $linenum) = ($_, $.);
  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 (/^#/) {
  86. next;
  87. }
  88. if ( /enum\s+(\S+\s+)?{/ .. /}/ ) {
  89. s/^\s+//;
  90. chomp;
  91. s/[,\s].*//;
  92. if(($_ !~ /\}(;|)/) &&
  93. ($_ ne "typedef") &&
  94. ($_ ne "enum") &&
  95. ($_ ne "=") &&
  96. ($_ !~ /^\d+$/) &&
  97. ($_ !~ /^[ \t]*$/)) {
  98. if($verbose) {
  99. print "Source: $Cpreprocessor $i$file\n";
  100. print "Symbol: $_\n";
  101. print "Line #$linenum: $line\n\n";
  102. }
  103. push @syms, $_;
  104. }
  105. }
  106. }
  107. close H_IN || die "Error preprocessing $file";
  108. }
  109. sub scanheader {
  110. my ($f)=@_;
  111. scanenums($f);
  112. open H, "<$f";
  113. while(<H>) {
  114. my ($line, $linenum) = ($_, $.);
  115. if (/^#define +([^ \n]*)/) {
  116. if($verbose) {
  117. print "Source: $f\n";
  118. print "Symbol: $1\n";
  119. print "Line #$linenum: $line\n\n";
  120. }
  121. push @syms, $1;
  122. }
  123. }
  124. close H;
  125. }
  126. opendir(my $dh, $incdir) || die "Can't opendir $incdir: $!";
  127. my @hfiles = grep { /\.h$/ } readdir($dh);
  128. closedir $dh;
  129. for(@hfiles) {
  130. scanheader("$incdir/$_");
  131. }
  132. my $errors = 0;
  133. for my $s (@syms) {
  134. if($s !~ /^(lib|)curl/i) {
  135. print "Bad symbols in public header files:\n" if(!$errors);
  136. $errors++;
  137. print " $s\n";
  138. }
  139. }
  140. if($errors) {
  141. exit 1;
  142. }
  143. printf "%d fine symbols found\n", scalar(@syms);