Fix for "strange errors" exposed by ccgost engine. The fix is
[openssl.git] / util / mkerr.pl
1 #!/usr/local/bin/perl -w
2
3 my $config = "crypto/err/openssl.ec";
4 my $hprefix = "openssl/";
5 my $debug = 0;
6 my $rebuild = 0;
7 my $static = 1;
8 my $recurse = 0;
9 my $reindex = 0;
10 my $dowrite = 0;
11 my $staticloader = "";
12
13 my $pack_errcode;
14 my $load_errcode;
15
16 while (@ARGV) {
17         my $arg = $ARGV[0];
18         if($arg eq "-conf") {
19                 shift @ARGV;
20                 $config = shift @ARGV;
21         } elsif($arg eq "-hprefix") {
22                 shift @ARGV;
23                 $hprefix = shift @ARGV;
24         } elsif($arg eq "-debug") {
25                 $debug = 1;
26                 shift @ARGV;
27         } elsif($arg eq "-rebuild") {
28                 $rebuild = 1;
29                 shift @ARGV;
30         } elsif($arg eq "-recurse") {
31                 $recurse = 1;
32                 shift @ARGV;
33         } elsif($arg eq "-reindex") {
34                 $reindex = 1;
35                 shift @ARGV;
36         } elsif($arg eq "-nostatic") {
37                 $static = 0;
38                 shift @ARGV;
39         } elsif($arg eq "-staticloader") {
40                 $staticloader = "static ";
41                 shift @ARGV;
42         } elsif($arg eq "-write") {
43                 $dowrite = 1;
44                 shift @ARGV;
45         } else {
46                 last;
47         }
48 }
49
50 if($recurse) {
51         @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>);
52 } else {
53         @source = @ARGV;
54 }
55
56 # Read in the config file
57
58 open(IN, "<$config") || die "Can't open config file $config";
59
60 # Parse config file
61
62 while(<IN>)
63 {
64         if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
65                 $hinc{$1} = $2;
66                 $libinc{$2} = $1;
67                 $cskip{$3} = $1;
68                 if($3 ne "NONE") {
69                         $csrc{$1} = $3;
70                         $fmax{$1} = 99;
71                         $rmax{$1} = 99;
72                         $fassigned{$1} = ":";
73                         $rassigned{$1} = ":";
74                         $fnew{$1} = 0;
75                         $rnew{$1} = 0;
76                 }
77         } elsif (/^F\s+(\S+)/) {
78         # Add extra function with $1
79         } elsif (/^R\s+(\S+)\s+(\S+)/) {
80                 $rextra{$1} = $2;
81                 $rcodes{$1} = $2;
82         }
83 }
84
85 close IN;
86
87 # Scan each header file in turn and make a list of error codes
88 # and function names
89
90 while (($hdr, $lib) = each %libinc)
91 {
92         next if($hdr eq "NONE");
93         print STDERR "Scanning header file $hdr\n" if $debug; 
94         my $line = "", $def= "", $linenr = 0, $gotfile = 0;
95         if (open(IN, "<$hdr")) {
96             $gotfile = 1;
97             while(<IN>) {
98                 $linenr++;
99                 print STDERR "line: $linenr\r" if $debug;
100
101                 last if(/BEGIN\s+ERROR\s+CODES/);
102                 if ($line ne '') {
103                     $_ = $line . $_;
104                     $line = '';
105                 }
106
107                 if (/\\$/) {
108                     $line = $_;
109                     next;
110                 }
111
112                 if(/\/\*/) {
113                     if (not /\*\//) {           # multiline comment...
114                         $line = $_;             # ... just accumulate
115                         next; 
116                     } else {
117                         s/\/\*.*?\*\///gs;      # wipe it
118                     }
119                 }
120
121                 if ($cpp) {
122                     $cpp++ if /^#\s*if/;
123                     $cpp-- if /^#\s*endif/;
124                     next;
125                 }
126                 $cpp = 1 if /^#.*ifdef.*cplusplus/;  # skip "C" declaration
127
128                 next if (/^\#/);                      # skip preprocessor directives
129
130                 s/{[^{}]*}//gs;                      # ignore {} blocks
131
132                 if (/\{|\/\*/) { # Add a } so editor works...
133                     $line = $_;
134                 } else {
135                     $def .= $_;
136                 }
137             }
138         }
139
140         print STDERR "                                  \r" if $debug;
141         $defnr = 0;
142         # Delete any DECLARE_ macros
143         $def =~ s/DECLARE_\w+\([\w,\s]+\)//gs;
144         foreach (split /;/, $def) {
145             $defnr++;
146             print STDERR "def: $defnr\r" if $debug;
147
148             # The goal is to collect function names from function declarations.
149
150             s/^[\n\s]*//g;
151             s/[\n\s]*$//g;
152
153             # Skip over recognized non-function declarations
154             next if(/typedef\W/ or /DECLARE_STACK_OF/ or /TYPEDEF_.*_OF/);
155
156             # Remove STACK_OF(foo)
157             s/STACK_OF\(\w+\)/void/;
158
159             # Reduce argument lists to empty ()
160             # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
161             while(/\(.*\)/s) {
162                 s/\([^\(\)]+\)/\{\}/gs;
163                 s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs;    #(*f{}) -> f
164             }
165             # pretend as we didn't use curly braces: {} -> ()
166             s/\{\}/\(\)/gs;
167
168             if (/(\w+)\s*\(\).*/s) {    # first token prior [first] () is
169                 my $name = $1;          # a function name!
170                 $name =~ tr/[a-z]/[A-Z]/;
171                 $ftrans{$name} = $1;
172             } elsif (/[\(\)]/ and not (/=/)) {
173                 print STDERR "Header $hdr: cannot parse: $_;\n";
174             }
175         }
176
177         print STDERR "                                  \r" if $debug;
178
179         next if $reindex;
180
181         # Scan function and reason codes and store them: keep a note of the
182         # maximum code used.
183
184         if ($gotfile) {
185           while(<IN>) {
186                 if(/^\#define\s+(\S+)\s+(\S+)/) {
187                         $name = $1;
188                         $code = $2;
189                         next if $name =~ /^${lib}err/;
190                         unless($name =~ /^${lib}_([RF])_(\w+)$/) {
191                                 print STDERR "Invalid error code $name\n";
192                                 next;
193                         }
194                         if($1 eq "R") {
195                                 $rcodes{$name} = $code;
196                                 if ($rassigned{$lib} =~ /:$code:/) {
197                                         print STDERR "!! ERROR: $lib reason code $code assigned twice\n";
198                                 }
199                                 $rassigned{$lib} .= "$code:";
200                                 if(!(exists $rextra{$name}) &&
201                                          ($code > $rmax{$lib}) ) {
202                                         $rmax{$lib} = $code;
203                                 }
204                         } else {
205                                 if ($fassigned{$lib} =~ /:$code:/) {
206                                         print STDERR "!! ERROR: $lib function code $code assigned twice\n";
207                                 }
208                                 $fassigned{$lib} .= "$code:";
209                                 if($code > $fmax{$lib}) {
210                                         $fmax{$lib} = $code;
211                                 }
212                                 $fcodes{$name} = $code;
213                         }
214                 }
215           }
216         }
217
218         if ($debug) {
219                 if (defined($fmax{$lib})) {
220                         print STDERR "Max function code fmax" . "{" . "$lib" . "} = $fmax{$lib}\n";
221                         $fassigned{$lib} =~ m/^:(.*):$/;
222                         @fassigned = sort {$a <=> $b} split(":", $1);
223                         print STDERR "  @fassigned\n";
224                 }
225                 if (defined($rmax{$lib})) {
226                         print STDERR "Max reason code rmax" . "{" . "$lib" . "} = $rmax{$lib}\n";
227                         $rassigned{$lib} =~ m/^:(.*):$/;
228                         @rassigned = sort {$a <=> $b} split(":", $1);
229                         print STDERR "  @rassigned\n";
230                 }
231         }
232
233         if ($lib eq "SSL") {
234                 if ($rmax{$lib} >= 1000) {
235                         print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n";
236                         print STDERR "!!        Any new alerts must be added to $config.\n";
237                         print STDERR "\n";
238                 }
239         }
240         close IN;
241 }
242
243 # Scan each C source file and look for function and reason codes
244 # This is done by looking for strings that "look like" function or
245 # reason codes: basically anything consisting of all upper case and
246 # numerics which has _F_ or _R_ in it and which has the name of an
247 # error library at the start. This seems to work fine except for the
248 # oddly named structure BIO_F_CTX which needs to be ignored.
249 # If a code doesn't exist in list compiled from headers then mark it
250 # with the value "X" as a place holder to give it a value later.
251 # Store all function and reason codes found in %ufcodes and %urcodes
252 # so all those unreferenced can be printed out.
253
254
255 foreach $file (@source) {
256         # Don't parse the error source file.
257         next if exists $cskip{$file};
258         print STDERR "File loaded: ".$file."\r" if $debug;
259         open(IN, "<$file") || die "Can't open source file $file\n";
260         while(<IN>) {
261                 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
262                         next unless exists $csrc{$2};
263                         next if($1 eq "BIO_F_BUFFER_CTX");
264                         $ufcodes{$1} = 1;
265                         if(!exists $fcodes{$1}) {
266                                 $fcodes{$1} = "X";
267                                 $fnew{$2}++;
268                         }
269                         $notrans{$1} = 1 unless exists $ftrans{$3};
270                 }
271                 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
272                         next unless exists $csrc{$2};
273                         $urcodes{$1} = 1;
274                         if(!exists $rcodes{$1}) {
275                                 $rcodes{$1} = "X";
276                                 $rnew{$2}++;
277                         }
278                 } 
279         }
280         close IN;
281 }
282 print STDERR "                                  \n" if $debug;
283
284 # Now process each library in turn.
285
286 foreach $lib (keys %csrc)
287 {
288         my $hfile = $hinc{$lib};
289         my $cfile = $csrc{$lib};
290         if(!$fnew{$lib} && !$rnew{$lib}) {
291                 print STDERR "$lib:\t\tNo new error codes\n";
292                 next unless $rebuild;
293         } else {
294                 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
295                 print STDERR " $rnew{$lib} New Reasons.\n";
296                 next unless $dowrite;
297         }
298
299         # If we get here then we have some new error codes so we
300         # need to rebuild the header file and C file.
301
302         # Make a sorted list of error and reason codes for later use.
303
304         my @function = sort grep(/^${lib}_/,keys %fcodes);
305         my @reasons = sort grep(/^${lib}_/,keys %rcodes);
306
307         # Rewrite the header file
308
309         if (open(IN, "<$hfile")) {
310             # Copy across the old file
311             while(<IN>) {
312                 push @out, $_;
313                 last if (/BEGIN ERROR CODES/);
314             }
315             close IN;
316         } else {
317             push @out,
318 "/* ====================================================================\n",
319 " * Copyright (c) 2001-2005 The OpenSSL Project.  All rights reserved.\n",
320 " *\n",
321 " * Redistribution and use in source and binary forms, with or without\n",
322 " * modification, are permitted provided that the following conditions\n",
323 " * are met:\n",
324 " *\n",
325 " * 1. Redistributions of source code must retain the above copyright\n",
326 " *    notice, this list of conditions and the following disclaimer. \n",
327 " *\n",
328 " * 2. Redistributions in binary form must reproduce the above copyright\n",
329 " *    notice, this list of conditions and the following disclaimer in\n",
330 " *    the documentation and/or other materials provided with the\n",
331 " *    distribution.\n",
332 " *\n",
333 " * 3. All advertising materials mentioning features or use of this\n",
334 " *    software must display the following acknowledgment:\n",
335 " *    \"This product includes software developed by the OpenSSL Project\n",
336 " *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n",
337 " *\n",
338 " * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n",
339 " *    endorse or promote products derived from this software without\n",
340 " *    prior written permission. For written permission, please contact\n",
341 " *    openssl-core\@openssl.org.\n",
342 " *\n",
343 " * 5. Products derived from this software may not be called \"OpenSSL\"\n",
344 " *    nor may \"OpenSSL\" appear in their names without prior written\n",
345 " *    permission of the OpenSSL Project.\n",
346 " *\n",
347 " * 6. Redistributions of any form whatsoever must retain the following\n",
348 " *    acknowledgment:\n",
349 " *    \"This product includes software developed by the OpenSSL Project\n",
350 " *    for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n",
351 " *\n",
352 " * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n",
353 " * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n",
354 " * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n",
355 " * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\n",
356 " * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n",
357 " * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n",
358 " * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n",
359 " * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n",
360 " * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n",
361 " * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n",
362 " * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n",
363 " * OF THE POSSIBILITY OF SUCH DAMAGE.\n",
364 " * ====================================================================\n",
365 " *\n",
366 " * This product includes cryptographic software written by Eric Young\n",
367 " * (eay\@cryptsoft.com).  This product includes software written by Tim\n",
368 " * Hudson (tjh\@cryptsoft.com).\n",
369 " *\n",
370 " */\n",
371 "\n",
372 "#ifndef HEADER_${lib}_ERR_H\n",
373 "#define HEADER_${lib}_ERR_H\n",
374 "\n",
375 "/* BEGIN ERROR CODES */\n";
376         }
377         open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
378
379         print OUT @out;
380         undef @out;
381         print OUT <<"EOF";
382 /* The following lines are auto generated by the script mkerr.pl. Any changes
383  * made after this point may be overwritten when the script is next run.
384  */
385 EOF
386         if($static) {
387                 print OUT <<"EOF";
388 ${staticloader}void ERR_load_${lib}_strings(void);
389
390 EOF
391         } else {
392                 print OUT <<"EOF";
393 ${staticloader}void ERR_load_${lib}_strings(void);
394 ${staticloader}void ERR_unload_${lib}_strings(void);
395 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
396 #define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
397
398 EOF
399         }
400         print OUT <<"EOF";
401 /* Error codes for the $lib functions. */
402
403 /* Function codes. */
404 EOF
405
406         foreach $i (@function) {
407                 $z=6-int(length($i)/8);
408                 if($fcodes{$i} eq "X") {
409                         $fassigned{$lib} =~ m/^:([^:]*):/;
410                         $findcode = $1;
411                         if (!defined($findcode)) {
412                                 $findcode = $fmax{$lib};
413                         }
414                         while ($fassigned{$lib} =~ m/:$findcode:/) {
415                                 $findcode++;
416                         }
417                         $fcodes{$i} = $findcode;
418                         $fassigned{$lib} .= "$findcode:";
419                         print STDERR "New Function code $i\n" if $debug;
420                 }
421                 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
422         }
423
424         print OUT "\n/* Reason codes. */\n";
425
426         foreach $i (@reasons) {
427                 $z=6-int(length($i)/8);
428                 if($rcodes{$i} eq "X") {
429                         $rassigned{$lib} =~ m/^:([^:]*):/;
430                         $findcode = $1;
431                         if (!defined($findcode)) {
432                                 $findcode = $rmax{$lib};
433                         }
434                         while ($rassigned{$lib} =~ m/:$findcode:/) {
435                                 $findcode++;
436                         }
437                         $rcodes{$i} = $findcode;
438                         $rassigned{$lib} .= "$findcode:";
439                         print STDERR "New Reason code   $i\n" if $debug;
440                 }
441                 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
442         }
443         print OUT <<"EOF";
444
445 #ifdef  __cplusplus
446 }
447 #endif
448 #endif
449 EOF
450         close OUT;
451
452         # Rewrite the C source file containing the error details.
453
454         # First, read any existing reason string definitions:
455         my %err_reason_strings;
456         if (open(IN,"<$cfile")) {
457                 while (<IN>) {
458                         if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
459                                 $err_reason_strings{$1} = $2;
460                         }
461                         if (/\b${lib}_F_(\w*)\b.*\"(.*)\"/) {
462                                 if (!exists $ftrans{$1} && ($1 ne $2)) {
463                                         print STDERR "WARNING: Mismatched function string $2\n";
464                                         $ftrans{$1} = $2;
465                                 }
466                         }
467                 }
468                 close(IN);
469         }
470
471
472         my $hincf;
473         if($static) {
474                 $hfile =~ /([^\/]+)$/;
475                 $hincf = "<${hprefix}$1>";
476         } else {
477                 $hincf = "\"$hfile\"";
478         }
479
480         # If static we know the error code at compile time so use it
481         # in error definitions.
482
483         if ($static)
484                 {
485                 $pack_errcode = "ERR_LIB_${lib}";
486                 $load_errcode = "0";
487                 }
488         else
489                 {
490                 $pack_errcode = "0";
491                 $load_errcode = "ERR_LIB_${lib}";
492                 }
493
494
495         open (OUT,">$cfile") || die "Can't open $cfile for writing";
496
497         print OUT <<"EOF";
498 /* $cfile */
499 /* ====================================================================
500  * Copyright (c) 1999-2006 The OpenSSL Project.  All rights reserved.
501  *
502  * Redistribution and use in source and binary forms, with or without
503  * modification, are permitted provided that the following conditions
504  * are met:
505  *
506  * 1. Redistributions of source code must retain the above copyright
507  *    notice, this list of conditions and the following disclaimer. 
508  *
509  * 2. Redistributions in binary form must reproduce the above copyright
510  *    notice, this list of conditions and the following disclaimer in
511  *    the documentation and/or other materials provided with the
512  *    distribution.
513  *
514  * 3. All advertising materials mentioning features or use of this
515  *    software must display the following acknowledgment:
516  *    "This product includes software developed by the OpenSSL Project
517  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
518  *
519  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
520  *    endorse or promote products derived from this software without
521  *    prior written permission. For written permission, please contact
522  *    openssl-core\@OpenSSL.org.
523  *
524  * 5. Products derived from this software may not be called "OpenSSL"
525  *    nor may "OpenSSL" appear in their names without prior written
526  *    permission of the OpenSSL Project.
527  *
528  * 6. Redistributions of any form whatsoever must retain the following
529  *    acknowledgment:
530  *    "This product includes software developed by the OpenSSL Project
531  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
532  *
533  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
534  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
535  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
536  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
537  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
538  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
539  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
540  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
541  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
542  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
543  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
544  * OF THE POSSIBILITY OF SUCH DAMAGE.
545  * ====================================================================
546  *
547  * This product includes cryptographic software written by Eric Young
548  * (eay\@cryptsoft.com).  This product includes software written by Tim
549  * Hudson (tjh\@cryptsoft.com).
550  *
551  */
552
553 /* NOTE: this file was auto generated by the mkerr.pl script: any changes
554  * made to it will be overwritten when the script next updates this file,
555  * only reason strings will be preserved.
556  */
557
558 #include <stdio.h>
559 #include <openssl/err.h>
560 #include $hincf
561
562 /* BEGIN ERROR CODES */
563 #ifndef OPENSSL_NO_ERR
564
565 #define ERR_FUNC(func) ERR_PACK($pack_errcode,func,0)
566 #define ERR_REASON(reason) ERR_PACK($pack_errcode,0,reason)
567
568 static ERR_STRING_DATA ${lib}_str_functs[]=
569         {
570 EOF
571         # Add each function code: if a function name is found then use it.
572         foreach $i (@function) {
573                 my $fn;
574                 $i =~ /^${lib}_F_(\S+)$/;
575                 $fn = $1;
576                 if(exists $ftrans{$fn}) {
577                         $fn = $ftrans{$fn};
578                 }
579 #               print OUT "{ERR_PACK($pack_errcode,$i,0),\t\"$fn\"},\n";
580                 print OUT "{ERR_FUNC($i),\t\"$fn\"},\n";
581         }
582         print OUT <<"EOF";
583 {0,NULL}
584         };
585
586 static ERR_STRING_DATA ${lib}_str_reasons[]=
587         {
588 EOF
589         # Add each reason code.
590         foreach $i (@reasons) {
591                 my $rn;
592                 my $rstr = "ERR_REASON($i)";
593                 my $nspc = 0;
594                 if (exists $err_reason_strings{$i}) {
595                         $rn = $err_reason_strings{$i};
596                 } else {
597                         $i =~ /^${lib}_R_(\S+)$/;
598                         $rn = $1;
599                         $rn =~ tr/_[A-Z]/ [a-z]/;
600                 }
601                 $nspc = 40 - length($rstr) unless length($rstr) > 40;
602                 $nspc = " " x $nspc;
603                 print OUT "{${rstr}${nspc},\"$rn\"},\n";
604         }
605 if($static) {
606         print OUT <<"EOF";
607 {0,NULL}
608         };
609
610 #endif
611
612 ${staticloader}void ERR_load_${lib}_strings(void)
613         {
614 #ifndef OPENSSL_NO_ERR
615
616         if (ERR_func_error_string(${lib}_str_functs[0].error) == NULL)
617                 {
618                 ERR_load_strings($load_errcode,${lib}_str_functs);
619                 ERR_load_strings($load_errcode,${lib}_str_reasons);
620                 }
621 #endif
622         }
623 EOF
624 } else {
625         print OUT <<"EOF";
626 {0,NULL}
627         };
628
629 #endif
630
631 #ifdef ${lib}_LIB_NAME
632 static ERR_STRING_DATA ${lib}_lib_name[]=
633         {
634 {0      ,${lib}_LIB_NAME},
635 {0,NULL}
636         };
637 #endif
638
639
640 static int ${lib}_lib_error_code=0;
641 static int ${lib}_error_init=1;
642
643 ${staticloader}void ERR_load_${lib}_strings(void)
644         {
645         if (${lib}_lib_error_code == 0)
646                 ${lib}_lib_error_code=ERR_get_next_error_library();
647
648         if (${lib}_error_init)
649                 {
650                 ${lib}_error_init=0;
651 #ifndef OPENSSL_NO_ERR
652                 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
653                 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
654 #endif
655
656 #ifdef ${lib}_LIB_NAME
657                 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
658                 ERR_load_strings(0,${lib}_lib_name);
659 #endif
660                 }
661         }
662
663 ${staticloader}void ERR_unload_${lib}_strings(void)
664         {
665         if (${lib}_error_init == 0)
666                 {
667 #ifndef OPENSSL_NO_ERR
668                 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_functs);
669                 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_reasons);
670 #endif
671
672 #ifdef ${lib}_LIB_NAME
673                 ERR_unload_strings(0,${lib}_lib_name);
674 #endif
675                 ${lib}_error_init=1;
676                 }
677         }
678
679 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line)
680         {
681         if (${lib}_lib_error_code == 0)
682                 ${lib}_lib_error_code=ERR_get_next_error_library();
683         ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
684         }
685 EOF
686
687 }
688
689         close OUT;
690         undef %err_reason_strings;
691 }
692
693 if($debug && defined(%notrans)) {
694         print STDERR "The following function codes were not translated:\n";
695         foreach(sort keys %notrans)
696         {
697                 print STDERR "$_\n";
698         }
699 }
700
701 # Make a list of unreferenced function and reason codes
702
703 foreach (keys %fcodes) {
704         push (@funref, $_) unless exists $ufcodes{$_};
705 }
706
707 foreach (keys %rcodes) {
708         push (@runref, $_) unless exists $urcodes{$_};
709 }
710
711 if($debug && defined(@funref) ) {
712         print STDERR "The following function codes were not referenced:\n";
713         foreach(sort @funref)
714         {
715                 print STDERR "$_\n";
716         }
717 }
718
719 if($debug && defined(@runref) ) {
720         print STDERR "The following reason codes were not referenced:\n";
721         foreach(sort @runref)
722         {
723                 print STDERR "$_\n";
724         }
725 }