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