2
0

objxref.pl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/local/bin/perl
  2. use strict;
  3. my %xref_tbl;
  4. my %oid_tbl;
  5. my ($mac_file, $xref_file) = @ARGV;
  6. open(IN, $mac_file) || die "Can't open $mac_file";
  7. # Read in OID nid values for a lookup table.
  8. while (<IN>)
  9. {
  10. chomp;
  11. my ($name, $num) = /^(\S+)\s+(\S+)$/;
  12. $oid_tbl{$name} = $num;
  13. }
  14. close IN;
  15. open(IN, $xref_file) || die "Can't open $xref_file";
  16. my $ln = 1;
  17. while (<IN>)
  18. {
  19. chomp;
  20. s/#.*$//;
  21. next if (/^\S*$/);
  22. my ($xr, $p1, $p2) = /^(\S+)\s+(\S+)\s+(\S+)/;
  23. check_oid($xr);
  24. check_oid($p1);
  25. check_oid($p2);
  26. $xref_tbl{$xr} = [$p1, $p2, $ln];
  27. }
  28. my @xrkeys = keys %xref_tbl;
  29. my @srt1 = sort { $oid_tbl{$a} <=> $oid_tbl{$b}} @xrkeys;
  30. for(my $i = 0; $i <= $#srt1; $i++)
  31. {
  32. $xref_tbl{$srt1[$i]}[2] = $i;
  33. }
  34. my @srt2 = sort
  35. {
  36. my$ap1 = $oid_tbl{$xref_tbl{$a}[0]};
  37. my$bp1 = $oid_tbl{$xref_tbl{$b}[0]};
  38. return $ap1 - $bp1 if ($ap1 != $bp1);
  39. my$ap2 = $oid_tbl{$xref_tbl{$a}[1]};
  40. my$bp2 = $oid_tbl{$xref_tbl{$b}[1]};
  41. return $ap2 - $bp2;
  42. } @xrkeys;
  43. my $pname = $0;
  44. $pname =~ s|^.[^/]/||;
  45. print <<EOF;
  46. /* AUTOGENERATED BY $pname, DO NOT EDIT */
  47. typedef struct
  48. {
  49. int sign_id;
  50. int hash_id;
  51. int pkey_id;
  52. } nid_triple;
  53. static const nid_triple sigoid_srt[] =
  54. {
  55. EOF
  56. foreach (@srt1)
  57. {
  58. my $xr = $_;
  59. my ($p1, $p2) = @{$xref_tbl{$_}};
  60. print "\t{NID_$xr, NID_$p1, NID_$p2},\n";
  61. }
  62. print "\t};";
  63. print <<EOF;
  64. static const nid_triple * const sigoid_srt_xref[] =
  65. {
  66. EOF
  67. foreach (@srt2)
  68. {
  69. my $x = $xref_tbl{$_}[2];
  70. print "\t\&sigoid_srt\[$x\],\n";
  71. }
  72. print "\t};\n\n";
  73. sub check_oid
  74. {
  75. my ($chk) = @_;
  76. if (!exists $oid_tbl{$chk})
  77. {
  78. die "Not Found \"$chk\"\n";
  79. }
  80. }