Fix manpage problems
[openssl.git] / crypto / objects / objxref.pl
index 3fa584036e1e13cb430c742ec08620a4ba1c786f..0ec63f067e3cfba8b7e5c696ecc21496c0ff3b03 100644 (file)
@@ -1,4 +1,11 @@
-#!/usr/local/bin/perl
+#! /usr/bin/env perl
+# Copyright 1998-2018 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the OpenSSL license (the "License").  You may not use
+# this file except in compliance with the License.  You can obtain a copy
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
 
 use strict;
 
@@ -7,25 +14,32 @@ my %oid_tbl;
 
 my ($mac_file, $xref_file) = @ARGV;
 
-open(IN, $mac_file) || die "Can't open $mac_file";
+# Output year depends on the year of the script and the input file.
+my $YEAR = [localtime([stat($0)]->[9])]->[5] + 1900;
+my $iYEAR = [localtime([stat($mac_file)]->[9])]->[5] + 1900;
+$YEAR = $iYEAR if $iYEAR > $YEAR;
+$iYEAR = [localtime([stat($xref_file)]->[9])]->[5] + 1900;
+$YEAR = $iYEAR if $iYEAR > $YEAR;
+
+open(IN, $mac_file) || die "Can't open $mac_file, $!\n";
 
 # Read in OID nid values for a lookup table.
 
 while (<IN>)
        {
-       chomp;
+       s|\R$||;                # Better chomp
        my ($name, $num) = /^(\S+)\s+(\S+)$/;
        $oid_tbl{$name} = $num;
        }
 close IN;
 
-open(IN, $xref_file) || die "Can't open $xref_file";
+open(IN, $xref_file) || die "Can't open $xref_file, $!\n";
 
 my $ln = 1;
 
 while (<IN>)
        {
-       chomp;
+       s|\R$||;                # Better chomp
        s/#.*$//;
        next if (/^\S*$/);
        my ($xr, $p1, $p2) = /^(\S+)\s+(\S+)\s+(\S+)/;
@@ -39,7 +53,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;
        }
@@ -54,51 +69,74 @@ my @srt2 = sort
 
        return $ap2 - $bp2;
        } @xrkeys;
-       
 
-print <<EOF;
-/* AUTOGENERATED BY $0, DO NOT EDIT */
+my $pname = $0;
+$pname =~ s|.*/||;
 
-typedef struct
-       {
-       int sign_id;
-       int hash_id;
-       int pkey_id;
-       } nid_triple;
-
-static const nid_triple sigoid_srt[] =
-       {
+print <<EOF;
+/*
+ * WARNING: do not edit!
+ * Generated by $pname
+ *
+ * Copyright 1998-$YEAR The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+
+typedef struct {
+    int sign_id;
+    int hash_id;
+    int pkey_id;
+} nid_triple;
+
+DEFINE_STACK_OF(nid_triple)
+
+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
        {
        my ($chk) = @_;
        if (!exists $oid_tbl{$chk})
                {
-               die "Not Found \"$chk\"\n";
+               die "Can't find \"$chk\"\n";
                }
        }
-