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