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>, <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= "", $linenr = 0;
85 print STDERR "line: $linenr\r" if $debug;
87 last if(/BEGIN\s+ERROR\s+CODES/);
98 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
100 $cpp = 0 if /^#.*endif/;
104 next if (/^#/); # skip preprocessor directives
106 s/\/\*.*?\*\///gs; # ignore comments
107 s/{[^{}]*}//gs; # ignore {} blocks
109 if (/{|\/\*/) { # Add a } so editor works...
116 print STDERR " \r" if $debug;
118 foreach (split /;/, $def) {
120 print STDERR "def: $defnr\r" if $debug;
124 next if(/typedef\W/);
125 if (/\(\*(\w*)\([^\)]+/) {
127 $name =~ tr/[a-z]/[A-Z]/;
129 } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s){
132 } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
133 while (not /\(\)$/s) {
135 s/\([^\(\)]*\)\)$/\)/s;
140 $name =~ tr/[a-z]/[A-Z]/;
142 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
143 print STDERR "Header $hdr: cannot parse: $_;\n";
147 print STDERR " \r" if $debug;
151 # Scan function and reason codes and store them: keep a note of the
155 if(/^#define\s+(\S+)\s+(\S+)/) {
158 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
159 print STDERR "Invalid error code $name\n";
163 $rcodes{$name} = $code;
164 if(!(exists $rextra{$name}) &&
165 ($code > $rmax{$lib}) ) {
169 if($code > $fmax{$lib}) {
172 $fcodes{$name} = $code;
179 # Scan each C source file and look for function and reason codes
180 # This is done by looking for strings that "look like" function or
181 # reason codes: basically anything consisting of all upper case and
182 # numerics which has _F_ or _R_ in it and which has the name of an
183 # error library at the start. This seems to work fine except for the
184 # oddly named structure BIO_F_CTX which needs to be ignored.
185 # If a code doesn't exist in list compiled from headers then mark it
186 # with the value "X" as a place holder to give it a value later.
187 # Store all function and reason codes found in %ufcodes and %urcodes
188 # so all those unreferenced can be printed out.
191 foreach $file (@source) {
192 # Don't parse the error source file.
193 next if exists $cskip{$file};
194 open(IN, "<$file") || die "Can't open source file $file\n";
196 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
197 next unless exists $csrc{$2};
198 next if($1 eq "BIO_F_BUFFER_CTX");
200 if(!exists $fcodes{$1}) {
204 $notrans{$1} = 1 unless exists $ftrans{$3};
206 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
207 next unless exists $csrc{$2};
209 if(!exists $rcodes{$1}) {
218 # Now process each library in turn.
220 foreach $lib (keys %csrc)
222 my $hfile = $hinc{$lib};
223 my $cfile = $csrc{$lib};
224 if(!$fnew{$lib} && !$rnew{$lib}) {
225 print STDERR "$lib:\t\tNo new error codes\n";
226 next unless $rebuild;
228 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
229 print STDERR " $rnew{$lib} New Reasons.\n";
230 next unless $dowrite;
233 # If we get here then we have some new error codes so we
234 # need to rebuild the header file and C file.
236 # Make a sorted list of error and reason codes for later use.
238 my @function = sort grep(/^${lib}_/,keys %fcodes);
239 my @reasons = sort grep(/^${lib}_/,keys %rcodes);
241 # Rewrite the header file
243 open(IN, "<$hfile") || die "Can't Open Header File $hfile\n";
245 # Copy across the old file
248 last if (/BEGIN ERROR CODES/);
252 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
257 /* The following lines are auto generated by the script mkerr.pl. Any changes
258 * made after this point may be overwritten when the script is next run.
261 /* Error codes for the $lib functions. */
263 /* Function codes. */
266 foreach $i (@function) {
267 $z=6-int(length($i)/8);
268 if($fcodes{$i} eq "X") {
269 $fcodes{$i} = ++$fmax{$lib};
270 print STDERR "New Function code $i\n" if $debug;
272 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
275 print OUT "\n/* Reason codes. */\n";
277 foreach $i (@reasons) {
278 $z=6-int(length($i)/8);
279 if($rcodes{$i} eq "X") {
280 $rcodes{$i} = ++$rmax{$lib};
281 print STDERR "New Reason code $i\n" if $debug;
283 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
294 # Rewrite the C source file containing the error details.
296 # First, read any existing reason string definitions:
297 my %err_reason_strings;
298 if (open(IN,"<$cfile")) {
300 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
301 $err_reason_strings{$1} = $2;
309 $hfile =~ /([^\/]+)$/;
310 $hincf = "<openssl/$1>";
312 $hincf = "\"$hfile\"";
316 open (OUT,">$cfile") || die "Can't open $cfile for writing";
320 /* ====================================================================
321 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
323 * Redistribution and use in source and binary forms, with or without
324 * modification, are permitted provided that the following conditions
327 * 1. Redistributions of source code must retain the above copyright
328 * notice, this list of conditions and the following disclaimer.
330 * 2. Redistributions in binary form must reproduce the above copyright
331 * notice, this list of conditions and the following disclaimer in
332 * the documentation and/or other materials provided with the
335 * 3. All advertising materials mentioning features or use of this
336 * software must display the following acknowledgment:
337 * "This product includes software developed by the OpenSSL Project
338 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
340 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
341 * endorse or promote products derived from this software without
342 * prior written permission. For written permission, please contact
343 * openssl-core\@OpenSSL.org.
345 * 5. Products derived from this software may not be called "OpenSSL"
346 * nor may "OpenSSL" appear in their names without prior written
347 * permission of the OpenSSL Project.
349 * 6. Redistributions of any form whatsoever must retain the following
351 * "This product includes software developed by the OpenSSL Project
352 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
354 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
355 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
356 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
357 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
358 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
359 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
360 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
361 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
362 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
363 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
364 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
365 * OF THE POSSIBILITY OF SUCH DAMAGE.
366 * ====================================================================
368 * This product includes cryptographic software written by Eric Young
369 * (eay\@cryptsoft.com). This product includes software written by Tim
370 * Hudson (tjh\@cryptsoft.com).
374 /* NOTE: this file was auto generated by the mkerr.pl script: any changes
375 * made to it will be overwritten when the script next updates this file,
376 * only reason strings will be preserved.
380 #include <openssl/err.h>
383 /* BEGIN ERROR CODES */
384 #ifndef OPENSSL_NO_ERR
385 static ERR_STRING_DATA ${lib}_str_functs[]=
388 # Add each function code: if a function name is found then use it.
389 foreach $i (@function) {
391 $i =~ /^${lib}_F_(\S+)$/;
393 if(exists $ftrans{$fn}) {
396 print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
402 static ERR_STRING_DATA ${lib}_str_reasons[]=
405 # Add each reason code.
406 foreach $i (@reasons) {
409 if (exists $err_reason_strings{$i}) {
410 $rn = $err_reason_strings{$i};
412 $i =~ /^${lib}_R_(\S+)$/;
414 $rn =~ tr/_[A-Z]/ [a-z]/;
416 $nspc = 40 - length($i) unless length($i) > 40;
418 print OUT "{${i}${nspc},\"$rn\"},\n";
427 void ERR_load_${lib}_strings(void)
434 #ifndef OPENSSL_NO_ERR
435 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
436 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
449 #ifdef ${lib}_LIB_NAME
450 static ERR_STRING_DATA ${lib}_lib_name[]=
452 {0 ,${lib}_LIB_NAME},
458 int ${lib}_lib_error_code=0;
460 void ERR_load_${lib}_strings(void)
464 if (${lib}_lib_error_code == 0)
465 ${lib}_lib_error_code=ERR_get_next_error_library();
470 #ifndef OPENSSL_NO_ERR
471 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
472 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
475 #ifdef ${lib}_LIB_NAME
476 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
477 ERR_load_strings(0,${lib}_lib_name);
482 void ERR_${lib}_error(int function, int reason, char *file, int line)
484 if (${lib}_lib_error_code == 0)
485 ${lib}_lib_error_code=ERR_get_next_error_library();
486 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
493 undef %err_reason_strings;
496 if($debug && defined(%notrans)) {
497 print STDERR "The following function codes were not translated:\n";
498 foreach(sort keys %notrans)
504 # Make a list of unreferenced function and reason codes
506 foreach (keys %fcodes) {
507 push (@funref, $_) unless exists $ufcodes{$_};
510 foreach (keys %rcodes) {
511 push (@runref, $_) unless exists $urcodes{$_};
514 if($debug && defined(@funref) ) {
515 print STDERR "The following function codes were not referenced:\n";
516 foreach(sort @funref)
522 if($debug && defined(@runref) ) {
523 print STDERR "The following reason codes were not referenced:\n";
524 foreach(sort @runref)