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