xref: /freebsd/crypto/openssl/VMS/translatesyms.pl (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert#! /usr/bin/env perl
2*e0c4386eSCy Schubert# Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert#
4*e0c4386eSCy Schubert# Licensed under the Apache License 2.0 (the "License").  You may not use
5*e0c4386eSCy Schubert# this file except in compliance with the License.  You can obtain a copy
6*e0c4386eSCy Schubert# in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert# https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert
9*e0c4386eSCy Schubert
10*e0c4386eSCy Schubert# This script will translate any SYMBOL_VECTOR item that has a translation
11*e0c4386eSCy Schubert# in CXX$DEMANGLER_DB.  The latter is generated by and CC/DECC command that
12*e0c4386eSCy Schubert# uses the qualifier /REPOSITORY with the build directory as value.  When
13*e0c4386eSCy Schubert# /NAMES=SHORTENED has been used, this file will hold the translations from
14*e0c4386eSCy Schubert# the original symbols to the shortened variants.
15*e0c4386eSCy Schubert#
16*e0c4386eSCy Schubert# CXX$DEMAGLER_DB. is an ISAM file, but with the magic of RMS, it can be
17*e0c4386eSCy Schubert# read as a text file, with each record as one line.
18*e0c4386eSCy Schubert#
19*e0c4386eSCy Schubert# The lines will have the following syntax for any symbol found that's longer
20*e0c4386eSCy Schubert# than 31 characters:
21*e0c4386eSCy Schubert#
22*e0c4386eSCy Schubert# LONG_symbol_34567890123{cksum}$LONG_symbol_34567890123_more_than_31_chars
23*e0c4386eSCy Schubert#
24*e0c4386eSCy Schubert# $ is present at the end of the shortened symbol name, and is preceded by a
25*e0c4386eSCy Schubert# 7 character checksum.  The $ makes it easy to separate the shortened name
26*e0c4386eSCy Schubert# from the original one.
27*e0c4386eSCy Schubert
28*e0c4386eSCy Schubertuse strict;
29*e0c4386eSCy Schubertuse warnings;
30*e0c4386eSCy Schubert
31*e0c4386eSCy Schubertusage() if scalar @ARGV < 1;
32*e0c4386eSCy Schubert
33*e0c4386eSCy Schubertmy %translations = ();
34*e0c4386eSCy Schubert
35*e0c4386eSCy Schubertopen DEMANGLER_DATA, $ARGV[0]
36*e0c4386eSCy Schubert    or die "Couldn't open $ARGV[0]: $!\n";
37*e0c4386eSCy Schubertwhile(<DEMANGLER_DATA>) {
38*e0c4386eSCy Schubert    s|\R$||;
39*e0c4386eSCy Schubert    (my $translated, my $original) = split /\$/;
40*e0c4386eSCy Schubert    $translations{$original} = $translated.'$';
41*e0c4386eSCy Schubert}
42*e0c4386eSCy Schubertclose DEMANGLER_DATA;
43*e0c4386eSCy Schubert
44*e0c4386eSCy Schubert$| = 1;                         # Autoflush
45*e0c4386eSCy Schubertwhile(<STDIN>) {
46*e0c4386eSCy Schubert    s@
47*e0c4386eSCy Schubert      ((?:[A-Za-z0-9_]+)\/)?([A-Za-z0-9_]+)=(PROCEDURE|DATA)
48*e0c4386eSCy Schubert     @
49*e0c4386eSCy Schubert      if (defined($translations{$2})) {
50*e0c4386eSCy Schubert          my $trans = $translations{$2};
51*e0c4386eSCy Schubert          my $trans_uc = uc $trans;
52*e0c4386eSCy Schubert          if (defined($1) && $trans ne $trans_uc) {
53*e0c4386eSCy Schubert              "$trans_uc/$trans=$3"
54*e0c4386eSCy Schubert          } else {
55*e0c4386eSCy Schubert              "$trans=$3"
56*e0c4386eSCy Schubert          }
57*e0c4386eSCy Schubert      } else {
58*e0c4386eSCy Schubert          $&
59*e0c4386eSCy Schubert      }
60*e0c4386eSCy Schubert     @gxe;
61*e0c4386eSCy Schubert    print $_;
62*e0c4386eSCy Schubert}
63