Update year.
[openssl.git] / util / mkerr.pl
index 399b10e1a338081e71fa8bdce2af0e8552fef18b..aac87bbf3b8f8186426edb654b9ffb9dcd44fa81 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/local/bin/perl -w
 
 my $config = "crypto/err/openssl.ec";
+my $hprefix = "openssl/";
 my $debug = 0;
 my $rebuild = 0;
 my $static = 1;
@@ -12,11 +13,16 @@ my $staticloader = "";
 my $pack_errcode;
 my $load_errcode;
 
+my $errcount;
+
 while (@ARGV) {
        my $arg = $ARGV[0];
        if($arg eq "-conf") {
                shift @ARGV;
                $config = shift @ARGV;
+       } elsif($arg eq "-hprefix") {
+               shift @ARGV;
+               $hprefix = shift @ARGV;
        } elsif($arg eq "-debug") {
                $debug = 1;
                shift @ARGV;
@@ -135,6 +141,8 @@ while (($hdr, $lib) = each %libinc)
 
        print STDERR "                                  \r" if $debug;
         $defnr = 0;
+       # Delete any DECLARE_ macros
+       $def =~ s/DECLARE_\w+\([\w,\s]+\)//gs;
        foreach (split /;/, $def) {
            $defnr++;
            print STDERR "def: $defnr\r" if $debug;
@@ -147,6 +155,9 @@ while (($hdr, $lib) = each %libinc)
            # Skip over recognized non-function declarations
            next if(/typedef\W/ or /DECLARE_STACK_OF/ or /TYPEDEF_.*_OF/);
 
+           # 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) {
@@ -186,6 +197,7 @@ while (($hdr, $lib) = each %libinc)
                                $rcodes{$name} = $code;
                                if ($rassigned{$lib} =~ /:$code:/) {
                                        print STDERR "!! ERROR: $lib reason code $code assigned twice\n";
+                                       ++$errcount;
                                }
                                $rassigned{$lib} .= "$code:";
                                if(!(exists $rextra{$name}) &&
@@ -195,6 +207,7 @@ while (($hdr, $lib) = each %libinc)
                        } else {
                                if ($fassigned{$lib} =~ /:$code:/) {
                                        print STDERR "!! ERROR: $lib function code $code assigned twice\n";
+                                       ++$errcount;
                                }
                                $fassigned{$lib} .= "$code:";
                                if($code > $fmax{$lib}) {
@@ -225,6 +238,7 @@ while (($hdr, $lib) = each %libinc)
                if ($rmax{$lib} >= 1000) {
                        print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n";
                        print STDERR "!!        Any new alerts must be added to $config.\n";
+                       ++$errcount;
                        print STDERR "\n";
                }
        }
@@ -307,7 +321,7 @@ foreach $lib (keys %csrc)
        } else {
            push @out,
 "/* ====================================================================\n",
-" * Copyright (c) 2001-2005 The OpenSSL Project.  All rights reserved.\n",
+" * Copyright (c) 2001-2008 The OpenSSL Project.  All rights reserved.\n",
 " *\n",
 " * Redistribution and use in source and binary forms, with or without\n",
 " * modification, are permitted provided that the following conditions\n",
@@ -449,14 +463,21 @@ EOF
                        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;
+                               }
+                       }
                }
                close(IN);
        }
 
+
        my $hincf;
        if($static) {
                $hfile =~ /([^\/]+)$/;
-               $hincf = "<openssl/$1>";
+               $hincf = "<${hprefix}$1>";
        } else {
                $hincf = "\"$hfile\"";
        }
@@ -481,7 +502,7 @@ EOF
        print OUT <<"EOF";
 /* $cfile */
 /* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -595,17 +616,14 @@ if($static) {
 
 ${staticloader}void ERR_load_${lib}_strings(void)
        {
-       static int init=1;
+#ifndef OPENSSL_NO_ERR
 
-       if (init)
+       if (ERR_func_error_string(${lib}_str_functs[0].error) == NULL)
                {
-               init=0;
-#ifndef OPENSSL_NO_ERR
                ERR_load_strings($load_errcode,${lib}_str_functs);
                ERR_load_strings($load_errcode,${lib}_str_reasons);
-#endif
-
                }
+#endif
        }
 EOF
 } else {
@@ -710,3 +728,9 @@ if($debug && defined(@runref) ) {
                print STDERR "$_\n";
        }
 }
+
+if($errcount) {
+       print STDERR "There were errors, failing...\n\n";
+       exit $errcount;
+}
+