I had forgotten to change mkerr.pl to use the new macro system.
[openssl.git] / util / mkerr.pl
index 062619de50d9965cc178c58715a8bd7ac74c9a90..33b904f9ee1d3c680468c9a4a1208873210610c3 100644 (file)
@@ -3,9 +3,10 @@
 my $config = "crypto/err/openssl.ec";
 my $debug = 0;
 my $rebuild = 0;
 my $config = "crypto/err/openssl.ec";
 my $debug = 0;
 my $rebuild = 0;
-my $static = 0;
+my $static = 1;
 my $recurse = 0;
 my $reindex = 0;
 my $recurse = 0;
 my $reindex = 0;
+my $dowrite = 0;
 
 
 while (@ARGV) {
 
 
 while (@ARGV) {
@@ -25,8 +26,11 @@ while (@ARGV) {
        } elsif($arg eq "-reindex") {
                $reindex = 1;
                shift @ARGV;
        } elsif($arg eq "-reindex") {
                $reindex = 1;
                shift @ARGV;
-       } elsif($arg eq "-static") {
-               $static = 1;
+       } elsif($arg eq "-nostatic") {
+               $static = 0;
+               shift @ARGV;
+       } elsif($arg eq "-write") {
+               $dowrite = 1;
                shift @ARGV;
        } else {
                last;
                shift @ARGV;
        } else {
                last;
@@ -34,7 +38,7 @@ while (@ARGV) {
 }
 
 if($recurse) {
 }
 
 if($recurse) {
-       @source = (<crypto/*.c>, <crypto/*/*.c>, ,<rsaref/*.c>, <ssl/*.c>);
+       @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>);
 } else {
        @source = @ARGV;
 }
 } else {
        @source = @ARGV;
 }
@@ -62,7 +66,6 @@ while(<IN>)
        } elsif (/^R\s+(\S+)\s+(\S+)/) {
                $rextra{$1} = $2;
                $rcodes{$1} = $2;
        } elsif (/^R\s+(\S+)\s+(\S+)/) {
                $rextra{$1} = $2;
                $rcodes{$1} = $2;
-       # Add extra reason with $1, value $2
        }
 }
 
        }
 }
 
@@ -76,8 +79,11 @@ while (($lib, $hdr) = each %hinc)
        next if($hdr eq "NONE");
        print STDERR "Scanning header file $hdr\n" if $debug; 
        open(IN, "<$hdr") || die "Can't open Header file $hdr\n";
        next if($hdr eq "NONE");
        print STDERR "Scanning header file $hdr\n" if $debug; 
        open(IN, "<$hdr") || die "Can't open Header file $hdr\n";
-       my $line = "", $def= "";
+       my $line = "", $def= "", $linenr = 0;
        while(<IN>) {
        while(<IN>) {
+           $linenr++;
+           print STDERR "line: $linenr\r" if $debug;
+
            last if(/BEGIN\s+ERROR\s+CODES/);
            if ($line ne '') {
                $_ = $line . $_;
            last if(/BEGIN\s+ERROR\s+CODES/);
            if ($line ne '') {
                $_ = $line . $_;
@@ -107,28 +113,39 @@ while (($lib, $hdr) = each %hinc)
            }
        }
 
            }
        }
 
+       print STDERR "                                  \r" if $debug;
+        $defnr = 0;
        foreach (split /;/, $def) {
        foreach (split /;/, $def) {
+           $defnr++;
+           print STDERR "def: $defnr\r" if $debug;
+
            s/^[\n\s]*//g;
            s/[\n\s]*$//g;
            s/^[\n\s]*//g;
            s/[\n\s]*$//g;
-           next if (/\w+\W+(\w+)\W*\(\s*\)$/s); # K&R C
-           next if (/\(\*(\w*)\([^\)]+/);
-           if (/\w+\W+\w+\W*\(.*\)$/s) {
+           next if(/typedef\W/);
+           if (/\(\*(\w*)\([^\)]+/) {
+               my $name = $1;
+               $name =~ tr/[a-z]/[A-Z]/;
+               $ftrans{$name} = $1;
+           } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s){
+               # K&R C
+               next ;
+           } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
                while (not /\(\)$/s) {
                    s/[^\(\)]*\)$/\)/s;
                    s/\([^\(\)]*\)\)$/\)/s;
                }
                s/\(void\)//;
                /(\w+)\W*\(\)/s;
                while (not /\(\)$/s) {
                    s/[^\(\)]*\)$/\)/s;
                    s/\([^\(\)]*\)\)$/\)/s;
                }
                s/\(void\)//;
                /(\w+)\W*\(\)/s;
