1 #!/usr/local/bin/perl -w
3 my $config = "crypto/err/openssl.ec";
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 "-write") {
41 @source = (<crypto/*.c>, <crypto/*/*.c>, <rsaref/*.c>, <ssl/*.c>);
46 # Read in the config file
48 open(IN, "<$config") || die "Can't open config file $config";
54 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
64 } elsif (/^F\s+(\S+)/) {
65 # Add extra function with $1
66 } elsif (/^R\s+(\S+)\s+(\S+)/) {
74 # Scan each header file in turn and make a list of error codes
77 while (($lib, $hdr) = each %hinc)
79 next if($hdr eq "NONE");
80 print STDERR "Scanning header file $hdr\n" if $debug;
81 open(IN, "<$hdr") || die "Can't open Header file $hdr\n";
82 my $line = "", $def= "";
84 last if(/BEGIN\s+ERROR\s+CODES/);
95 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
97 $cpp = 0 if /^#.*endif/;
101 next if (/^#/); # skip preprocessor directives
103 s/\/\*.*?\*\///gs; # ignore comments
104 s/{[^{}]*}//gs; # ignore {} blocks
106 if (/{|\/\*/) { # Add a } so editor works...
113 foreach (split /;/, $def) {
116 next if(/typedef\W/);
117 if (/\(\*(\w*)\([^\)]+/) {
119 $name =~ tr/[a-z]/[A-Z]/;
121 } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s){
124 } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
125 while (not /\(\)$/s) {
127 s/\([^\(\)]*\)\)$/\)/s;
132 $name =~ tr/[a-z]/[A-Z]/;
134 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
135 print STDERR "Header $hdr: cannot parse: $_;\n";
141 # Scan function and reason codes and store them: keep a note of the
145 if(/^#define\s+(\S+)\s+(\S+)/) {
148 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
149 print STDERR "Invalid error code $name\n";
153 $rcodes{$name} = $code;
154 if(!(exists $rextra{$name}) &&
155 ($code > $rmax{$lib}) ) {
159 if($code > $fmax{$lib}) {
162 $fcodes{$name} = $code;
169 # Scan each C source file and look for function and reason codes
170 # This is done by looking for strings that "look like" function or
171 # reason codes: basically anything consisting of all upper case and
172 # numerics which has _F_ or _R_ in it and which has the name of an
173 # error library at the start. This seems to work fine except for the
174 # oddly named structure BIO_F_CTX which needs to be ignored.
175 # If a code doesn't exist in list compiled from headers then mark it
176 # with the value "X" as a place holder to give it a value later.
177 # Store all function and reason codes found in %ufcodes and %urcodes
178 # so all those unreferenced can be printed out.
181 foreach $file (@source) {
182 # Don't parse the error source file.
183 next if exists $cskip{$file};
184 open(IN, "<$file") || die "Can't open source file $file\n";
186 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
187 next unless exists $csrc{$2};
188 next if($1 eq "BIO_F_BUFFER_CTX");
190 if(!exists $fcodes{$1}) {
194 $notrans{$1} = 1 unless exists $ftrans{$3};
196 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
197 next unless exists $csrc{$2};
199 if(!exists $rcodes{$1}) {
208 # Now process each library in turn.
210 foreach $lib (keys %csrc)
212 my $hfile = $hinc{$lib};
213 my $cfile = $csrc{$lib};
214 if(!$fnew{$lib} && !$rnew{$lib}) {
215 print STDERR "$lib:\t\tNo new error codes\n";
216 next unless $rebuild;
218 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
219 print STDERR " $rnew{$lib} New Reasons.\n";
220 next unless $dowrite;
223 # If we get here then we have some new error codes so we
224 # need to rebuild the header file and C file.
226 # Make a sorted list of error and reason codes for later use.
228 my @function = sort grep(/^${lib}_/,keys %fcodes);
229 my @reasons = sort grep(/^${lib}_/,keys %rcodes);
231 # Rewrite the header file
233 open(IN, "<$hfile") || die "Can't Open Header File $hfile\n";
235 # Copy across the old file
238 last if (/BEGIN ERROR CODES/);
242 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
247 /* The following lines are auto generated by the script mkerr.pl. Any changes
248 * made after this point may be overwritten when the script is next run.
251 /* Error codes for the $lib functions. */
253 /* Function codes. */
256 foreach $i (@function) {
257 $z=6-int(length($i)/8);
258 if($fcodes{$i} eq "X") {
259 $fcodes{$i} = ++$fmax{$lib};
260 print STDERR "New Function code $i\n" if $debug;
262 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
265 print OUT "\n/* Reason codes. */\n";
267 foreach $i (@reasons) {
268 $z=6-int(length($i)/8);
269 if($rcodes{$i} eq "X") {
270 $rcodes{$i} = ++$rmax{$lib};
271 print STDERR "New Reason code $i\n" if $debug;
273 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
285 # Rewrite the C source file containing the error details.
287 # First, read any existing reason string definitions:
288 my %err_reason_strings;
289 if (open(IN,"<$cfile")) {
291 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
292 $err_reason_strings{$1} = $2;
300 $hfile =~ /([^\/]+)$/;
301 $hincf = "<openssl/$1>";
303 $hincf = "\"$hfile\"";
307 open (OUT,">$cfile") || die "Can't open $cfile for writing";
311 /* ====================================================================
312 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
314 * Redistribution and use in source and binary forms, with or without
315 * modification, are permitted provided that the following conditions
318 * 1. Redistributions of source code must retain the above copyright
319 * notice, this list of conditions and the following disclaimer.
321 * 2. Redistributions in binary form must reproduce the above copyright
322 * notice, this list of conditions and the following disclaimer in
323 * the documentation and/or other materials provided with the
326 * 3. All advertising materials mentioning features or use of this
327 * software must display the following acknowledgment:
328 * "This product includes software developed by the OpenSSL Project
329 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
331 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
332 * endorse or promote products derived from this software without
333 * prior written permission. For written permission, please contact
334 * openssl-core\@OpenSSL.org.
336 * 5. Products derived from this software may not be called "OpenSSL"
337 * nor may "OpenSSL" appear in their names without prior written
338 * permission of the OpenSSL Project.
340 * 6. Redistributions of any form whatsoever must retain the following
342 * "This product includes software developed by the OpenSSL Project
343 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
345 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
346 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
347 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
348 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
349 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
350 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
351 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
352 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
353 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
354 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
355 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
356 * OF THE POSSIBILITY OF SUCH DAMAGE.
357 * ====================================================================
359 * This product includes cryptographic software written by Eric Young
360 * (eay\@cryptsoft.com). This product includes software written by Tim
361 * Hudson (tjh\@cryptsoft.com).
365 /* NOTE: this file was auto generated by the mkerr.pl script: any changes
366 * made to it will be overwritten when the script next updates this file,
367 * only reason strings will be preserved.
371 #include <openssl/err.h>
374 /* BEGIN ERROR CODES */
376 static ERR_STRING_DATA ${lib}_str_functs[]=
379 # Add each function code: if a function name is found then use it.
380 foreach $i (@function) {
382 $i =~ /^${lib}_F_(\S+)$/;
384 if(exists $ftrans{$fn}) {
387 print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
393 static ERR_STRING_DATA ${lib}_str_reasons[]=
396 # Add each reason code.
397 foreach $i (@reasons) {
400 if (exists $err_reason_strings{$i}) {
401 $rn = $err_reason_strings{$i};
403 $i =~ /^${lib}_R_(\S+)$/;
405 $rn =~ tr/_[A-Z]/ [a-z]/;
407 $nspc = 40 - length($i) unless length($i) > 40;
409 print OUT "{${i}${nspc},\"$rn\"},\n";
418 void ERR_load_${lib}_strings(void)
426 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
427 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
440 #ifdef ${lib}_LIB_NAME
441 static ERR_STRING_DATA ${lib}_lib_name[]=
443 {0 ,${lib}_LIB_NAME},
449 int ${lib}_lib_error_code=0;
451 void ERR_load_${lib}_strings(void)
455 if (${lib}_lib_error_code == 0)
456 ${lib}_lib_error_code=ERR_get_next_error_library();
462 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
463 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
466 #ifdef ${lib}_LIB_NAME
467 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
468 ERR_load_strings(0,${lib}_lib_name);
473 void ERR_${lib}_error(int function, int reason, char *file, int line)
475 if (${lib}_lib_error_code == 0)
476 ${lib}_lib_error_code=ERR_get_next_error_library();
477 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
484 undef %err_reason_strings;
487 if($debug && defined(%notrans)) {
488 print STDERR "The following function codes were not translated:\n";
489 foreach(sort keys %notrans)
495 # Make a list of unreferenced function and reason codes
497 foreach (keys %fcodes) {
498 push (@funref, $_) unless exists $ufcodes{$_};
501 foreach (keys %rcodes) {
502 push (@runref, $_) unless exists $urcodes{$_};
505 if($debug && defined(@funref) ) {
506 print STDERR "The following function codes were not referenced:\n";
507 foreach(sort @funref)
513 if($debug && defined(@runref) ) {
514 print STDERR "The following reason codes were not referenced:\n";
515 foreach(sort @runref)