Correct slight logic error in processing IF in build.info
[openssl.git] / util / mkerr.pl
index 96c705e16bf3a8ec41ca1bc810c4d273bf4bf0c2..4fd5520d87cb851746e76a9bf534f44ebf49d958 100644 (file)
@@ -3,6 +3,7 @@
 my $config = "crypto/err/openssl.ec";
 my $hprefix = "openssl/";
 my $debug = 0;
+my $unref = 0;
 my $rebuild = 0;
 my $static = 1;
 my $recurse = 0;
@@ -26,6 +27,7 @@ while (@ARGV) {
                $hprefix = shift @ARGV;
        } elsif($arg eq "-debug") {
                $debug = 1;
+               $unref = 1;
                shift @ARGV;
        } elsif($arg eq "-rebuild") {
                $rebuild = 1;
@@ -42,6 +44,9 @@ while (@ARGV) {
        } elsif($arg eq "-staticloader") {
                $staticloader = "static ";
                shift @ARGV;
+       } elsif($arg eq "-unref") {
+               $unref = 1;
+               shift @ARGV;
        } elsif($arg eq "-write") {
                $dowrite = 1;
                shift @ARGV;
@@ -89,7 +94,7 @@ Options:
                   void ERR_load_<LIB>_strings(void);
                   void ERR_unload_<LIB>_strings(void);
                   void ERR_<LIB>_error(int f, int r, char *fn, int ln);
-                  #define <LIB>err(f,r) ERR_<LIB>_error(f,r,__FILE__,__LINE__)
+                  #define <LIB>err(f,r) ERR_<LIB>_error(f,r,OPENSSL_FILE,OPENSSL_LINE)
                 while the code facilitates the use of these in an environment
                 where the error support routines are dynamically loaded at 
                 runtime.
@@ -98,6 +103,8 @@ Options:
   -staticloader Prefix generated functions with the 'static' scope modifier.
                 Default: don't write any scope modifier prefix.
 
+  -unref        Print out unreferenced function and reason codes.
+
   -write        Actually (over)write the generated code to the header and C 
                 source files as assigned to each library through the config 
                 file.
@@ -116,7 +123,7 @@ EOF
 }
 
 if($recurse) {
-       @source = ( <crypto/*.c>, <crypto/*/*.c>, <ssl/*.c> )
+       @source = ( <crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, <ssl/*/*.c> )
 } else {
        @source = @ARGV;
 }
@@ -328,9 +335,18 @@ foreach $file (@source) {
        next if exists $cskip{$file};
        print STDERR "File loaded: ".$file."\r" if $debug;
        open(IN, "<$file") || die "Can't open source file $file\n";
+       my $func;
+       my $linenr = 0;
        while(<IN>) {
                # skip obsoleted source files entirely!
                last if(/^#error\s+obsolete/);
+               $linenr++;
+               if (!/;$/ && /^\**([a-zA-Z_].*[\s*])?([A-Za-z_0-9]+)\(.*([),]|$)/)
+                       {
+                       /^([^()]*(\([^()]*\)[^()]*)*)\(/;
+                       $1 =~ /([A-Za-z_0-9]*)$/;
+                       $func = $1;
+                       }
 
                if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
                        next unless exists $csrc{$2};
@@ -340,7 +356,11 @@ foreach $file (@source) {
                                $fcodes{$1} = "X";
                                $fnew{$2}++;
                        }
-                       $notrans{$1} = 1 unless exists $ftrans{$3};
+                       $ftrans{$3} = $func unless exists $ftrans{$3};
+            if (uc $func ne $3) {
+                print STDERR "ERROR: mismatch $file:$linenr $func:$3\n";
+                $errcount++;
+            }
                        print STDERR "Function: $1\t= $fcodes{$1} (lib: $2, name: $3)\n" if $debug; 
                }
                if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
@@ -364,7 +384,6 @@ foreach $lib (keys %csrc)
        my $hfile = $hinc{$lib};
        my $cfile = $csrc{$lib};
        if(!$fnew{$lib} && !$rnew{$lib}) {
-               print STDERR "$lib:\t\tNo new error codes\n";
                next unless $rebuild;
        } else {
                print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
@@ -474,7 +493,7 @@ EOF
 ${staticloader}void ERR_load_${lib}_strings(void);
 ${staticloader}void ERR_unload_${lib}_strings(void);
 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
-# define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
+# define ${lib}err(f,r) ERR_${lib}_error((f),(r),OPENSSL_FILE,OPENSSL_LINE)
 
 EOF
        }
@@ -535,14 +554,21 @@ EOF
        # First, read any existing reason string definitions:
        my %err_reason_strings;
        if (open(IN,"<$cfile")) {
+               my $line = "";
                while (<IN>) {
-                       if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
-                               $err_reason_strings{$1} = $2;
-                       }
-                       if (/\b${lib}_F_(\w*)\b.*\"(.*)\"/) {
-                               if (!exists $ftrans{$1} && ($1 ne $2)) {
-                                       print STDERR "WARNING: Mismatched function string $2\n";
-                                       $ftrans{$1} = $2;
+                       s|\R$||; # Better chomp
+                       $_ = $line . $_;
+                       $line = "";
+                       if (/{ERR_(FUNC|REASON)\(/) {
+                               if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
+                                       $err_reason_strings{$1} = $2;
+                               } elsif (/\b${lib}_F_(\w*)\b.*\"(.*)\"/) {
+                                       if (!exists $ftrans{$1} && ($1 ne $2)) {
+                                               print STDERR "WARNING: Mismatched function string $2\n";
+                                               $ftrans{$1} = $2;
+                                       }
+                               } else {
+                                       $line = $_;
                                }
                        }
                }
@@ -576,7 +602,6 @@ EOF
        open (OUT,">$cfile") || die "Can't open $cfile for writing";
 
        print OUT <<"EOF";
-/* $cfile */
 /* ====================================================================
  * Copyright (c) 1999-$year The OpenSSL Project.  All rights reserved.
  *
@@ -788,7 +813,7 @@ foreach (keys %rcodes) {
        push (@runref, $_) unless exists $urcodes{$_};
 }
 
-if($debug && @funref) {
+if($unref && @funref) {
        print STDERR "The following function codes were not referenced:\n";
        foreach(sort @funref)
        {
@@ -796,7 +821,7 @@ if($debug && @funref) {
        }
 }
 
-if($debug && @runref) {
+if($unref && @runref) {
        print STDERR "The following reason codes were not referenced:\n";
        foreach(sort @runref)
        {