Fix some clang warnings.
[openssl.git] / crypto / objects / objects.pl
1 #!/usr/local/bin/perl
2
3 open (NUMIN,"$ARGV[1]") || die "Can't open number file $ARGV[1]";
4 $max_nid=0;
5 $o=0;
6 while(<NUMIN>)
7         {
8         chop;
9         $o++;
10         s/#.*$//;
11         next if /^\s*$/;
12         $_ = 'X'.$_;
13         ($Cname,$mynum) = split;
14         $Cname =~ s/^X//;
15         if (defined($nidn{$mynum}))
16                 { die "$ARGV[1]:$o:There's already an object with NID ",$mynum," on line ",$order{$mynum},"\n"; }
17         if (defined($nid{$Cname}))
18                 { die "$ARGV[1]:$o:There's already an object with name ",$Cname," on line ",$order{$nid{$Cname}},"\n"; }
19         $nid{$Cname} = $mynum;
20         $nidn{$mynum} = $Cname;
21         $order{$mynum} = $o;
22         $max_nid = $mynum if $mynum > $max_nid;
23         }
24 close NUMIN;
25
26 open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
27 $Cname="";
28 $o=0;
29 while (<IN>)
30         {
31         chop;
32         $o++;
33         if (/^!module\s+(.*)$/)
34                 {
35                 $module = $1."-";
36                 $module =~ s/\./_/g;
37                 $module =~ s/-/_/g;
38                 }
39         if (/^!global$/)
40                 { $module = ""; }
41         if (/^!Cname\s+(.*)$/)
42                 { $Cname = $1; }
43         if (/^!Alias\s+(.+?)\s+(.*)$/)
44                 {
45                 $Cname = $module.$1;
46                 $myoid = $2;
47                 $myoid = &process_oid($myoid);
48                 $Cname =~ s/-/_/g;
49                 $ordern{$o} = $Cname;
50                 $order{$Cname} = $o;
51                 $obj{$Cname} = $myoid;
52                 $_ = "";
53                 $Cname = "";
54                 }
55         s/!.*$//;
56         s/#.*$//;
57         next if /^\s*$/;
58         ($myoid,$mysn,$myln) = split ':';
59         $mysn =~ s/^\s*//;
60         $mysn =~ s/\s*$//;
61         $myln =~ s/^\s*//;
62         $myln =~ s/\s*$//;
63         $myoid =~ s/^\s*//;
64         $myoid =~ s/\s*$//;
65         if ($myoid ne "")
66                 {
67                 $myoid = &process_oid($myoid);
68                 }
69
70         if ($Cname eq "" && !($myln =~ / /))
71                 {
72                 $Cname = $myln;
73                 $Cname =~ s/\./_/g;
74                 $Cname =~ s/-/_/g;
75                 if ($Cname ne "" && defined($ln{$module.$Cname}))
76                         { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
77                 }
78         if ($Cname eq "")
79                 {
80                 $Cname = $mysn;
81                 $Cname =~ s/-/_/g;
82                 if ($Cname ne "" && defined($sn{$module.$Cname}))
83                         { die "objects.txt:$o:There's already an object with short name ",$sn{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
84                 }
85         if ($Cname eq "")
86                 {
87                 $Cname = $myln;
88                 $Cname =~ s/-/_/g;
89                 $Cname =~ s/\./_/g;
90                 $Cname =~ s/ /_/g;
91                 if ($Cname ne "" && defined($ln{$module.$Cname}))
92                         { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
93                 }
94         $Cname =~ s/\./_/g;
95         $Cname =~ s/-/_/g;
96         $Cname = $module.$Cname;
97         $ordern{$o} = $Cname;
98         $order{$Cname} = $o;
99         $sn{$Cname} = $mysn;
100         $ln{$Cname} = $myln;
101         $obj{$Cname} = $myoid;
102         if (!defined($nid{$Cname}))
103                 {
104                 $max_nid++;
105                 $nid{$Cname} = $max_nid;
106                 $nidn{$max_nid} = $Cname;
107 print STDERR "Added OID $Cname\n";
108                 }
109         $Cname="";
110         }
111 close IN;
112
113 open (NUMOUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
114 foreach (sort { $a <=> $b } keys %nidn)
115         {
116         print NUMOUT $nidn{$_},"\t\t",$_,"\n";
117         }
118 close NUMOUT;
119
120 open (OUT,">$ARGV[2]") || die "Can't open output file $ARGV[2]";
121 print OUT <<'EOF';
122 /* crypto/objects/obj_mac.h */
123
124 /* THIS FILE IS GENERATED FROM objects.txt by objects.pl via the
125  * following command:
126  * perl objects.pl objects.txt obj_mac.num obj_mac.h
127  */
128
129 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
130  * All rights reserved.
131  *
132  * This package is an SSL implementation written
133  * by Eric Young (eay@cryptsoft.com).
134  * The implementation was written so as to conform with Netscapes SSL.
135  * 
136  * This library is free for commercial and non-commercial use as long as
137  * the following conditions are aheared to.  The following conditions
138  * apply to all code found in this distribution, be it the RC4, RSA,
139  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
140  * included with this distribution is covered by the same copyright terms
141  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
142  * 
143  * Copyright remains Eric Young's, and as such any Copyright notices in
144  * the code are not to be removed.
145  * If this package is used in a product, Eric Young should be given attribution
146  * as the author of the parts of the library used.
147  * This can be in the form of a textual message at program startup or
148  * in documentation (online or textual) provided with the package.
149  * 
150  * Redistribution and use in source and binary forms, with or without
151  * modification, are permitted provided that the following conditions
152  * are met:
153  * 1. Redistributions of source code must retain the copyright
154  *    notice, this list of conditions and the following disclaimer.
155  * 2. Redistributions in binary form must reproduce the above copyright
156  *    notice, this list of conditions and the following disclaimer in the
157  *    documentation and/or other materials provided with the distribution.
158  * 3. All advertising materials mentioning features or use of this software
159  *    must display the following acknowledgement:
160  *    "This product includes cryptographic software written by
161  *     Eric Young (eay@cryptsoft.com)"
162  *    The word 'cryptographic' can be left out if the rouines from the library
163  *    being used are not cryptographic related :-).
164  * 4. If you include any Windows specific code (or a derivative thereof) from 
165  *    the apps directory (application code) you must include an acknowledgement:
166  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
167  * 
168  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
169  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
170  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
172  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
173  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
174  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
175  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
176  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
177  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
178  * SUCH DAMAGE.
179  * 
180  * The licence and distribution terms for any publically available version or
181  * derivative of this code cannot be changed.  i.e. this code cannot simply be
182  * copied and put under another distribution licence
183  * [including the GNU Public Licence.]
184  */
185
186 #define SN_undef                        "UNDEF"
187 #define LN_undef                        "undefined"
188 #define NID_undef                       0
189 #define OBJ_undef                       0L
190
191 EOF
192
193 foreach (sort { $a <=> $b } keys %ordern)
194         {
195         $Cname=$ordern{$_};
196         print OUT "#define SN_",$Cname,"\t\t\"",$sn{$Cname},"\"\n" if $sn{$Cname} ne "";
197         print OUT "#define LN_",$Cname,"\t\t\"",$ln{$Cname},"\"\n" if $ln{$Cname} ne "";
198         print OUT "#define NID_",$Cname,"\t\t",$nid{$Cname},"\n" if $nid{$Cname} ne "";
199         print OUT "#define OBJ_",$Cname,"\t\t",$obj{$Cname},"\n" if $obj{$Cname} ne "";
200         print OUT "\n";
201         }
202
203 close OUT;
204
205 sub process_oid
206         {
207         local($oid)=@_;
208         local(@a,$oid_pref);
209
210         @a = split(/\s+/,$myoid);
211         $pref_oid = "";
212         $pref_sep = "";
213         if (!($a[0] =~ /^[0-9]+$/))
214                 {
215                 $a[0] =~ s/-/_/g;
216                 if (!defined($obj{$a[0]}))
217                         { die "$ARGV[0]:$o:Undefined identifier ",$a[0],"\n"; }
218                 $pref_oid = "OBJ_" . $a[0];
219                 $pref_sep = ",";
220                 shift @a;
221                 }
222         $oids = join('L,',@a) . "L";
223         if ($oids ne "L")
224                 {
225                 $oids = $pref_oid . $pref_sep . $oids;
226                 }
227         else
228                 {
229                 $oids = $pref_oid;
230                 }
231         return($oids);
232         }