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 open(IN, "<$hdr") || die "Can't open Header file $hdr\n";
86 my $line = "", $def= "", $linenr = 0;
89 print STDERR "line: $linenr\r" if $debug;
91 last if(/BEGIN\s+ERROR\s+CODES/);
102 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
104 $cpp = 0 if /^#.*endif/;
108 next if (/^#/); # skip preprocessor directives
110 s/\/\*.*?\*\///gs; # ignore comments
111 s/{[^{}]*}//gs; # ignore {} blocks
113 if (/{|\/\*/) { # Add a } so editor works...
120 print STDERR " \r" if $debug;
122 foreach (split /;/, $def) {
124 print STDERR "def: $defnr\r" if $debug;
128 next if(/typedef\W/);
129 if (/\(\*(\w*)\([^\)]+/) {
131 $name =~ tr/[a-z]/[A-Z]/;
133 } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s){
136 } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
137 while (not /\(\)$/s) {
139 s/\([^\(\)]*\)\)$/\)/s;
144 $name =~ tr/[a-z]/[A-Z]/;
146 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
147 print STDERR "Header $hdr: cannot parse: $_;\n";
151 print STDERR " \r" if $debug;
155 # Scan function and reason codes and store them: keep a note of the
159 if(/^#define\s+(\S+)\s+(\S+)/) {
162 next if $name =~ /^${lib}err/;
163 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
164 print STDERR "Invalid error code $name\n";
168 $rcodes{$name} = $code;
169 if(!(exists $rextra{$name}) &&
170 ($code > $rmax{$lib}) ) {
174 if($code > $fmax{$lib}) {
177 $fcodes{$name} = $code;
184 # Scan each C source file and look for function and reason codes
185 # This is done by looking for strings that "look like" function or
186 # reason codes: basically anything consisting of all upper case and
187 # numerics which has _F_ or _R_ in it and which has the name of an
188 # error library at the start. This seems to work fine except for the
189 # oddly named structure BIO_F_CTX which needs to be ignored.
190 # If a code doesn't exist in list compiled from headers then mark it
191 # with the value "X" as a place holder to give it a value later.
192 # Store all function and reason codes found in %ufcodes and %urcodes
193 # so all those unreferenced can be printed out.
196 print STDERR "Files loaded: " if $debug;
197 foreach $file (@source) {
198 # Don't parse the error source file.
199 next if exists $cskip{$file};
200 print STDERR $file if $debug;
201 open(IN, "<$file") || die "Can't open source file $file\n";
203 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
204 next unless exists $csrc{$2};
205 next if($1 eq "BIO_F_BUFFER_CTX");
207 if(!exists $fcodes{$1}) {
211 $notrans{$1} = 1 unless exists $ftrans{$3};
213 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
214 next unless exists $csrc{$2};
216 if(!exists $rcodes{$1}) {
224 print STDERR "\n" if $debug;
226 # Now process each library in turn.
228 foreach $lib (keys %csrc)
230 my $hfile = $hinc{$lib};
231 my $cfile = $csrc{$lib};
232 if(!$fnew{$lib} && !$rnew{$lib}) {
233 print STDERR "$lib:\t\tNo new error codes\n";
234 next unless $rebuild;
236 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
237 print STDERR " $rnew{$lib} New Reasons.\n";
238 next unless $dowrite;
241 # If we get here then we have some new error codes so we
242 # need to rebuild the header file and C file.
244 # Make a sorted list of error and reason codes for later use.
246 my @function = sort grep(/^${lib}_/,keys %fcodes);
247 my @reasons = sort grep(/^${lib}_/,keys %rcodes);
249 # Rewrite the header file
251 open(IN, "<$hfile") || die "Can't Open Header File $hfile\n";
253 # Copy across the old file
256 last if (/BEGIN ERROR CODES/);
260 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
265 /* The following lines are auto generated by the script mkerr.pl. Any changes
266 * made after this point may be overwritten when the script is next run.
271 ${staticloader}void ERR_load_${lib}_strings(void);
276 ${staticloader}void ERR_load_${lib}_strings(void);
277 ${staticloader}void ERR_unload_${lib}_strings(void);
278 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
279 #define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
284 /* Error codes for the $lib functions. */
286 /* Function codes. */
289 foreach $i (@function) {
290 $z=6-int(length($i)/8);
291 if($fcodes{$i} eq "X") {
292 $fcodes{$i} = ++$fmax{$lib};
293 print STDERR "New Function code $i\n" if $debug;
295 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
298 print OUT "\n/* Reason codes. */\n";
300 foreach $i (@reasons) {
301 $z=6-int(length($i)/8);
302 if($rcodes{$i} eq "X") {
303 $rcodes{$i} = ++$rmax{$lib};
304 print STDERR "New Reason code $i\n" if $debug;
306 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
317 # Rewrite the C source file containing the error details.
319 # First, read any existing reason string definitions:
320 my %err_reason_strings;
321 if (open(IN,"<$cfile")) {
323 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
324 $err_reason_strings{$1} = $2;
332 $hfile =~ /([^\/]+)$/;
333 $hincf = "<openssl/$1>";
335 $hincf = "\"$hfile\"";
339 open (OUT,">$cfile") || die "Can't open $cfile for writing";
343 /* ====================================================================
344 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
346 * Redistribution and use in source and binary forms, with or without
347 * modification, are permitted provided that the following conditions
350 * 1. Redistributions of source code must retain the above copyright
351 * notice, this list of conditions and the following disclaimer.
353 * 2. Redistributions in binary form must reproduce the above copyright
354 * notice, this list of conditions and the following disclaimer in
355 * the documentation and/or other materials provided with the
358 * 3. All advertising materials mentioning features or use of this
359 * software must display the following acknowledgment:
360 * "This product includes software developed by the OpenSSL Project
361 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
363 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
364 * endorse or promote products derived from this software without
365 * prior written permission. For written permission, please contact
366 * openssl-core\@OpenSSL.org.
368 * 5. Products derived from this software may not be called "OpenSSL"
369 * nor may "OpenSSL" appear in their names without prior written
370 * permission of the OpenSSL Project.
372 * 6. Redistributions of any form whatsoever must retain the following
374 * "This product includes software developed by the OpenSSL Project
375 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
377 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
378 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
379 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
380 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
381 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
382 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
383 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
384 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
385 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
386 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
387 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
388 * OF THE POSSIBILITY OF SUCH DAMAGE.
389 * ====================================================================
391 * This product includes cryptographic software written by Eric Young
392 * (eay\@cryptsoft.com). This product includes software written by Tim
393 * Hudson (tjh\@cryptsoft.com).
397 /* NOTE: this file was auto generated by the mkerr.pl script: any changes
398 * made to it will be overwritten when the script next updates this file,
399 * only reason strings will be preserved.
403 #include <openssl/err.h>
406 /* BEGIN ERROR CODES */
407 #ifndef OPENSSL_NO_ERR
408 static ERR_STRING_DATA ${lib}_str_functs[]=
411 # Add each function code: if a function name is found then use it.
412 foreach $i (@function) {
414 $i =~ /^${lib}_F_(\S+)$/;
416 if(exists $ftrans{$fn}) {
419 print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
425 static ERR_STRING_DATA ${lib}_str_reasons[]=
428 # Add each reason code.
429 foreach $i (@reasons) {
432 if (exists $err_reason_strings{$i}) {
433 $rn = $err_reason_strings{$i};
435 $i =~ /^${lib}_R_(\S+)$/;
437 $rn =~ tr/_[A-Z]/ [a-z]/;
439 $nspc = 40 - length($i) unless length($i) > 40;
441 print OUT "{${i}${nspc},\"$rn\"},\n";
450 ${staticloader}void ERR_load_${lib}_strings(void)
457 #ifndef OPENSSL_NO_ERR
458 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
459 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
472 #ifdef ${lib}_LIB_NAME
473 static ERR_STRING_DATA ${lib}_lib_name[]=
475 {0 ,${lib}_LIB_NAME},
481 static int ${lib}_lib_error_code=0;
482 static int ${lib}_error_init=1;
484 ${staticloader}void ERR_load_${lib}_strings(void)
486 if (${lib}_lib_error_code == 0)
487 ${lib}_lib_error_code=ERR_get_next_error_library();
489 if (${lib}_error_init)
492 #ifndef OPENSSL_NO_ERR
493 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
494 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
497 #ifdef ${lib}_LIB_NAME
498 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
499 ERR_load_strings(0,${lib}_lib_name);
504 ${staticloader}void ERR_unload_${lib}_strings(void)
506 if (${lib}_error_init == 0)
508 #ifndef OPENSSL_NO_ERR
509 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_functs);
510 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_reasons);
513 #ifdef ${lib}_LIB_NAME
514 ERR_unload_strings(0,${lib}_lib_name);
520 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line)
522 if (${lib}_lib_error_code == 0)
523 ${lib}_lib_error_code=ERR_get_next_error_library();
524 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
531 undef %err_reason_strings;
534 if($debug && defined(%notrans)) {
535 print STDERR "The following function codes were not translated:\n";
536 foreach(sort keys %notrans)
542 # Make a list of unreferenced function and reason codes
544 foreach (keys %fcodes) {
545 push (@funref, $_) unless exists $ufcodes{$_};
548 foreach (keys %rcodes) {
549 push (@runref, $_) unless exists $urcodes{$_};
552 if($debug && defined(@funref) ) {
553 print STDERR "The following function codes were not referenced:\n";
554 foreach(sort @funref)
560 if($debug && defined(@runref) ) {
561 print STDERR "The following reason codes were not referenced:\n";
562 foreach(sort @runref)