- print STDERR "\n";
- foreach my $lib ( sort keys %fmax ) {
- print STDERR "Function codes for ${lib}:\n";
- if ( $fassigned{$lib} =~ m/^:(.*):$/ ) {
- my @fassigned = sort { $a <=> $b } split( ":", $1 );
- print STDERR " ", join(' ', @fassigned), "\n";
- } else {
- print STDERR " --none--\n";
- }
- }
- }
-}
-
-# Scan each header file and make a list of error codes
-# and function names
-&phase("Scanning headers");
-while ( ( my $hdr, my $lib ) = each %libinc ) {
- next if $hdr eq "NONE";
- print STDERR " ." if $debug;
- my $line = "";
- my $def = "";
- my $linenr = 0;
- my $cpp = 0;
-
- open(IN, "<$hdr")
- || open(IN, "<$hdr.in")
- || die "Can't open $hdr or $hdr.in, $!,";
- while ( <IN> ) {
- $linenr++;
-
- if ( $line ne '' ) {
- $_ = $line . $_;
- $line = '';
- }
-
- if ( /\\$/ ) {
- $line = $_;
- next;
- }
-
- if ( /\/\*/ ) {
- if ( not /\*\// ) { # multiline comment...
- $line = $_; # ... just accumulate
- next;
- } else {
- s/\/\*.*?\*\///gs; # wipe it
- }
- }
-
- if ( $cpp ) {
- $cpp++ if /^#\s*if/;
- $cpp-- if /^#\s*endif/;
- next;
- }
- $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
-
- next if /^\#/; # skip preprocessor directives
-
- s/{[^{}]*}//gs; # ignore {} blocks
-
- if ( /\{|\/\*/ ) { # Add a so editor works...
- $line = $_;
- } else {
- $def .= $_;
- }
- }
-
- # Delete any DECLARE_ macros
- my $defnr = 0;
- $def =~ s/DECLARE_\w+\([\w,\s]+\)//gs;
- foreach ( split /;/, $def ) {
- $defnr++;
- # The goal is to collect function names from function declarations.
-
- s/^[\n\s]*//g;
- s/[\n\s]*$//g;
-
- # Skip over recognized non-function declarations
- next if /typedef\W/;
-
- # Remove STACK_OF(foo)
- s/STACK_OF\(\w+\)/void/;
-
- # Reduce argument lists to empty ()
- # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
- while ( /\(.*\)/s ) {
- s/\([^\(\)]+\)/\{\}/gs;
- s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f
- }
-
- # pretend as we didn't use curly braces: {} -> ()
- s/\{\}/\(\)/gs;
-
- # Last token just before the first () is a function name.
- if ( /(\w+)\s*\(\).*/s ) {
- my $name = $1;
- $name =~ tr/[a-z]/[A-Z]/;
- $ftrans{$name} = $1;
- } elsif ( /[\(\)]/ and not(/=/) ) {
- print STDERR "Header $hdr: cannot parse: $_;\n";
- }
- }
-
- next if $reindex;
-
- if ( $lib eq "SSL" && $rmax{$lib} >= 1000 ) {
- print STDERR "SSL error codes 1000+ are reserved for alerts.\n";
- print STDERR "Any new alerts must be added to $config.\n";
- $errors++;