More method functions for EC_GFp_simple_method.
[openssl.git] / util / mkerr.pl
index ccf766b9a04156bcc66bb9dc66ad3473ff75a96e..b744c81d6b970a359b0012808420a102cf7dae77 100644 (file)
@@ -38,7 +38,7 @@ while (@ARGV) {
 }
 
 if($recurse) {
-       @source = (<crypto/*.c>, <crypto/*/*.c>, ,<rsaref/*.c>, <ssl/*.c>);
+       @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>);
 } else {
        @source = @ARGV;
 }
@@ -66,7 +66,6 @@ while(<IN>)
        } elsif (/^R\s+(\S+)\s+(\S+)/) {
                $rextra{$1} = $2;
                $rcodes{$1} = $2;
-       # Add extra reason with $1, value $2
        }
 }
 
@@ -80,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";
-       my $line = "", $def= "";
+       my $line = "", $def= "", $linenr = 0;
        while(<IN>) {
+           $linenr++;
+           print STDERR "line: $linenr\r" if $debug;
+
            last if(/BEGIN\s+ERROR\s+CODES/);
            if ($line ne '') {
                $_ = $line . $_;
@@ -111,28 +113,39 @@ while (($lib, $hdr) = each %hinc)
            }
        }
 
+       print STDERR "                                  \r" if $debug;
+        $defnr = 0;
        foreach (split /;/, $def) {
+           $defnr++;
+           print STDERR "def: $defnr\r" if $debug;
+
            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;
-               next if(/typedef\W/);
                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";
            }
        }
 
+       print STDERR "                                  \r" if $debug;
+
        next if $reindex;
 
        # Scan function and reason codes and store them: keep a note of the
@@ -275,14 +288,30 @@ EOF
 }
 #endif
 #endif
-
 EOF
        close OUT;
 
        # 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";
 
@@ -343,15 +372,16 @@ EOF
  */
 
 /* 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 <openssl/$hincf>
+#include $hincf
 
 /* BEGIN ERROR CODES */
-#ifndef NO_ERR
+#ifndef OPENSSL_NO_ERR
 static ERR_STRING_DATA ${lib}_str_functs[]=
        {
 EOF
@@ -376,9 +406,13 @@ EOF
        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";
@@ -397,7 +431,7 @@ void ERR_load_${lib}_strings(void)
        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
@@ -433,7 +467,7 @@ void ERR_load_${lib}_strings(void)
        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
@@ -441,7 +475,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);
-#endif;
+#endif
                }
        }
 
@@ -456,7 +490,7 @@ EOF
 }
 
        close OUT;
-
+       undef %err_reason_strings;
 }
 
 if($debug && defined(%notrans)) {