-               next if(/typedef\W/);
                my $name = $1;
                $name =~ tr/[a-z]/[A-Z]/;
                $ftrans{$name} = $1;
                my $name = $1;
                $name =~ tr/[a-z]/[A-Z]/;
                $ftrans{$name} = $1;
-               
            } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
                print STDERR "Header $hdr: cannot parse: $_;\n";
            }
        }
 
            } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
                print STDERR "Header $hdr: cannot parse: $_;\n";
            }
        }
 
+       print STDERR "                                  \r" if $debug;
+
        next if $reindex;
 
        # Scan function and reason codes and store them: keep a note of the
        next if $reindex;
 
        # Scan function and reason codes and store them: keep a note of the
@@ -167,6 +184,8 @@ while (($lib, $hdr) = each %hinc)
 # oddly named structure BIO_F_CTX which needs to be ignored.
 # If a code doesn't exist in list compiled from headers then mark it
 # with the value "X" as a place holder to give it a value later.
 # oddly named structure BIO_F_CTX which needs to be ignored.
 # If a code doesn't exist in list compiled from headers then mark it
 # with the value "X" as a place holder to give it a value later.
+# Store all function and reason codes found in %ufcodes and %urcodes
+# so all those unreferenced can be printed out.
 
 
 foreach $file (@source) {
 
 
 foreach $file (@source) {
@@ -174,16 +193,19 @@ foreach $file (@source) {
        next if exists $cskip{$file};
        open(IN, "<$file") || die "Can't open source file $file\n";
        while(<IN>) {
        next if exists $cskip{$file};
        open(IN, "<$file") || die "Can't open source file $file\n";
        while(<IN>) {
-               if(/(([A-Z0-9]+)_F_[A-Z0-9_]+)/) {
+               if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
                        next unless exists $csrc{$2};
                        next if($1 eq "BIO_F_BUFFER_CTX");
                        next unless exists $csrc{$2};
                        next if($1 eq "BIO_F_BUFFER_CTX");
+                       $ufcodes{$1} = 1;
                        if(!exists $fcodes{$1}) {
                                $fcodes{$1} = "X";
                                $fnew{$2}++;
                        }
                        if(!exists $fcodes{$1}) {
                                $fcodes{$1} = "X";
                                $fnew{$2}++;
                        }
+                       $notrans{$1} = 1 unless exists $ftrans{$3};
                }
                if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
                        next unless exists $csrc{$2};
                }
                if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
                        next unless exists $csrc{$2};
+                       $urcodes{$1} = 1;
                        if(!exists $rcodes{$1}) {
                                $rcodes{$1} = "X";
                                $rnew{$2}++;
                        if(!exists $rcodes{$1}) {
                                $rcodes{$1} = "X";
                                $rnew{$2}++;
@@ -205,7 +227,7 @@ foreach $lib (keys %csrc)
        } else {
                print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
                print STDERR " $rnew{$lib} New Reasons.\n";
        } else {
                print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
                print STDERR " $rnew{$lib} New Reasons.\n";
-
+               next unless $dowrite;
        }
 
        # If we get here then we have some new error codes so we
        }
 
        # If we get here then we have some new error codes so we
@@ -272,8 +294,25 @@ EOF
 
        # Rewrite the C source file containing the error details.
 
 
        # Rewrite the C source file containing the error details.
 
-       $hfile =~ /([^\/]+)$/;
-       my $hincf = $1;
+       # First, read any existing reason string definitions:
+       my %err_reason_strings;
+       if (open(IN,"<$cfile")) {
+               while (<IN>) {
+                       if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
+                               $err_reason_strings{$1} = $2;
+                       }
+               }
+               close(IN);
+       }
+
+       my $hincf;
+       if($static) {
+               $hfile =~ /([^\/]+)$/;
+               $hincf = "<openssl/$1>";
+       } else {
+               $hincf = "\"$hfile\"";
+       }
+
 
        open (OUT,">$cfile") || die "Can't open $cfile for writing";
 
 
        open (OUT,">$cfile") || die "Can't open $cfile for writing";
 
@@ -334,15 +373,16 @@ EOF
  */
 
 /* NOTE: this file was auto generated by the mkerr.pl script: any changes
  */
 
 /* NOTE: this file was auto generated by the mkerr.pl script: any changes
- * made to it will be overwritten when the script next updates this file.
+ * made to it will be overwritten when the script next updates this file,
+ * only reason strings will be preserved.
  */
 
 #include <stdio.h>
 #include <openssl/err.h>
  */
 
 #include <stdio.h>
 #include <openssl/err.h>
-#include <openssl/$hincf>
+#include $hincf
 
 /* BEGIN ERROR CODES */
 
 /* BEGIN ERROR CODES */
-#ifndef NO_ERR
+#ifndef OPENSSL_NO_ERR
 static ERR_STRING_DATA ${lib}_str_functs[]=
        {
 EOF
 static ERR_STRING_DATA ${lib}_str_functs[]=
        {
 EOF
@@ -353,8 +393,6 @@ EOF
                $fn = $1;
                if(exists $ftrans{$fn}) {
                        $fn = $ftrans{$fn};
                $fn = $1;
                if(exists $ftrans{$fn}) {
                        $fn = $ftrans{$fn};
-               } else {
-                       push @notrans, $i;
                }
                print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
        }
                }
                print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
        }
@@ -369,9 +407,13 @@ EOF
        foreach $i (@reasons) {
                my $rn;
                my $nspc = 0;
        foreach $i (@reasons) {
                my $rn;
                my $nspc = 0;
-               $i =~ /^${lib}_R_(\S+)$/;
-               $rn = $1;
-               $rn =~ tr/_[A-Z]/ [a-z]/;
+               if (exists $err_reason_strings{$i}) {
+                       $rn = $err_reason_strings{$i};
+               } else {
+                       $i =~ /^${lib}_R_(\S+)$/;
+                       $rn = $1;
+                       $rn =~ tr/_[A-Z]/ [a-z]/;
+               }
                $nspc = 40 - length($i) unless length($i) > 40;
                $nspc = " " x $nspc;
                print OUT "{${i}${nspc},\"$rn\"},\n";
                $nspc = 40 - length($i) unless length($i) > 40;
                $nspc = " " x $nspc;
                print OUT "{${i}${nspc},\"$rn\"},\n";
@@ -390,7 +432,7 @@ void ERR_load_${lib}_strings(void)
        if (init)
                {
                init=0;
        if (init)
                {
                init=0;
-#ifndef NO_ERR
+#ifndef OPENSSL_NO_ERR
                ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
                ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
 #endif
                ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
                ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
 #endif
@@ -426,7 +468,7 @@ void ERR_load_${lib}_strings(void)
        if (init)
                {
                init=0;
        if (init)
                {
                init=0;
-#ifndef NO_ERR
+#ifndef OPENSSL_NO_ERR
                ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
                ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
 #endif
                ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
                ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
 #endif
@@ -434,7 +476,7 @@ void ERR_load_${lib}_strings(void)
 #ifdef ${lib}_LIB_NAME
                ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
                ERR_load_strings(0,${lib}_lib_name);
 #ifdef ${lib}_LIB_NAME
                ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
                ERR_load_strings(0,${lib}_lib_name);
-#endif;
+#endif
                }
        }
 
                }
        }
 
@@ -449,12 +491,38 @@ EOF
 }
 
        close OUT;
 }
 
        close OUT;
-
+       undef %err_reason_strings;
 }
 
 }
 
-if($debug && defined(@notrans)) {
+if($debug && defined(%notrans)) {
        print STDERR "The following function codes were not translated:\n";
        print STDERR "The following function codes were not translated:\n";
-       foreach(@notrans)
+       foreach(sort keys %notrans)
+       {
+               print STDERR "$_\n";
+       }
+}
+
+# Make a list of unreferenced function and reason codes
+
+foreach (keys %fcodes) {
+       push (@funref, $_) unless exists $ufcodes{$_};
+}
+
+foreach (keys %rcodes) {
+       push (@runref, $_) unless exists $urcodes{$_};
+}
+
+if($debug && defined(@funref) ) {
+       print STDERR "The following function codes were not referenced:\n";
+       foreach(sort @funref)
+       {
+               print STDERR "$_\n";
+       }
+}
+
+if($debug && defined(@runref) ) {
+       print STDERR "The following reason codes were not referenced:\n";
+       foreach(sort @runref)
        {
                print STDERR "$_\n";
        }
        {
                print STDERR "$_\n";
        }