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+)/) {
69 # Add extra reason with $1, value $2
75 # Scan each header file in turn and make a list of error codes
78 while (($lib, $hdr) = each %hinc)
80 next if($hdr eq "NONE");
81 print STDERR "Scanning header file $hdr\n" if $debug;
82 open(IN, "<$hdr") || die "Can't open Header file $hdr\n";
83 my $line = "", $def= "";
85 last if(/BEGIN\s+ERROR\s+CODES/);
96 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
98 $cpp = 0 if /^#.*endif/;
102 next if (/^#/); # skip preprocessor directives
104 s/\/\*.*?\*\///gs; # ignore comments
105 s/{[^{}]*}//gs; # ignore {} blocks
107 if (/{|\/\*/) { # Add a } so editor works...
114 foreach (split /;/, $def) {
117 next if (/\w+\W+(\w+)\W*\(\s*\)$/s); # K&R C
118 next if (/\(\*(\w*)\([^\)]+/);
119 if (/\w+\W+\w+\W*\(.*\)$/s) {
120 while (not /\(\)$/s) {
122 s/\([^\(\)]*\)\)$/\)/s;
126 next if(/typedef\W/);
128 $name =~ tr/[a-z]/[A-Z]/;
131 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
132 print STDERR "Header $hdr: cannot parse: $_;\n";
138 # Scan function and reason codes and store them: keep a note of the
142 if(/^#define\s+(\S+)\s+(\S+)/) {
145 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
146 print STDERR "Invalid error code $name\n";
150 $rcodes{$name} = $code;
151 if(!(exists $rextra{$name}) &&
152 ($code > $rmax{$lib}) ) {
156 if($code > $fmax{$lib}) {
159 $fcodes{$name} = $code;
166 # Scan each C source file and look for function and reason codes
167 # This is done by looking for strings that "look like" function or
168 # reason codes: basically anything consisting of all upper case and
169 # numerics which has _F_ or _R_ in it and which has the name of an
170 # error library at the start. This seems to work fine except for the
171 # oddly named structure BIO_F_CTX which needs to be ignored.
172 # If a code doesn't exist in list compiled from headers then mark it
173 # with the value "X" as a place holder to give it a value later.
174 # Store all function and reason codes found in %ufcodes and %urcodes
175 # so all those unreferenced can be printed out.
178 foreach $file (@source) {
179 # Don't parse the error source file.
180 next if exists $cskip{$file};
181 open(IN, "<$file") || die "Can't open source file $file\n";
183 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
184 next unless exists $csrc{$2};
185 next if($1 eq "BIO_F_BUFFER_CTX");
187 if(!exists $fcodes{$1}) {
191 $notrans{$1} = 1 unless exists $ftrans{$3};
193 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
194 next unless exists $csrc{$2};
196 if(!exists $rcodes{$1}) {
205 # Now process each library in turn.
207 foreach $lib (keys %csrc)
209 my $hfile = $hinc{$lib};
210 my $cfile = $csrc{$lib};
211 if(!$fnew{$lib} && !$rnew{$lib}) {
212 print STDERR "$lib:\t\tNo new error codes\n";
213 next unless $rebuild;
215 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
216 print STDERR " $rnew{$lib} New Reasons.\n";
217 next unless $dowrite;
220 # If we get here then we have some new error codes so we
221 # need to rebuild the header file and C file.
223 # Make a sorted list of error and reason codes for later use.
225 my @function = sort grep(/^${lib}_/,keys %fcodes);
226 my @reasons = sort grep(/^${lib}_/,keys %rcodes);
228 # Rewrite the header file
230 open(IN, "<$hfile") || die "Can't Open Header File $hfile\n";
232 # Copy across the old file
235 last if (/BEGIN ERROR CODES/);
239 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
244 /* The following lines are auto generated by the script mkerr.pl. Any changes
245 * made after this point may be overwritten when the script is next run.
248 /* Error codes for the $lib functions. */
250 /* Function codes. */
253 foreach $i (@function) {
254 $z=6-int(length($i)/8);
255 if($fcodes{$i} eq "X") {
256 $fcodes{$i} = ++$fmax{$lib};
257 print STDERR "New Function code $i\n" if $debug;
259 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
262 print OUT "\n/* Reason codes. */\n";
264 foreach $i (@reasons) {
265 $z=6-int(length($i)/8);
266 if($rcodes{$i} eq "X") {
267 $rcodes{$i} = ++$rmax{$lib};
268 print STDERR "New Reason code $i\n" if $debug;
270 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
282 # Rewrite the C source file containing the error details.
284 $hfile =~ /([^\/]+)$/;
287 open (OUT,">$cfile") || die "Can't open $cfile for writing";
291 /* ====================================================================
292 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
294 * Redistribution and use in source and binary forms, with or without
295 * modification, are permitted provided that the following conditions
298 * 1. Redistributions of source code must retain the above copyright
299 * notice, this list of conditions and the following disclaimer.
301 * 2. Redistributions in binary form must reproduce the above copyright
302 * notice, this list of conditions and the following disclaimer in
303 * the documentation and/or other materials provided with the
306 * 3. All advertising materials mentioning features or use of this
307 * software must display the following acknowledgment:
308 * "This product includes software developed by the OpenSSL Project
309 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
311 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
312 * endorse or promote products derived from this software without
313 * prior written permission. For written permission, please contact
314 * openssl-core\@OpenSSL.org.
316 * 5. Products derived from this software may not be called "OpenSSL"
317 * nor may "OpenSSL" appear in their names without prior written
318 * permission of the OpenSSL Project.
320 * 6. Redistributions of any form whatsoever must retain the following
322 * "This product includes software developed by the OpenSSL Project
323 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
325 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
326 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
327 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
328 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
329 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
330 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
331 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
332 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
333 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
334 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
335 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
336 * OF THE POSSIBILITY OF SUCH DAMAGE.
337 * ====================================================================
339 * This product includes cryptographic software written by Eric Young
340 * (eay\@cryptsoft.com). This product includes software written by Tim
341 * Hudson (tjh\@cryptsoft.com).
345 /* NOTE: this file was auto generated by the mkerr.pl script: any changes
346 * made to it will be overwritten when the script next updates this file.
350 #include <openssl/err.h>
351 #include <openssl/$hincf>
353 /* BEGIN ERROR CODES */
355 static ERR_STRING_DATA ${lib}_str_functs[]=
358 # Add each function code: if a function name is found then use it.
359 foreach $i (@function) {
361 $i =~ /^${lib}_F_(\S+)$/;
363 if(exists $ftrans{$fn}) {
366 print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
372 static ERR_STRING_DATA ${lib}_str_reasons[]=
375 # Add each reason code.
376 foreach $i (@reasons) {
379 $i =~ /^${lib}_R_(\S+)$/;
381 $rn =~ tr/_[A-Z]/ [a-z]/;
382 $nspc = 40 - length($i) unless length($i) > 40;
384 print OUT "{${i}${nspc},\"$rn\"},\n";
393 void ERR_load_${lib}_strings(void)
401 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
402 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
415 #ifdef ${lib}_LIB_NAME
416 static ERR_STRING_DATA ${lib}_lib_name[]=
418 {0 ,${lib}_LIB_NAME},
424 int ${lib}_lib_error_code=0;
426 void ERR_load_${lib}_strings(void)
430 if (${lib}_lib_error_code == 0)
431 ${lib}_lib_error_code=ERR_get_next_error_library();
437 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
438 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
441 #ifdef ${lib}_LIB_NAME
442 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
443 ERR_load_strings(0,${lib}_lib_name);
448 void ERR_${lib}_error(int function, int reason, char *file, int line)
450 if (${lib}_lib_error_code == 0)
451 ${lib}_lib_error_code=ERR_get_next_error_library();
452 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
462 if($debug && defined(%notrans)) {
463 print STDERR "The following function codes were not translated:\n";
464 foreach(sort keys %notrans)
470 # Make a list of unreferenced function and reason codes
472 foreach (keys %fcodes) {
473 push (@funref, $_) unless exists $ufcodes{$_};
476 foreach (keys %rcodes) {
477 push (@runref, $_) unless exists $urcodes{$_};
480 if($debug && defined(@funref) ) {
481 print STDERR "The following function codes were not referenced:\n";
482 foreach(sort @funref)
488 if($debug && defined(@runref) ) {
489 print STDERR "The following reason codes were not referenced:\n";
490 foreach(sort @runref)