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