summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/util/mkerr.pl
diff options
context:
space:
mode:
authorbeck <>2002-05-15 02:29:21 +0000
committerbeck <>2002-05-15 02:29:21 +0000
commitb64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch)
treefa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/util/mkerr.pl
parente471e1ea98d673597b182ea85f29e30c97cd08b5 (diff)
downloadopenbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz
openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2
openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/util/mkerr.pl')
-rw-r--r--src/lib/libcrypto/util/mkerr.pl200
1 files changed, 150 insertions, 50 deletions
diff --git a/src/lib/libcrypto/util/mkerr.pl b/src/lib/libcrypto/util/mkerr.pl
index 7d98b5234d..6c2237d142 100644
--- a/src/lib/libcrypto/util/mkerr.pl
+++ b/src/lib/libcrypto/util/mkerr.pl
@@ -7,7 +7,7 @@ my $static = 1;
7my $recurse = 0; 7my $recurse = 0;
8my $reindex = 0; 8my $reindex = 0;
9my $dowrite = 0; 9my $dowrite = 0;
10 10my $staticloader = "";
11 11
12while (@ARGV) { 12while (@ARGV) {
13 my $arg = $ARGV[0]; 13 my $arg = $ARGV[0];
@@ -29,6 +29,9 @@ while (@ARGV) {
29 } elsif($arg eq "-nostatic") { 29 } elsif($arg eq "-nostatic") {
30 $static = 0; 30 $static = 0;
31 shift @ARGV; 31 shift @ARGV;
32 } elsif($arg eq "-staticloader") {
33 $staticloader = "static ";
34 shift @ARGV;
32 } elsif($arg eq "-write") { 35 } elsif($arg eq "-write") {
33 $dowrite = 1; 36 $dowrite = 1;
34 shift @ARGV; 37 shift @ARGV;
@@ -38,7 +41,7 @@ while (@ARGV) {
38} 41}
39 42
40if($recurse) { 43if($recurse) {
41 @source = (<crypto/*.c>, <crypto/*/*.c>, <rsaref/*.c>, <ssl/*.c>); 44 @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>);
42} else { 45} else {
43 @source = @ARGV; 46 @source = @ARGV;
44} 47}
@@ -53,6 +56,7 @@ while(<IN>)
53{ 56{
54 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) { 57 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
55 $hinc{$1} = $2; 58 $hinc{$1} = $2;
59 $libinc{$2} = $1;
56 $cskip{$3} = $1; 60 $cskip{$3} = $1;
57 if($3 ne "NONE") { 61 if($3 ne "NONE") {
58 $csrc{$1} = $3; 62 $csrc{$1} = $3;
@@ -74,42 +78,44 @@ close IN;
74# Scan each header file in turn and make a list of error codes 78# Scan each header file in turn and make a list of error codes
75# and function names 79# and function names
76 80
77while (($lib, $hdr) = each %hinc) 81while (($hdr, $lib) = each %libinc)
78{ 82{
79 next if($hdr eq "NONE"); 83 next if($hdr eq "NONE");
80 print STDERR "Scanning header file $hdr\n" if $debug; 84 print STDERR "Scanning header file $hdr\n" if $debug;
81 open(IN, "<$hdr") || die "Can't open Header file $hdr\n"; 85 my $line = "", $def= "", $linenr = 0, $gotfile = 0;
82 my $line = "", $def= "", $linenr = 0; 86 if (open(IN, "<$hdr")) {
83 while(<IN>) { 87 $gotfile = 1;
84 $linenr++; 88 while(<IN>) {
85 print STDERR "line: $linenr\r" if $debug; 89 $linenr++;
86 90 print STDERR "line: $linenr\r" if $debug;
87 last if(/BEGIN\s+ERROR\s+CODES/); 91
88 if ($line ne '') { 92 last if(/BEGIN\s+ERROR\s+CODES/);
89 $_ = $line . $_; 93 if ($line ne '') {
90 $line = ''; 94 $_ = $line . $_;
91 } 95 $line = '';
96 }
92 97
93 if (/\\$/) { 98 if (/\\$/) {
94 $line = $_; 99 $line = $_;
95 next; 100 next;
96 } 101 }
97 102
98 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration 103 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
99 if ($cpp) { 104 if ($cpp) {
100 $cpp = 0 if /^#.*endif/; 105 $cpp = 0 if /^#.*endif/;
101 next; 106 next;
102 } 107 }
103 108
104 next if (/^#/); # skip preprocessor directives 109 next if (/^\#/); # skip preprocessor directives
105 110
106 s/\/\*.*?\*\///gs; # ignore comments 111 s/\/\*.*?\*\///gs; # ignore comments
107 s/{[^{}]*}//gs; # ignore {} blocks 112 s/{[^{}]*}//gs; # ignore {} blocks
108 113
109 if (/{|\/\*/) { # Add a } so editor works... 114 if (/\{|\/\*/) { # Add a } so editor works...
110 $line = $_; 115 $line = $_;
111 } else { 116 } else {
112 $def .= $_; 117 $def .= $_;
118 }
113 } 119 }
114 } 120 }
115 121
@@ -151,10 +157,12 @@ while (($lib, $hdr) = each %hinc)
151 # Scan function and reason codes and store them: keep a note of the 157 # Scan function and reason codes and store them: keep a note of the
152 # maximum code used. 158 # maximum code used.
153 159
154 while(<IN>) { 160 if ($gotfile) {
155 if(/^#define\s+(\S+)\s+(\S+)/) { 161 while(<IN>) {
162 if(/^\#define\s+(\S+)\s+(\S+)/) {
156 $name = $1; 163 $name = $1;
157 $code = $2; 164 $code = $2;
165 next if $name =~ /^${lib}err/;
158 unless($name =~ /^${lib}_([RF])_(\w+)$/) { 166 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
159 print STDERR "Invalid error code $name\n"; 167 print STDERR "Invalid error code $name\n";
160 next; 168 next;
@@ -172,6 +180,7 @@ while (($lib, $hdr) = each %hinc)
172 $fcodes{$name} = $code; 180 $fcodes{$name} = $code;
173 } 181 }
174 } 182 }
183 }
175 } 184 }
176 close IN; 185 close IN;
177} 186}
@@ -188,9 +197,11 @@ while (($lib, $hdr) = each %hinc)
188# so all those unreferenced can be printed out. 197# so all those unreferenced can be printed out.
189 198
190 199
200print STDERR "Files loaded: " if $debug;
191foreach $file (@source) { 201foreach $file (@source) {
192 # Don't parse the error source file. 202 # Don't parse the error source file.
193 next if exists $cskip{$file}; 203 next if exists $cskip{$file};
204 print STDERR $file if $debug;
194 open(IN, "<$file") || die "Can't open source file $file\n"; 205 open(IN, "<$file") || die "Can't open source file $file\n";
195 while(<IN>) { 206 while(<IN>) {
196 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) { 207 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
@@ -214,6 +225,7 @@ foreach $file (@source) {
214 } 225 }
215 close IN; 226 close IN;
216} 227}
228print STDERR "\n" if $debug;
217 229
218# Now process each library in turn. 230# Now process each library in turn.
219 231
@@ -240,15 +252,74 @@ foreach $lib (keys %csrc)
240 252
241 # Rewrite the header file 253 # Rewrite the header file
242 254
243 open(IN, "<$hfile") || die "Can't Open Header File $hfile\n"; 255 if (open(IN, "<$hfile")) {
244 256 # Copy across the old file
245 # Copy across the old file 257 while(<IN>) {
246 while(<IN>) {
247 push @out, $_; 258 push @out, $_;
248 last if (/BEGIN ERROR CODES/); 259 last if (/BEGIN ERROR CODES/);
260 }
261 close IN;
262 } else {
263 push @out,
264"/* ====================================================================\n",
265" * Copyright (c) 2001 The OpenSSL Project. All rights reserved.\n",
266" *\n",
267" * Redistribution and use in source and binary forms, with or without\n",
268" * modification, are permitted provided that the following conditions\n",
269" * are met:\n",
270" *\n",
271" * 1. Redistributions of source code must retain the above copyright\n",
272" * notice, this list of conditions and the following disclaimer. \n",
273" *\n",
274" * 2. Redistributions in binary form must reproduce the above copyright\n",
275" * notice, this list of conditions and the following disclaimer in\n",
276" * the documentation and/or other materials provided with the\n",
277" * distribution.\n",
278" *\n",
279" * 3. All advertising materials mentioning features or use of this\n",
280" * software must display the following acknowledgment:\n",
281" * \"This product includes software developed by the OpenSSL Project\n",
282" * for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n",
283" *\n",
284" * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n",
285" * endorse or promote products derived from this software without\n",
286" * prior written permission. For written permission, please contact\n",
287" * openssl-core\@openssl.org.\n",
288" *\n",
289" * 5. Products derived from this software may not be called \"OpenSSL\"\n",
290" * nor may \"OpenSSL\" appear in their names without prior written\n",
291" * permission of the OpenSSL Project.\n",
292" *\n",
293" * 6. Redistributions of any form whatsoever must retain the following\n",
294" * acknowledgment:\n",
295" * \"This product includes software developed by the OpenSSL Project\n",
296" * for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n",
297" *\n",
298" * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n",
299" * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n",
300" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n",
301" * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n",
302" * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n",
303" * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n",
304" * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n",
305" * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n",
306" * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n",
307" * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n",
308" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n",
309" * OF THE POSSIBILITY OF SUCH DAMAGE.\n",
310" * ====================================================================\n",
311" *\n",
312" * This product includes cryptographic software written by Eric Young\n",
313" * (eay\@cryptsoft.com). This product includes software written by Tim\n",
314" * Hudson (tjh\@cryptsoft.com).\n",
315" *\n",
316" */\n",
317"\n",
318"#ifndef HEADER_${lib}_ERR_H\n",
319"#define HEADER_${lib}_ERR_H\n",
320"\n",
321"/* BEGIN ERROR CODES */\n";
249 } 322 }
250 close IN;
251
252 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n"; 323 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
253 324
254 print OUT @out; 325 print OUT @out;
@@ -257,7 +328,22 @@ foreach $lib (keys %csrc)
257/* The following lines are auto generated by the script mkerr.pl. Any changes 328/* 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. 329 * made after this point may be overwritten when the script is next run.
259 */ 330 */
331EOF
332 if($static) {
333 print OUT <<"EOF";
334${staticloader}void ERR_load_${lib}_strings(void);
335
336EOF
337 } else {
338 print OUT <<"EOF";
339${staticloader}void ERR_load_${lib}_strings(void);
340${staticloader}void ERR_unload_${lib}_strings(void);
341${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
342#define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
260 343
344EOF
345 }
346 print OUT <<"EOF";
261/* Error codes for the $lib functions. */ 347/* Error codes for the $lib functions. */
262 348
263/* Function codes. */ 349/* Function codes. */
@@ -288,7 +374,6 @@ EOF
288} 374}
289#endif 375#endif
290#endif 376#endif
291
292EOF 377EOF
293 close OUT; 378 close OUT;
294 379
@@ -382,7 +467,7 @@ EOF
382#include $hincf 467#include $hincf
383 468
384/* BEGIN ERROR CODES */ 469/* BEGIN ERROR CODES */
385#ifndef NO_ERR 470#ifndef OPENSSL_NO_ERR
386static ERR_STRING_DATA ${lib}_str_functs[]= 471static ERR_STRING_DATA ${lib}_str_functs[]=
387 { 472 {
388EOF 473EOF
@@ -425,14 +510,14 @@ if($static) {
425 510
426#endif 511#endif
427 512
428void ERR_load_${lib}_strings(void) 513${staticloader}void ERR_load_${lib}_strings(void)
429 { 514 {
430 static int init=1; 515 static int init=1;
431 516
432 if (init) 517 if (init)
433 { 518 {
434 init=0; 519 init=0;
435#ifndef NO_ERR 520#ifndef OPENSSL_NO_ERR
436 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs); 521 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
437 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons); 522 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
438#endif 523#endif
@@ -456,19 +541,18 @@ static ERR_STRING_DATA ${lib}_lib_name[]=
456#endif 541#endif
457 542
458 543
459int ${lib}_lib_error_code=0; 544static int ${lib}_lib_error_code=0;
545static int ${lib}_error_init=1;
460 546
461void ERR_load_${lib}_strings(void) 547${staticloader}void ERR_load_${lib}_strings(void)
462 { 548 {
463 static int init=1;
464
465 if (${lib}_lib_error_code == 0) 549 if (${lib}_lib_error_code == 0)
466 ${lib}_lib_error_code=ERR_get_next_error_library(); 550 ${lib}_lib_error_code=ERR_get_next_error_library();
467 551
468 if (init) 552 if (${lib}_error_init)
469 { 553 {
470 init=0; 554 ${lib}_error_init=0;
471#ifndef NO_ERR 555#ifndef OPENSSL_NO_ERR
472 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs); 556 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
473 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons); 557 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
474#endif 558#endif
@@ -480,7 +564,23 @@ void ERR_load_${lib}_strings(void)
480 } 564 }
481 } 565 }
482 566
483void ERR_${lib}_error(int function, int reason, char *file, int line) 567${staticloader}void ERR_unload_${lib}_strings(void)
568 {
569 if (${lib}_error_init == 0)
570 {
571#ifndef OPENSSL_NO_ERR
572 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_functs);
573 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_reasons);
574#endif
575
576#ifdef ${lib}_LIB_NAME
577 ERR_unload_strings(0,${lib}_lib_name);
578#endif
579 ${lib}_error_init=1;
580 }
581 }
582
583${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line)
484 { 584 {
485 if (${lib}_lib_error_code == 0) 585 if (${lib}_lib_error_code == 0)
486 ${lib}_lib_error_code=ERR_get_next_error_library(); 586 ${lib}_lib_error_code=ERR_get_next_error_library();