1 #!/usr/local/bin/perl -w
3 my $config = "crypto/err/openssl.ec";
10 my $staticloader = "";
16 $config = shift @ARGV;
17 } elsif($arg eq "-debug") {
20 } elsif($arg eq "-rebuild") {
23 } elsif($arg eq "-recurse") {
26 } elsif($arg eq "-reindex") {
29 } elsif($arg eq "-nostatic") {
32 } elsif($arg eq "-staticloader") {
33 $staticloader = "static ";
35 } elsif($arg eq "-write") {
44 @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>);
49 # Read in the config file
51 open(IN, "<$config") || die "Can't open config file $config";
57 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
68 } elsif (/^F\s+(\S+)/) {
69 # Add extra function with $1
70 } elsif (/^R\s+(\S+)\s+(\S+)/) {
78 # Scan each header file in turn and make a list of error codes
81 while (($hdr, $lib) = each %libinc)
83 next if($hdr eq "NONE");
84 print STDERR "Scanning header file $hdr\n" if $debug;
85 my $line = "", $def= "", $linenr = 0, $gotfile = 0;
86 if (open(IN, "<$hdr")) {
90 print STDERR "line: $linenr\r" if $debug;
92 last if(/BEGIN\s+ERROR\s+CODES/);
103 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
105 $cpp = 0 if /^#.*endif/;
109 next if (/^\#/); # skip preprocessor directives
111 s/\/\*.*?\*\///gs; # ignore comments
112 s/{[^{}]*}//gs; # ignore {} blocks
114 if (/\{|\/\*/) { # Add a } so editor works...
122 print STDERR " \r" if $debug;
124 foreach (split /;/, $def) {
126 print STDERR "def: $defnr\r" if $debug;
130 next if(/typedef\W/);
131 if (/\(\*(\w*)\([^\)]+/) {
133 $name =~ tr/[a-z]/[A-Z]/;
135 } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s){
138 } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
139 while (not /\(\)$/s) {
141 s/\([^\(\)]*\)\)$/\)/s;
146 $name =~ tr/[a-z]/[A-Z]/;
148 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
149 print STDERR "Header $hdr: cannot parse: $_;\n";
153 print STDERR " \r" if $debug;
157 # Scan function and reason codes and store them: keep a note of the
162 if(/^\#define\s+(\S+)\s+(\S+)/) {
165 next if $name =~ /^${lib}err/;
166 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
167 print STDERR "Invalid error code $name\n";
171 $rcodes{$name} = $code;
172 if(!(exists $rextra{$name}) &&
173 ($code > $rmax{$lib}) ) {
177 if($code > $fmax{$lib}) {
180 $fcodes{$name} = $code;
188 # Scan each C source file and look for function and reason codes
189 # This is done by looking for strings that "look like" function or
190 # reason codes: basically anything consisting of all upper case and
191 # numerics which has _F_ or _R_ in it and which has the name of an
192 # error library at the start. This seems to work fine except for the
193 # oddly named structure BIO_F_CTX which needs to be ignored.
194 # If a code doesn't exist in list compiled from headers then mark it
195 # with the value "X" as a place holder to give it a value later.
196 # Store all function and reason codes found in %ufcodes and %urcodes
197 # so all those unreferenced can be printed out.
200 print STDERR "Files loaded: " if $debug;
201 foreach $file (@source) {
202 # Don't parse the error source file.
203 next if exists $cskip{$file};
204 print STDERR $file if $debug;
205 open(IN, "<$file") || die "Can't open source file $file\n";
207 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
208 next unless exists $csrc{$2};
209 next if($1 eq "BIO_F_BUFFER_CTX");
211 if(!exists $fcodes{$1}) {
215 $notrans{$1} = 1 unless exists $ftrans{$3};
217 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
218 next unless exists $csrc{$2};
220 if(!exists $rcodes{$1}) {
228 print STDERR "\n" if $debug;
230 # Now process each library in turn.
232 foreach $lib (keys %csrc)
234 my $hfile = $hinc{$lib};
235 my $cfile = $csrc{$lib};
236 if(!$fnew{$lib} && !$rnew{$lib}) {
237 print STDERR "$lib:\t\tNo new error codes\n";
238 next unless $rebuild;
240 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
241 print STDERR " $rnew{$lib} New Reasons.\n";
242 next unless $dowrite;
245 # If we get here then we have some new error codes so we
246 # need to rebuild the header file and C file.
248 # Make a sorted list of error and reason codes for later use.
250 my @function = sort grep(/^${lib}_/,keys %fcodes);
251 my @reasons = sort grep(/^${lib}_/,keys %rcodes);
253 # Rewrite the header file
255 if (open(IN, "<$hfile")) {
256 # Copy across the old file
259 last if (/BEGIN ERROR CODES/);
264 "/* ====================================================================\n",
265 " * Copyright (c) 2001 The OpenSSL Project. All rights reserved.\n",
267 " * Redistribution and use in source and binary forms, with or without\n",
268 " * modification, are permitted provided that the following conditions\n",
271 " * 1. Redistributions of source code must retain the above copyright\n",
272 " * notice, this list of conditions and the following disclaimer. \n",
274 " * 2. Redistributions in binary form must reproduce the above copyright\n",
275 " * notice, this list of conditions and the following disclaimer in\n",
276 " * the documentation and/or other materials provided with the\n",
277 " * distribution.\n",
279 " * 3. All advertising materials mentioning features or use of this\n",
280 " * software must display the following acknowledgment:\n",
281 " * \"This product includes software developed by the OpenSSL Project\n",
282 " * for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n",
284 " * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n",
285 " * endorse or promote products derived from this software without\n",
286 " * prior written permission. For written permission, please contact\n",
287 " * openssl-core\@openssl.org.\n",
289 " * 5. Products derived from this software may not be called \"OpenSSL\"\n",
290 " * nor may \"OpenSSL\" appear in their names without prior written\n",
291 " * permission of the OpenSSL Project.\n",
293 " * 6. Redistributions of any form whatsoever must retain the following\n",
294 " * acknowledgment:\n",
295 " * \"This product includes software developed by the OpenSSL Project\n",
296 " * for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n",
298 " * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n",
299 " * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n",
300 " * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n",
301 " * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n",
302 " * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n",
303 " * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n",
304 " * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n",
305 " * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n",
306 " * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n",
307 " * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n",
308 " * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n",
309 " * OF THE POSSIBILITY OF SUCH DAMAGE.\n",
310 " * ====================================================================\n",
312 " * This product includes cryptographic software written by Eric Young\n",
313 " * (eay\@cryptsoft.com). This product includes software written by Tim\n",
314 " * Hudson (tjh\@cryptsoft.com).\n",
318 "#ifndef HEADER_${lib}_ERR_H\n",
319 "#define HEADER_${lib}_ERR_H\n",
321 "/* BEGIN ERROR CODES */\n";
323 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
328 /* The following lines are auto generated by the script mkerr.pl. Any changes
329 * made after this point may be overwritten when the script is next run.
334 ${staticloader}void ERR_load_${lib}_strings(void);
339 ${staticloader}void ERR_load_${lib}_strings(void);
340 ${staticloader}void ERR_unload_${lib}_strings(void);
341 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
342 #define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
347 /* Error codes for the $lib functions. */
349 /* Function codes. */
352 foreach $i (@function) {
353 $z=6-int(length($i)/8);
354 if($fcodes{$i} eq "X") {
355 $fcodes{$i} = ++$fmax{$lib};
356 print STDERR "New Function code $i\n" if $debug;
358 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
361 print OUT "\n/* Reason codes. */\n";
363 foreach $i (@reasons) {
364 $z=6-int(length($i)/8);
365 if($rcodes{$i} eq "X") {
366 $rcodes{$i} = ++$rmax{$lib};
367 print STDERR "New Reason code $i\n" if $debug;
369 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
380 # Rewrite the C source file containing the error details.
382 # First, read any existing reason string definitions:
383 my %err_reason_strings;
384 if (open(IN,"<$cfile")) {
386 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
387 $err_reason_strings{$1} = $2;
395 $hfile =~ /([^\/]+)$/;
396 $hincf = "<openssl/$1>";
398 $hincf = "\"$hfile\"";
402 open (OUT,">$cfile") || die "Can't open $cfile for writing";
406 /* ====================================================================
407 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
409 * Redistribution and use in source and binary forms, with or without
410 * modification, are permitted provided that the following conditions
413 * 1. Redistributions of source code must retain the above copyright
414 * notice, this list of conditions and the following disclaimer.
416 * 2. Redistributions in binary form must reproduce the above copyright
417 * notice, this list of conditions and the following disclaimer in
418 * the documentation and/or other materials provided with the
421 * 3. All advertising materials mentioning features or use of this
422 * software must display the following acknowledgment:
423 * "This product includes software developed by the OpenSSL Project
424 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
426 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
427 * endorse or promote products derived from this software without
428 * prior written permission. For written permission, please contact
429 * openssl-core\@OpenSSL.org.
431 * 5. Products derived from this software may not be called "OpenSSL"
432 * nor may "OpenSSL" appear in their names without prior written
433 * permission of the OpenSSL Project.
435 * 6. Redistributions of any form whatsoever must retain the following
437 * "This product includes software developed by the OpenSSL Project
438 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
440 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
441 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
442 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
443 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
444 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
445 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
446 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
447 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
448 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
449 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
450 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
451 * OF THE POSSIBILITY OF SUCH DAMAGE.
452 * ====================================================================
454 * This product includes cryptographic software written by Eric Young
455 * (eay\@cryptsoft.com). This product includes software written by Tim
456 * Hudson (tjh\@cryptsoft.com).
460 /* NOTE: this file was auto generated by the mkerr.pl script: any changes
461 * made to it will be overwritten when the script next updates this file,
462 * only reason strings will be preserved.
466 #include <openssl/err.h>
469 /* BEGIN ERROR CODES */
470 #ifndef OPENSSL_NO_ERR
471 static ERR_STRING_DATA ${lib}_str_functs[]=
474 # Add each function code: if a function name is found then use it.
475 foreach $i (@function) {
477 $i =~ /^${lib}_F_(\S+)$/;
479 if(exists $ftrans{$fn}) {
482 print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
488 static ERR_STRING_DATA ${lib}_str_reasons[]=
491 # Add each reason code.
492 foreach $i (@reasons) {
495 if (exists $err_reason_strings{$i}) {
496 $rn = $err_reason_strings{$i};
498 $i =~ /^${lib}_R_(\S+)$/;
500 $rn =~ tr/_[A-Z]/ [a-z]/;
502 $nspc = 40 - length($i) unless length($i) > 40;
504 print OUT "{${i}${nspc},\"$rn\"},\n";
513 ${staticloader}void ERR_load_${lib}_strings(void)
520 #ifndef OPENSSL_NO_ERR
521 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
522 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
535 #ifdef ${lib}_LIB_NAME
536 static ERR_STRING_DATA ${lib}_lib_name[]=
538 {0 ,${lib}_LIB_NAME},
544 static int ${lib}_lib_error_code=0;
545 static int ${lib}_error_init=1;
547 ${staticloader}void ERR_load_${lib}_strings(void)
549 if (${lib}_lib_error_code == 0)
550 ${lib}_lib_error_code=ERR_get_next_error_library();
552 if (${lib}_error_init)
555 #ifndef OPENSSL_NO_ERR
556 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
557 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
560 #ifdef ${lib}_LIB_NAME
561 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
562 ERR_load_strings(0,${lib}_lib_name);
567 ${staticloader}void ERR_unload_${lib}_strings(void)
569 if (${lib}_error_init == 0)
571 #ifndef OPENSSL_NO_ERR
572 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_functs);
573 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_reasons);
576 #ifdef ${lib}_LIB_NAME
577 ERR_unload_strings(0,${lib}_lib_name);
583 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line)
585 if (${lib}_lib_error_code == 0)
586 ${lib}_lib_error_code=ERR_get_next_error_library();
587 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
594 undef %err_reason_strings;
597 if($debug && defined(%notrans)) {
598 print STDERR "The following function codes were not translated:\n";
599 foreach(sort keys %notrans)
605 # Make a list of unreferenced function and reason codes
607 foreach (keys %fcodes) {
608 push (@funref, $_) unless exists $ufcodes{$_};
611 foreach (keys %rcodes) {
612 push (@runref, $_) unless exists $urcodes{$_};
615 if($debug && defined(@funref) ) {
616 print STDERR "The following function codes were not referenced:\n";
617 foreach(sort @funref)
623 if($debug && defined(@runref) ) {
624 print STDERR "The following reason codes were not referenced:\n";
625 foreach(sort @runref)