objxref.pl 1.9 KB
Newer Older
1 2
#!/usr/local/bin/perl

3 4 5 6 7 8 9
use strict;

my %xref_tbl;
my %oid_tbl;

my ($mac_file, $xref_file) = @ARGV;

10
open(IN, $mac_file) || die "Can't open $mac_file, $!\n";
11 12 13 14 15 16 17 18 19 20 21

# Read in OID nid values for a lookup table.

while (<IN>)
	{
	chomp;
	my ($name, $num) = /^(\S+)\s+(\S+)$/;
	$oid_tbl{$name} = $num;
	}
close IN;

22
open(IN, $xref_file) || die "Can't open $xref_file, $!\n";
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

my $ln = 1;

while (<IN>)
	{
	chomp;
	s/#.*$//;
	next if (/^\S*$/);
	my ($xr, $p1, $p2) = /^(\S+)\s+(\S+)\s+(\S+)/;
	check_oid($xr);
	check_oid($p1);
	check_oid($p2);
	$xref_tbl{$xr} = [$p1, $p2, $ln];
	}

my @xrkeys = keys %xref_tbl;

my @srt1 = sort { $oid_tbl{$a} <=> $oid_tbl{$b}} @xrkeys;

A
Andy Polyakov 已提交
42 43
my $i;
for($i = 0; $i <= $#srt1; $i++)
44 45 46 47 48 49 50 51 52 53 54 55 56 57
	{
	$xref_tbl{$srt1[$i]}[2] = $i;
	}

my @srt2 = sort
	{
	my$ap1 = $oid_tbl{$xref_tbl{$a}[0]};
	my$bp1 = $oid_tbl{$xref_tbl{$b}[0]};
	return $ap1 - $bp1 if ($ap1 != $bp1);
	my$ap2 = $oid_tbl{$xref_tbl{$a}[1]};
	my$bp2 = $oid_tbl{$xref_tbl{$b}[1]};

	return $ap2 - $bp2;
	} @xrkeys;
D
Dr. Stephen Henson 已提交
58 59

my $pname = $0;
60
$pname =~ s|.*/||;
61 62

print <<EOF;
D
Dr. Stephen Henson 已提交
63
/* AUTOGENERATED BY $pname, DO NOT EDIT */
64

65 66 67 68 69
typedef struct {
    int sign_id;
    int hash_id;
    int pkey_id;
} nid_triple;
70

71
static const nid_triple sigoid_srt[] = {
72 73 74 75 76 77
EOF

foreach (@srt1)
	{
	my $xr = $_;
	my ($p1, $p2) = @{$xref_tbl{$_}};
78 79 80 81 82 83 84 85 86 87 88
	my $o1 = "    {NID_$xr, NID_$p1,";
	my $o2 = "NID_$p2},";
        if (length("$o1 $o2") < 78)
		{
		print "$o1 $o2\n";
		}
	else
		{
		print "$o1\n     $o2\n";
		}
        }
89

90
print "};";
91 92 93
print <<EOF;


94
static const nid_triple *const sigoid_srt_xref[] = {
95 96 97 98
EOF

foreach (@srt2)
	{
99 100 101 102
	my ($p1, $p2, $x) = @{$xref_tbl{$_}};
	# If digest or signature algorithm is "undef" then the algorithm
	# needs special handling and is excluded from the cross reference table.
	next if $p1 eq "undef" || $p2 eq "undef";
103
	print "    \&sigoid_srt\[$x\],\n";
104 105
	}

106
print "};\n";
107 108 109 110 111 112

sub check_oid
	{
	my ($chk) = @_;
	if (!exists $oid_tbl{$chk})
		{
113
		die "Can't find \"$chk\", $!\n";
114 115
		}
	}