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