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