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