Make objxref.pl output in correct format
[openssl.git] / crypto / objects / objxref.pl
index 0dd360b5b0cda7e9bb1da8153284c228ff9efc61..1913b9d133c24b05c56c68b9eb98e4589abf6313 100644 (file)
@@ -1,6 +1,13 @@
 #!/usr/local/bin/perl
 
-open IN, "obj_mac.num";
+use strict;
+
+my %xref_tbl;
+my %oid_tbl;
+
+my ($mac_file, $xref_file) = @ARGV;
+
+open(IN, $mac_file) || die "Can't open $mac_file";
 
 # Read in OID nid values for a lookup table.
 
@@ -12,7 +19,7 @@ while (<IN>)
        }
 close IN;
 
-open IN, "obj_xref.txt";
+open(IN, $xref_file) || die "Can't open $xref_file";
 
 my $ln = 1;
 
@@ -32,7 +39,8 @@ my @xrkeys = keys %xref_tbl;
 
 my @srt1 = sort { $oid_tbl{$a} <=> $oid_tbl{$b}} @xrkeys;
 
-for(my $i = 0; $i <= $#srt1; $i++)
+my $i;
+for($i = 0; $i <= $#srt1; $i++)
        {
        $xref_tbl{$srt1[$i]}[2] = $i;
        }
@@ -47,38 +55,56 @@ my @srt2 = sort
 
        return $ap2 - $bp2;
        } @xrkeys;
-       
+
+my $pname = $0;
+
+$pname =~ s|^.[^/]/||;
 
 print <<EOF;
+/* AUTOGENERATED BY $pname, DO NOT EDIT */
 
-typedef int nid_triple[3];
+typedef struct {
+    int sign_id;
+    int hash_id;
+    int pkey_id;
+} nid_triple;
 
-static const nid_triple sigoid_srt[] =
-       {
+static const nid_triple sigoid_srt[] = {
 EOF
 
 foreach (@srt1)
        {
        my $xr = $_;
        my ($p1, $p2) = @{$xref_tbl{$_}};
-       print "\t{NID_$xr, NID_$p1, NID_$p2},\n";
-       }
+       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";
+               }
+        }
 
-print "\t};";
+print "};";
 print <<EOF;
 
 
-static const nid_triple * const sigoid_srt_xref[] =
-       {
+static const nid_triple *const sigoid_srt_xref[] = {
 EOF
 
 foreach (@srt2)
        {
-       my $x = $xref_tbl{$_}[2];
-       print "\t\&sigoid_srt\[$x\],\n";
+       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";
+       print "    \&sigoid_srt\[$x\],\n";
        }
 
-print "\t};\n\n";
+print "};\n";
 
 sub check_oid
        {
@@ -88,4 +114,3 @@ sub check_oid
                die "Not Found \"$chk\"\n";
                }
        }
-