| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
|
| 5 |
if (scalar @ARGV != 2) |
| 6 |
{ |
| 7 |
print "Usage: perl obj_xref.pl obj_mac.num obj_xref.txt > obj_xref.h\n"; |
| 8 |
exit 1; |
| 9 |
} |
| 10 |
|
| 11 |
my %xref_tbl; |
| 12 |
my %oid_tbl; |
| 13 |
|
| 14 |
my ($mac_file, $xref_file) = @ARGV; |
| 15 |
|
| 16 |
open(IN, $mac_file) || die "Can't open $mac_file"; |
| 17 |
|
| 18 |
# Read in OID nid values for a lookup table. |
| 19 |
|
| 20 |
while (<IN>) |
| 21 |
{ |
| 22 |
chomp; |
| 23 |
my ($name, $num) = /^(\S+)\s+(\S+)$/; |
| 24 |
$oid_tbl{$name} = $num; |
| 25 |
} |
| 26 |
close IN; |
| 27 |
|
| 28 |
open(IN, $xref_file) || die "Can't open $xref_file"; |
| 29 |
|
| 30 |
my $ln = 1; |
| 31 |
|
| 32 |
while (<IN>) |
| 33 |
{ |
| 34 |
chomp; |
| 35 |
s/#.*$//; |
| 36 |
next if (/^\S*$/); |
| 37 |
my ($xr, $p1, $p2) = /^(\S+)\s+(\S+)\s+(\S+)/; |
| 38 |
check_oid($xr); |
| 39 |
check_oid($p1); |
| 40 |
check_oid($p2); |
| 41 |
$xref_tbl{$xr} = [$p1, $p2, $ln]; |
| 42 |
} |
| 43 |
|
| 44 |
my @xrkeys = keys %xref_tbl; |
| 45 |
|
| 46 |
my @srt1 = sort { $oid_tbl{$a} <=> $oid_tbl{$b}} @xrkeys; |
| 47 |
|
| 48 |
for(my $i = 0; $i <= $#srt1; $i++) |
| 49 |
{ |
| 50 |
$xref_tbl{$srt1[$i]}[2] = $i; |
| 51 |
} |
| 52 |
|
| 53 |
my @srt2 = sort |
| 54 |
{ |
| 55 |
my$ap1 = $oid_tbl{$xref_tbl{$a}[0]}; |
| 56 |
my$bp1 = $oid_tbl{$xref_tbl{$b}[0]}; |
| 57 |
return $ap1 - $bp1 if ($ap1 != $bp1); |
| 58 |
my$ap2 = $oid_tbl{$xref_tbl{$a}[1]}; |
| 59 |
my$bp2 = $oid_tbl{$xref_tbl{$b}[1]}; |
| 60 |
|
| 61 |
return $ap2 - $bp2; |
| 62 |
} @xrkeys; |
| 63 |
|
| 64 |
my $pname = $0; |
| 65 |
|
| 66 |
$pname =~ s|^.[^/]/||; |
| 67 |
|
| 68 |
print <<EOF; |
| 69 |
/* THIS FILE IS GENERATED FROM obj_xref.txt by obj_xref.pl via the |
| 70 |
* following command: |
| 71 |
* perl obj_xref.pl obj_mac.num obj_xref.txt > obj_xref.h */ |
| 72 |
|
| 73 |
typedef struct |
| 74 |
{ |
| 75 |
int sign_id; |
| 76 |
int hash_id; |
| 77 |
int pkey_id; |
| 78 |
} nid_triple; |
| 79 |
|
| 80 |
static const nid_triple sigoid_srt[] = |
| 81 |
{ |
| 82 |
EOF |
| 83 |
|
| 84 |
foreach (@srt1) |
| 85 |
{ |
| 86 |
my $xr = $_; |
| 87 |
my ($p1, $p2) = @{$xref_tbl{$_}}; |
| 88 |
print "\t{NID_$xr, NID_$p1, NID_$p2},\n"; |
| 89 |
} |
| 90 |
|
| 91 |
print "\t};"; |
| 92 |
print <<EOF; |
| 93 |
|
| 94 |
|
| 95 |
static const nid_triple * const sigoid_srt_xref[] = |
| 96 |
{ |
| 97 |
EOF |
| 98 |
|
| 99 |
foreach (@srt2) |
| 100 |
{ |
| 101 |
my ($p1, $p2, $x) = @{$xref_tbl{$_}}; |
| 102 |
# If digest or signature algorithm is "undef" then the algorithm |
| 103 |
# needs special handling and is excluded from the cross reference table. |
| 104 |
next if $p1 eq "undef" || $p2 eq "undef"; |
| 105 |
print "\t\&sigoid_srt\[$x\],\n"; |
| 106 |
} |
| 107 |
|
| 108 |
print "\t};\n\n"; |
| 109 |
|
| 110 |
sub check_oid |
| 111 |
{ |
| 112 |
my ($chk) = @_; |
| 113 |
if (!exists $oid_tbl{$chk}) |
| 114 |
{ |
| 115 |
die "Not Found \"$chk\"\n"; |
| 116 |
} |
| 117 |
} |
| 118 |
|