1 #!/usr/local/bin/perl -w
3 my $config = "crypto/err/openssl.ec";
15 $config = shift @ARGV;
16 } elsif($arg eq "-debug") {
19 } elsif($arg eq "-rebuild") {
22 } elsif($arg eq "-recurse") {
25 } elsif($arg eq "-reindex") {
28 } elsif($arg eq "-static") {
37 @source = (<crypto/*.c>, <crypto/*/*.c>, ,<rsaref/*.c>, <ssl/*.c>);
42 # Read in the config file
44 open(IN, "<$config") || die "Can't open config file $config";
50 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
60 } elsif (/^F\s+(\S+)/) {
61 # Add extra function with $1
62 } elsif (/^R\s+(\S+)\s+(\S+)/) {
65 # Add extra reason with $1, value $2
71 # Scan each header file in turn and make a list of error codes
74 while (($lib, $hdr) = each %hinc)
76 next if($hdr eq "NONE");
77 print STDERR "Scanning header file $hdr\n" if $debug;
78 open(IN, "<$hdr") || die "Can't open Header file $hdr\n";
79 my $line = "", $def= "";
81 last if(/BEGIN\s+ERROR\s+CODES/);
92 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
94 $cpp = 0 if /^#.*endif/;
98 next if (/^#/); # skip preprocessor directives
100 s/\/\*.*?\*\///gs; # ignore comments
101 s/{[^{}]*}//gs; # ignore {} blocks
103 if (/{|\/\*/) { # Add a } so editor works...
110 foreach (split /;/, $def) {
113 next if (/\w+\W+(\w+)\W*\(\s*\)$/s); # K&R C
114 next if (/\(\*(\w*)\([^\)]+/);
115 if (/\w+\W+\w+\W*\(.*\)$/s) {
116 while (not /\(\)$/s) {
118 s/\([^\(\)]*\)\)$/\)/s;
122 next if(/typedef\W/);
124 $name =~ tr/[a-z]/[A-Z]/;
127 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
128 print STDERR "Header $hdr: cannot parse: $_;\n";
134 # Scan function and reason codes and store them: keep a note of the
138 if(/^#define\s+(\S+)\s+(\S+)/) {
141 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
142 print STDERR "Invalid error code $name\n";
146 $rcodes{$name} = $code;
147 if(!(exists $rextra{$name}) &&
148 ($code > $rmax{$lib}) ) {
152 if($code > $fmax{$lib}) {
155 $fcodes{$name} = $code;
162 # Scan each C source file and look for function and reason codes
163 # This is done by looking for strings that "look like" function or
164 # reason codes: basically anything consisting of all upper case and
165 # numerics which has _F_ or _R_ in it and which has the name of an
166 # error library at the start. This seems to work fine except for the
167 # oddly named structure BIO_F_CTX which needs to be ignored.
168 # If a code doesn't exist in list compiled from headers then mark it
169 # with the value "X" as a place holder to give it a value later.
172 foreach $file (@source) {
173 # Don't parse the error source file.
174 next if exists $cskip{$file};
175 open(IN, "<$file") || die "Can't open source file $file\n";
177 if(/(([A-Z0-9]+)_F_[A-Z0-9_]+)/) {
178 next unless exists $csrc{$2};
179 next if($1 eq "BIO_F_BUFFER_CTX");
180 if(!exists $fcodes{$1}) {
185 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
186 next unless exists $csrc{$2};
187 if(!exists $rcodes{$1}) {
196 # Now process each library in turn.
198 foreach $lib (keys %csrc)
200 my $hfile = $hinc{$lib};
201 my $cfile = $csrc{$lib};
202 if(!$fnew{$lib} && !$rnew{$lib}) {
203 print STDERR "$lib:\t\tNo new error codes\n";
204 next unless $rebuild;
206 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
207 print STDERR " $rnew{$lib} New Reasons.\n";
211 # If we get here then we have some new error codes so we
212 # need to rebuild the header file and C file.
214 # Make a sorted list of error and reason codes for later use.
216 my @function = sort grep(/^${lib}_/,keys %fcodes);
217 my @reasons = sort grep(/^${lib}_/,keys %rcodes);
219 # Rewrite the header file
221 open(IN, "<$hfile") || die "Can't Open Header File $hfile\n";
223 # Copy across the old file
226 last if (/BEGIN ERROR CODES/);
230 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
235 /* The following lines are auto generated by the script mkerr.pl. Any changes
236 * made after this point may be overwritten when the script is next run.
239 /* Error codes for the $lib functions. */
241 /* Function codes. */
244 foreach $i (@function) {
245 $z=6-int(length($i)/8);
246 if($fcodes{$i} eq "X") {
247 $fcodes{$i} = ++$fmax{$lib};
248 print STDERR "New Function code $i\n" if $debug;
250 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
253 print OUT "\n/* Reason codes. */\n";
255 foreach $i (@reasons) {
256 $z=6-int(length($i)/8);
257 if($rcodes{$i} eq "X") {
258 $rcodes{$i} = ++$rmax{$lib};
259 print STDERR "New Reason code $i\n" if $debug;
261 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
273 # Rewrite the C source file containing the error details.
275 $hfile =~ /([^\/]+)$/;
278 open (OUT,">$cfile") || die "Can't open $cfile for writing";
282 /* ====================================================================
283 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
285 * Redistribution and use in source and binary forms, with or without
286 * modification, are permitted provided that the following conditions
289 * 1. Redistributions of source code must retain the above copyright
290 * notice, this list of conditions and the following disclaimer.
292 * 2. Redistributions in binary form must reproduce the above copyright
293 * notice, this list of conditions and the following disclaimer in
294 * the documentation and/or other materials provided with the
297 * 3. All advertising materials mentioning features or use of this
298 * software must display the following acknowledgment:
299 * "This product includes software developed by the OpenSSL Project
300 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
302 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
303 * endorse or promote products derived from this software without
304 * prior written permission. For written permission, please contact
305 * openssl-core\@OpenSSL.org.
307 * 5. Products derived from this software may not be called "OpenSSL"
308 * nor may "OpenSSL" appear in their names without prior written
309 * permission of the OpenSSL Project.
311 * 6. Redistributions of any form whatsoever must retain the following
313 * "This product includes software developed by the OpenSSL Project
314 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
316 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
317 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
318 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
319 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
320 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
321 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
322 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
323 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
324 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
325 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
326 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
327 * OF THE POSSIBILITY OF SUCH DAMAGE.
328 * ====================================================================
330 * This product includes cryptographic software written by Eric Young
331 * (eay\@cryptsoft.com). This product includes software written by Tim
332 * Hudson (tjh\@cryptsoft.com).
336 /* NOTE: this file was auto generated by the mkerr.pl script: any changes
337 * made to it will be overwritten when the script next updates this file.
341 #include <openssl/err.h>
342 #include <openssl/$hincf>
344 /* BEGIN ERROR CODES */
346 static ERR_STRING_DATA ${lib}_str_functs[]=
349 # Add each function code: if a function name is found then use it.
350 foreach $i (@function) {
352 $i =~ /^${lib}_F_(\S+)$/;
354 if(exists $ftrans{$fn}) {
359 print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
365 static ERR_STRING_DATA ${lib}_str_reasons[]=
368 # Add each reason code.
369 foreach $i (@reasons) {
372 $i =~ /^${lib}_R_(\S+)$/;
374 $rn =~ tr/_[A-Z]/ [a-z]/;
375 $nspc = 40 - length($i) unless length($i) > 40;
377 print OUT "{${i}${nspc},\"$rn\"},\n";
386 void ERR_load_${lib}_strings(void)
394 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
395 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
408 #ifdef ${lib}_LIB_NAME
409 static ERR_STRING_DATA ${lib}_lib_name[]=
411 {0 ,${lib}_LIB_NAME},
417 int ${lib}_lib_error_code=0;
419 void ERR_load_${lib}_strings(void)
423 if (${lib}_lib_error_code == 0)
424 ${lib}_lib_error_code=ERR_get_next_error_library();
430 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
431 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
434 #ifdef ${lib}_LIB_NAME
435 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
436 ERR_load_strings(0,${lib}_lib_name);
441 void ERR_${lib}_error(int function, int reason, char *file, int line)
443 if (${lib}_lib_error_code == 0)
444 ${lib}_lib_error_code=ERR_get_next_error_library();
445 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
455 if($debug && defined(@notrans)) {
456 print STDERR "The following function codes were not translated:\n";