diff options
Diffstat (limited to 'src/lib/libcrypto/err/err_genc.pl')
| -rw-r--r-- | src/lib/libcrypto/err/err_genc.pl | 198 |
1 files changed, 198 insertions, 0 deletions
diff --git a/src/lib/libcrypto/err/err_genc.pl b/src/lib/libcrypto/err/err_genc.pl new file mode 100644 index 0000000000..a8e36c2f0c --- /dev/null +++ b/src/lib/libcrypto/err/err_genc.pl | |||
| @@ -0,0 +1,198 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | if ($ARGV[0] eq "-s") { $static=1; shift @ARGV; } | ||
| 4 | |||
| 5 | ($#ARGV == 1) || die "usage: $0 [-s] <header file> <output C file>\n"; | ||
| 6 | open(IN,"<$ARGV[0]") || die "unable to open $ARGV[0]:$!\n"; | ||
| 7 | open(STDOUT,">$ARGV[1]") || die "unable to open $ARGV[1]:$!\n"; | ||
| 8 | |||
| 9 | $Func=0; | ||
| 10 | $Reas=0; | ||
| 11 | $fuction{'FOPEN'}='fopen'; | ||
| 12 | while (<IN>) | ||
| 13 | { | ||
| 14 | if (/(\S+)\s*\(\);/) | ||
| 15 | { | ||
| 16 | $t=$1; | ||
| 17 | $t =~ s/\*//; | ||
| 18 | ($upper=$t) =~ tr/a-z/A-Z/; | ||
| 19 | $fuction{$upper}=$t; | ||
| 20 | } | ||
| 21 | next unless (/^#define\s+(\S+)\s/); | ||
| 22 | |||
| 23 | $o=$1; | ||
| 24 | if ($o =~ /^([^_]+)_F_(.*)/) | ||
| 25 | { | ||
| 26 | $type=$1; | ||
| 27 | $Func++; | ||
| 28 | $n=$2; | ||
| 29 | $n=$fuction{$n} if (defined($fuction{$n})); | ||
| 30 | $out{$1."_str_functs"}.= | ||
| 31 | sprintf("{ERR_PACK(0,%s,0),\t\"$n\"},\n",$o); | ||
| 32 | } | ||
| 33 | elsif ($o =~ /^([^_]+)_R_(.*)/) | ||
| 34 | { | ||
| 35 | $type=$1; | ||
| 36 | $Reas++; | ||
| 37 | $r=$2; | ||
| 38 | $r =~ tr/A-Z_/a-z /; | ||
| 39 | $pkg{$type."_str_reasons"}=$type; | ||
| 40 | $out{$type."_str_reasons"}.=sprintf("{%-40s,\"$r\"},\n",$o); | ||
| 41 | } | ||
| 42 | elsif ($ARGV[0] =~ /rsaref/ && $o =~ /^RE_(.*)/) | ||
| 43 | { | ||
| 44 | $type="RSAREF"; | ||
| 45 | $Reas++; | ||
| 46 | $r=$1; | ||
| 47 | $r =~ tr/A-Z_/a-z /; | ||
| 48 | $pkg{$type."_str_reasons"}=$type; | ||
| 49 | $out{$type."_str_reasons"}.=sprintf("{%-40s,\"$r\"},\n",$o); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | close(IN); | ||
| 53 | |||
| 54 | &header($type,$ARGV[0]); | ||
| 55 | |||
| 56 | foreach (sort keys %out) | ||
| 57 | { | ||
| 58 | print "static ERR_STRING_DATA ${_}[]=\n\t{\n"; | ||
| 59 | print $out{$_}; | ||
| 60 | print "{0,NULL},\n"; | ||
| 61 | print "\t};\n\n"; | ||
| 62 | } | ||
| 63 | print "#endif\n"; | ||
| 64 | |||
| 65 | if ($static) | ||
| 66 | { $lib="ERR_LIB_$type"; } | ||
| 67 | else | ||
| 68 | { $lib="${type}_lib_error_code"; } | ||
| 69 | |||
| 70 | $str=""; | ||
| 71 | $str.="#ifndef NO_ERR\n"; | ||
| 72 | $str.="\t\tERR_load_strings($lib,${type}_str_functs);\n" if $Func; | ||
| 73 | $str.="\t\tERR_load_strings($lib,${type}_str_reasons);\n" if $Reas; | ||
| 74 | $str.="#endif\n"; | ||
| 75 | |||
| 76 | if (!$static) | ||
| 77 | { | ||
| 78 | print <<"EOF"; | ||
| 79 | |||
| 80 | static int ${type}_lib_error_code=0; | ||
| 81 | |||
| 82 | void ERR_load_${type}_strings() | ||
| 83 | { | ||
| 84 | static int init=1; | ||
| 85 | |||
| 86 | if (${type}_lib_error_code == 0) | ||
| 87 | ${type}_lib_error_code=ERR_get_next_error_library(); | ||
| 88 | |||
| 89 | if (init); | ||
| 90 | {; | ||
| 91 | init=0; | ||
| 92 | $str | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | void ERR_${type}_error(function,reason,file,line) | ||
| 97 | int function; | ||
| 98 | int reason; | ||
| 99 | char *file; | ||
| 100 | int line; | ||
| 101 | { | ||
| 102 | if (${type}_lib_error_code == 0) | ||
| 103 | ${type}_lib_error_code=ERR_get_next_error_library(); | ||
| 104 | ERR_PUT_error(${type}_lib_error_code,function,reason,file,line); | ||
| 105 | } | ||
| 106 | EOF | ||
| 107 | } | ||
| 108 | else # $static | ||
| 109 | { | ||
| 110 | print <<"EOF"; | ||
| 111 | |||
| 112 | void ERR_load_${type}_strings() | ||
| 113 | { | ||
| 114 | static int init=1; | ||
| 115 | |||
| 116 | if (init); | ||
| 117 | {; | ||
| 118 | init=0; | ||
| 119 | $str | ||
| 120 | } | ||
| 121 | } | ||
| 122 | EOF | ||
| 123 | } | ||
| 124 | |||
| 125 | sub header | ||
| 126 | { | ||
| 127 | ($type,$header)=@_; | ||
| 128 | |||
| 129 | ($lc=$type) =~ tr/A-Z/a-z/; | ||
| 130 | $header =~ s/^.*\///; | ||
| 131 | |||
| 132 | print "/* lib/$lc/${lc}\_err.c */\n"; | ||
| 133 | print <<'EOF'; | ||
| 134 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | ||
| 135 | * All rights reserved. | ||
| 136 | * | ||
| 137 | * This package is an SSL implementation written | ||
| 138 | * by Eric Young (eay@cryptsoft.com). | ||
| 139 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 140 | * | ||
| 141 | * This library is free for commercial and non-commercial use as long as | ||
| 142 | * the following conditions are aheared to. The following conditions | ||
| 143 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 144 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 145 | * included with this distribution is covered by the same copyright terms | ||
| 146 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 147 | * | ||
| 148 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 149 | * the code are not to be removed. | ||
| 150 | * If this package is used in a product, Eric Young should be given attribution | ||
| 151 | * as the author of the parts of the library used. | ||
| 152 | * This can be in the form of a textual message at program startup or | ||
| 153 | * in documentation (online or textual) provided with the package. | ||
| 154 | * | ||
| 155 | * Redistribution and use in source and binary forms, with or without | ||
| 156 | * modification, are permitted provided that the following conditions | ||
| 157 | * are met: | ||
| 158 | * 1. Redistributions of source code must retain the copyright | ||
| 159 | * notice, this list of conditions and the following disclaimer. | ||
| 160 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 161 | * notice, this list of conditions and the following disclaimer in the | ||
| 162 | * documentation and/or other materials provided with the distribution. | ||
| 163 | * 3. All advertising materials mentioning features or use of this software | ||
| 164 | * must display the following acknowledgement: | ||
| 165 | * "This product includes cryptographic software written by | ||
| 166 | * Eric Young (eay@cryptsoft.com)" | ||
| 167 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 168 | * being used are not cryptographic related :-). | ||
| 169 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 170 | * the apps directory (application code) you must include an acknowledgement: | ||
| 171 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 172 | * | ||
| 173 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 174 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 175 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 176 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 177 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 178 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 179 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 180 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 181 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 182 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 183 | * SUCH DAMAGE. | ||
| 184 | * | ||
| 185 | * The licence and distribution terms for any publically available version or | ||
| 186 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 187 | * copied and put under another distribution licence | ||
| 188 | * [including the GNU Public Licence.] | ||
| 189 | */ | ||
| 190 | EOF | ||
| 191 | |||
| 192 | print "#include <stdio.h>\n"; | ||
| 193 | print "#include \"err.h\"\n"; | ||
| 194 | print "#include \"$header\"\n"; | ||
| 195 | print "\n/* BEGIN ERROR CODES */\n"; | ||
| 196 | print "#ifndef NO_ERR\n"; | ||
| 197 | } | ||
| 198 | |||
